41 #include "table/strings.h" 47 bool _ignore_restrictions;
84 suffix.
text[0] =
'\0';
93 if (
GB(callback, 0, 8) == 0xFF)
return;
94 if (callback < 0x400) {
105 if (callback == 0x400)
return;
106 if (callback == 0x401) {
110 if (callback < 0x400) {
117 if (callback >= 0x800 && callback < 0xC00) {
130 enum CargoSuffixInOut {
145 template <
typename TC,
typename TS>
152 for (uint j = 0; j <
lengthof(suffixes); j++) {
155 uint cargotype = local_id << 16 | use_input;
156 GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
158 suffixes[j].text[0] =
'\0';
164 for (uint j = 0; j <
lengthof(suffixes); j++) {
165 suffixes[j].text[0] =
'\0';
169 case CARGOSUFFIX_OUT:
189 static char industry_name[2][64];
192 GetString(industry_name[0], indsp1->
name,
lastof(industry_name[0]));
195 GetString(industry_name[1], indsp2->
name,
lastof(industry_name[1]));
197 int r =
strnatcmp(industry_name[0], industry_name[1]);
200 return (r != 0) ? r < 0 : (a < b);
229 uint8 indtype =
GB(p1, 0, 8);
239 static const NWidgetPart _nested_build_industry_widgets[] = {
248 NWidget(
WWT_MATRIX, COLOUR_DARK_GREEN,
WID_DPI_MATRIX_WIDGET),
SetMatrixDataTip(1, 0, STR_FUND_INDUSTRY_SELECTION_TOOLTIP),
SetFill(1, 0),
SetResize(1, 1),
SetScrollbar(
WID_DPI_SCROLLBAR),
255 SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
263 WDP_AUTO,
"build_industry", 170, 212,
266 _nested_build_industry_widgets,
lengthof(_nested_build_industry_widgets)
281 static const int MATRIX_TEXT_OFFSET = 17;
283 static const int MAX_MINWIDTH_LINEHEIGHTS = 20;
289 for (uint i = 0; i <
lengthof(this->index); i++) {
291 this->enabled[i] =
false;
294 if (_game_mode == GM_EDITOR) {
296 this->enabled[this->count] =
true;
298 this->timer_enabled =
false;
312 if (this->selected_type == ind) this->selected_index = -1;
315 this->index[this->count] = ind;
318 if (this->selected_type == ind) this->selected_index = this->count;
325 if (this->selected_index == -1) {
326 this->selected_index = 0;
327 this->selected_type = this->index[0];
330 this->vscroll->
SetCount(this->count);
354 std::string cargostring;
359 for (byte j = 0; j < cargolistlen; j++) {
362 if (firstcargo < 0) {
368 GetString(buf, STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION,
lastof(buf));
375 GetString(buf, prefixstr,
lastof(buf));
376 cargostring = std::string(buf) + cargostring;
380 GetString(buf, prefixstr,
lastof(buf));
381 cargostring = std::string(buf);
392 this->selected_index = -1;
397 this->CreateNestedTree();
399 this->FinishInitNested(0);
414 for (byte i = 0; i < this->count; i++) {
419 d.width += MATRIX_TEXT_OFFSET + padding.width;
420 d.height = 5 * resize->height;
428 uint extra_lines_req = 0;
429 uint extra_lines_prd = 0;
432 for (byte i = 0; i < this->count; i++) {
442 if (strdim.width > max_minwidth) {
443 extra_lines_req =
max(extra_lines_req, strdim.width / max_minwidth + 1);
444 strdim.width = max_minwidth;
450 cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
452 if (strdim.width > max_minwidth) {
453 extra_lines_prd =
max(extra_lines_prd, strdim.width / max_minwidth + 1);
454 strdim.width = max_minwidth;
460 height += extra_lines_prd + extra_lines_req;
470 d.width += padding.width;
471 d.height += padding.height;
484 if (_game_mode == GM_EDITOR) {
486 SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
499 uint text_left, text_right, icon_left, icon_right;
502 icon_left = icon_right - 10;
507 icon_right = icon_left + 10;
512 for (byte i = 0; i < this->vscroll->
GetCapacity() && i + this->vscroll->
GetPosition() < this->count; i++) {
513 int y = r.top +
WD_MATRIX_TOP + i * this->resize.step_height;
514 bool selected = this->selected_index == i + this->vscroll->
GetPosition();
517 DrawString(text_left, text_right, y, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
523 DrawString(text_left, text_right, y, indsp->
name, selected ? TC_WHITE : TC_ORANGE);
537 DrawStringMultiLine(left, right, y, bottom, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
543 if (_game_mode != GM_EDITOR) {
545 DrawString(left, right, y, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
558 cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
565 if (callback_res > 0x400) {
569 if (str != STR_UNDEFINED) {
587 if (y < this->count) {
588 this->selected_index = y;
589 this->selected_type = this->index[y];
597 !this->enabled[this->selected_index])) {
599 this->RaiseButtons();
604 if (this->enabled[this->selected_index] && click_count > 1) this->OnClick(pt,
WID_DPI_FUND_WIDGET, 1);
647 uint32 seed = InteractiveRandom();
648 uint32 layout_index = InteractiveRandomRange((uint32)indsp->
layouts.size());
650 if (_game_mode == GM_EDITOR) {
660 _ignore_restrictions =
true;
662 DoCommandP(tile, (layout_index << 8) | this->selected_type, seed,
666 _ignore_restrictions =
false;
678 if (!this->timer_enabled)
return;
679 if (--this->callback_timer == 0) {
690 if (call_back_result != this->enabled[this->selected_index]) {
691 this->enabled[this->selected_index] = call_back_result;
701 this->RaiseButtons();
706 this->RaiseButtons();
716 if (!gui_scope)
return;
725 void ShowBuildIndustryWindow()
732 static void UpdateIndustryProduction(
Industry *i);
734 static inline bool IsProductionAlterable(
const Industry *i)
737 bool has_prod =
false;
738 for (
size_t j = 0; j <
lengthof(is->production_rate); j++) {
739 if (is->production_rate[j] != 0) {
777 this->editbox_line = IL_NONE;
778 this->clicked_line = IL_NONE;
779 this->clicked_button = 0;
782 this->InitNested(window_number);
786 this->InvalidateData();
793 if (this->IsShaded())
return;
798 this->info_height = expected + 1;
817 bool has_accept =
false;
842 switch (cargo_suffix[j].
display) {
847 str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
854 str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
872 if (this->editable == EA_RATE) this->production_offset_y = y;
883 if (this->editable == EA_RATE) {
891 if (this->editable == EA_MULTIPLIER) {
893 this->production_offset_y = y;
906 if (callback_res > 0x400) {
910 if (message != STR_NULL && message != STR_UNDEFINED) {
933 if (widget ==
WID_IV_INFO) size->height = this->info_height;
943 switch (this->editable) {
951 if (pt.y >= this->production_offset_y) {
964 if (line == IL_NONE)
return;
966 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
972 switch (this->editable) {
995 default: NOT_REACHED();
998 UpdateIndustryProduction(i);
1001 this->clicked_line = line;
1002 this->clicked_button = button;
1005 this->editbox_line = line;
1006 switch (this->editable) {
1017 default: NOT_REACHED();
1043 this->clicked_line = IL_NONE;
1044 this->clicked_button = 0;
1050 if (this->viewport !=
nullptr) {
1063 uint value = atoi(str);
1064 switch (this->editbox_line) {
1065 case IL_NONE: NOT_REACHED();
1075 UpdateIndustryProduction(i);
1086 if (!gui_scope)
return;
1088 if (IsProductionAlterable(i)) {
1092 this->editable = EA_NONE;
1107 static void UpdateIndustryProduction(
Industry *i)
1131 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_IV_VIEWPORT),
SetMinimalSize(254, 86),
SetFill(1, 0),
SetPadding(1, 1, 1, 1),
SetResize(1, 1),
1145 WDP_AUTO,
"view_industry", 260, 120,
1148 _nested_industry_view_widgets,
lengthof(_nested_industry_view_widgets)
1151 void ShowIndustryViewWindow(
int industry)
1191 static const Industry *last_industry;
1194 static const StringID sorter_names[];
1204 this->industries.clear();
1207 this->industries.push_back(i);
1210 this->industries.shrink_to_fit();
1212 this->vscroll->
SetCount((uint)this->industries.size());
1215 if (!this->industries.
Sort())
return;
1216 IndustryDirectoryWindow::last_industry =
nullptr;
1244 int p1 = GetCargoTransportedPercentsIfValid(i, 0);
1245 int p2 = GetCargoTransportedPercentsIfValid(i, 1);
1247 if (p1 > p2)
Swap(p1, p2);
1249 return (p1 << 8) + p2;
1255 static char buf_cache[96];
1256 static char buf[96];
1259 GetString(buf, STR_INDUSTRY_NAME,
lastof(buf));
1261 if (b != last_industry) {
1264 GetString(buf_cache, STR_INDUSTRY_NAME,
lastof(buf_cache));
1277 int r = it_a - it_b;
1278 return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
1284 uint prod_a = 0, prod_b = 0;
1289 int r = prod_a - prod_b;
1291 return (r == 0) ? IndustryTypeSorter(a, b) : r < 0;
1297 int r = GetCargoTransportedSortValue(a) - GetCargoTransportedSortValue(b);
1298 return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
1318 typedef std::tuple<CargoID, uint16, const char*, uint> CargoInfo;
1319 std::vector<CargoInfo> cargos;
1327 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo a,
const CargoInfo b) {
1328 if (std::get<1>(a) != std::get<1>(b))
return std::get<1>(a) > std::get<1>(b);
1329 return std::get<3>(a) > std::get<3>(b);
1333 for (
size_t j = 0; j < min<size_t>(3, cargos.size()); j++) {
1334 CargoInfo ci = cargos[j];
1335 SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1346 switch (cargos.size()) {
1347 case 0:
return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1348 case 1:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1349 case 2:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1350 case 3:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1351 default:
return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1358 this->CreateNestedTree();
1361 this->industries.
SetListing(this->last_sorting);
1362 this->industries.
SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1364 this->BuildSortIndustriesList();
1366 this->FinishInitNested(0);
1371 this->last_sorting = this->industries.
GetListing();
1389 if (this->industries.size() == 0) {
1393 for (uint i = this->vscroll->
GetPosition(); i < this->industries.size(); i++) {
1396 y += this->resize.step_height;
1410 d.height += padding.height;
1411 *size =
maxdim(*size, d);
1417 for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] !=
INVALID_STRING_ID; i++) {
1420 d.width += padding.width;
1421 d.height += padding.height;
1422 *size =
maxdim(*size, d);
1428 for (uint i = 0; i < this->industries.size(); i++) {
1431 resize->height = d.height;
1435 *size =
maxdim(*size, d);
1456 if (p < this->industries.size()) {
1470 if (this->industries.
SortType() != index) {
1472 this->BuildSortIndustriesList();
1483 if (this->industries.
NeedRebuild()) this->BuildSortIndustriesList();
1484 this->DrawWidgets();
1490 this->BuildSortIndustriesList();
1509 Listing IndustryDirectoryWindow::last_sorting = {
false, 0};
1510 const Industry *IndustryDirectoryWindow::last_industry =
nullptr;
1514 &IndustryNameSorter,
1515 &IndustryTypeSorter,
1516 &IndustryProductionSorter,
1517 &IndustryTransportedCargoSorter
1521 const StringID IndustryDirectoryWindow::sorter_names[] = {
1524 STR_SORT_BY_PRODUCTION,
1525 STR_SORT_BY_TRANSPORTED,
1532 WDP_AUTO,
"list_industries", 428, 190,
1535 _nested_industry_directory_widgets,
lengthof(_nested_industry_directory_widgets)
1538 void ShowIndustryDirectory()
1557 SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1560 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1562 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1574 WDP_AUTO,
"industry_cargoes", 300, 210,
1577 _nested_industry_cargoes_widgets,
lengthof(_nested_industry_cargoes_widgets)
1648 this->u.industry.ind_type = ind_type;
1666 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
1667 if (cargo == this->u.cargo.vertical_cargoes[i]) {
1672 if (column < 0)
return -1;
1675 assert(this->u.cargo.supp_cargoes[column] ==
INVALID_CARGO);
1676 this->u.cargo.supp_cargoes[column] = column;
1678 assert(this->u.cargo.cust_cargoes[column] ==
INVALID_CARGO);
1679 this->u.cargo.cust_cargoes[column] = column;
1693 if (this->u.cargo.supp_cargoes[i] !=
INVALID_CARGO)
return true;
1694 if (this->u.cargo.cust_cargoes[i] !=
INVALID_CARGO)
return true;
1708 void MakeCargo(
const CargoID *cargoes, uint length,
int count = -1,
bool top_end =
false,
bool bottom_end =
false)
1715 this->u.cargo.vertical_cargoes[num] = cargoes[i];
1719 this->u.cargo.num_cargoes = (count < 0) ? num : count;
1721 this->u.cargo.top_end = top_end;
1722 this->u.cargo.bottom_end = bottom_end;
1737 for (i = 0; i <
MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] = cargoes[i];
1739 this->u.cargo_label.left_align = left_align;
1749 this->u.header = textid;
1760 int n = this->u.cargo.num_cargoes;
1763 return xpos + cargo_field_width / 2 - (HOR_CARGO_WIDTH + HOR_CARGO_SPACE / 2) * (n / 2);
1765 return xpos + cargo_field_width / 2 - HOR_CARGO_WIDTH / 2 - (HOR_CARGO_WIDTH + HOR_CARGO_SPACE) * (n / 2);
1774 void Draw(
int xpos,
int ypos)
const 1776 switch (this->type) {
1787 int ypos1 = ypos + VERT_INTER_INDUSTRY_SPACE / 2;
1788 int ypos2 = ypos + normal_height - 1 - VERT_INTER_INDUSTRY_SPACE / 2;
1789 int xpos2 = xpos + industry_width - 1;
1790 GfxDrawLine(xpos, ypos1, xpos2, ypos1, INDUSTRY_LINE_COLOUR);
1791 GfxDrawLine(xpos, ypos1, xpos, ypos2, INDUSTRY_LINE_COLOUR);
1792 GfxDrawLine(xpos, ypos2, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
1793 GfxDrawLine(xpos2, ypos1, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
1800 int blob_left, blob_right;
1802 blob_right = xpos2 - BLOB_DISTANCE;
1803 blob_left = blob_right - BLOB_WIDTH;
1805 blob_left = xpos + BLOB_DISTANCE;
1806 blob_right = blob_left + BLOB_WIDTH;
1808 GfxFillRect(blob_left, ypos2 - BLOB_DISTANCE - BLOB_HEIGHT, blob_right, ypos2 - BLOB_DISTANCE,
PC_BLACK);
1809 GfxFillRect(blob_left + 1, ypos2 - BLOB_DISTANCE - BLOB_HEIGHT + 1, blob_right - 1, ypos2 - BLOB_DISTANCE - 1, indsp->
map_colour);
1815 const CargoID *other_right, *other_left;
1817 other_right = this->u.industry.other_accepted;
1818 other_left = this->u.industry.other_produced;
1820 other_right = this->u.industry.other_produced;
1821 other_left = this->u.industry.other_accepted;
1823 ypos1 += VERT_CARGO_EDGE;
1827 int xp = xpos + industry_width + CARGO_STUB_WIDTH;
1828 DrawHorConnection(xpos + industry_width, xp - 1, ypos1, csp);
1833 int xp = xpos - CARGO_STUB_WIDTH;
1834 DrawHorConnection(xp + 1, xpos - 1, ypos1, csp);
1843 int cargo_base = this->GetCargoBase(xpos);
1844 int top = ypos + (this->u.cargo.top_end ? VERT_INTER_INDUSTRY_SPACE / 2 + 1 : 0);
1845 int bot = ypos - (this->u.cargo.bottom_end ? VERT_INTER_INDUSTRY_SPACE / 2 + 1 : 0) + normal_height - 1;
1846 int colpos = cargo_base;
1847 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
1848 if (this->u.cargo.top_end) GfxDrawLine(colpos, top - 1, colpos + HOR_CARGO_WIDTH - 1, top - 1, CARGO_LINE_COLOUR);
1849 if (this->u.cargo.bottom_end) GfxDrawLine(colpos, bot + 1, colpos + HOR_CARGO_WIDTH - 1, bot + 1, CARGO_LINE_COLOUR);
1850 GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
1854 colpos += HOR_CARGO_WIDTH - 2;
1855 GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
1856 colpos += 1 + HOR_CARGO_SPACE;
1859 const CargoID *hor_left, *hor_right;
1861 hor_left = this->u.cargo.cust_cargoes;
1862 hor_right = this->u.cargo.supp_cargoes;
1864 hor_left = this->u.cargo.supp_cargoes;
1865 hor_right = this->u.cargo.cust_cargoes;
1867 ypos += VERT_CARGO_EDGE + VERT_INTER_INDUSTRY_SPACE / 2;
1870 int col = hor_left[i];
1873 for (; col > 0; col--) {
1874 int lf = cargo_base + col * HOR_CARGO_WIDTH + (col - 1) * HOR_CARGO_SPACE;
1875 DrawHorConnection(lf, lf + HOR_CARGO_SPACE - dx, ypos, csp);
1878 DrawHorConnection(xpos, cargo_base - dx, ypos, csp);
1881 int col = hor_right[i];
1884 for (; col < this->u.cargo.num_cargoes - 1; col++) {
1885 int lf = cargo_base + (col + 1) * HOR_CARGO_WIDTH + col * HOR_CARGO_SPACE;
1886 DrawHorConnection(lf + dx - 1, lf + HOR_CARGO_SPACE - 1, ypos, csp);
1897 ypos += VERT_CARGO_EDGE + VERT_INTER_INDUSTRY_SPACE / 2;
1925 int cpos = this->GetCargoBase(0);
1927 for (col = 0; col < this->u.cargo.num_cargoes; col++) {
1928 if (pt.x < cpos)
break;
1934 int vpos = VERT_INTER_INDUSTRY_SPACE / 2 + VERT_CARGO_EDGE;
1945 if (this->u.cargo.supp_cargoes[row] !=
INVALID_CARGO)
return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
1946 if (left !=
nullptr) {
1952 if (col == this->u.cargo.num_cargoes) {
1953 if (this->u.cargo.cust_cargoes[row] !=
INVALID_CARGO)
return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
1954 if (right !=
nullptr) {
1965 return (this->u.cargo.supp_cargoes[row] !=
INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]] :
INVALID_CARGO;
1968 return (this->u.cargo.cust_cargoes[row] !=
INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]] :
INVALID_CARGO;
1981 int vpos = VERT_INTER_INDUSTRY_SPACE / 2 + VERT_CARGO_EDGE;
1989 return this->u.cargo_label.cargoes[row];
2002 GfxDrawLine(left, top, right, top, CARGO_LINE_COLOUR);
2050 int other_count = 0;
2055 int col = cargo_fld->
ConnectCargo(indsp->produced_cargo[i],
true);
2056 if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2060 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2065 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2067 if (cid == CT_PASSENGERS || cid == CT_MAIL) cargo_fld->
ConnectCargo(cid,
true);
2083 CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2086 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2087 int col = cargo_fld->
ConnectCargo(cargo_fld->u.
cargo.vertical_cargoes[i], !accepting);
2088 if (col >= 0) cargoes[col] = cargo_fld->u.
cargo.vertical_cargoes[i];
2108 int other_count = 0;
2114 if (col < 0) others[other_count++] = indsp->
accepts_cargo[i];
2118 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2123 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2172 typedef std::vector<CargoesRow> Fields;
2183 this->CreateNestedTree();
2185 this->FinishInitNested(0);
2186 this->OnInvalidateData(
id);
2199 this->ind_textsize.width = 0;
2200 this->ind_textsize.height = 0;
2204 if (!indsp->
enabled)
continue;
2209 d.width =
max(d.width, this->ind_textsize.width);
2210 d.height = this->ind_textsize.height;
2214 this->cargo_textsize.width = 0;
2215 this->cargo_textsize.height = 0;
2218 if (!csp->
IsValid())
continue;
2221 d =
maxdim(d, this->cargo_textsize);
2224 d.width += 2 * HOR_TEXT_PADDING;
2227 d.height =
max(d.height + 2 * VERT_TEXT_PADDING, min_ind_height);
2244 size->width =
max(size->width, this->ind_textsize.width + padding.width);
2248 size->width =
max(size->width, this->cargo_textsize.width + padding.width);
2278 while (length1 > 0) {
2280 for (uint i = 0; i < length2; i++)
if (*cargoes1 == cargoes2[i])
return true;
2296 for (uint i = 0; i < length; i++) {
2298 if (cargoes[i] == CT_PASSENGERS || cargoes[i] == CT_MAIL)
return true;
2313 case LT_TEMPERATE: climate_mask =
HZ_TEMP;
break;
2316 case LT_TOYLAND: climate_mask =
HZ_TOYLND;
break;
2317 default: NOT_REACHED();
2319 for (uint i = 0; i < length; i++) {
2345 if (!indsp->
enabled)
continue;
2363 if (!indsp->
enabled)
continue;
2365 if (HasCommonValidCargo(cargoes, length, indsp->produced_cargo,
lengthof(indsp->produced_cargo))) count++;
2378 while (top < bottom && !this->fields[top].columns[column].HasConnection()) {
2379 this->fields[top].columns[column].MakeEmpty(
CFT_EMPTY);
2382 this->fields[top].columns[column].u.cargo.top_end =
true;
2384 while (bottom > top && !this->fields[bottom].columns[column].HasConnection()) {
2385 this->fields[bottom].columns[column].MakeEmpty(
CFT_EMPTY);
2388 this->fields[bottom].columns[column].u.cargo.bottom_end =
true;
2399 assert(this->fields[row].columns[col].type ==
CFT_EMPTY);
2400 this->fields[row].columns[col].MakeIndustry(it);
2402 this->fields[row].ConnectIndustryProduced(col);
2404 this->fields[row].ConnectIndustryAccepted(col);
2426 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
2427 this->ind_cargo = it;
2431 this->fields.clear();
2432 this->fields.emplace_back();
2442 bool houses_accept = HousesCanAccept(central_sp->produced_cargo,
lengthof(central_sp->produced_cargo));
2445 int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo,
lengthof(central_sp->produced_cargo)) + houses_accept;
2446 int num_indrows =
max(3,
max(num_supp, num_cust));
2447 for (
int i = 0; i < num_indrows; i++) {
2448 this->fields.emplace_back();
2457 int central_row = 1 + num_indrows / 2;
2458 this->fields[central_row].columns[2].MakeIndustry(it);
2459 this->fields[central_row].ConnectIndustryProduced(2);
2460 this->fields[central_row].ConnectIndustryAccepted(2);
2463 this->fields[central_row - 1].MakeCargoLabel(2,
true);
2464 this->fields[central_row + 1].MakeCargoLabel(2,
false);
2471 if (!indsp->
enabled)
continue;
2474 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2479 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
2484 if (houses_supply) {
2485 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2488 if (houses_accept) {
2489 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, NUM_INDUSTRYTYPES);
2493 this->ShortenCargoColumn(1, 1, num_indrows);
2494 this->ShortenCargoColumn(3, 1, num_indrows);
2498 this->NotifySmallmap();
2507 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
2511 this->fields.clear();
2512 this->fields.emplace_back();
2520 bool houses_supply = HousesCanSupply(&cid, 1);
2521 bool houses_accept = HousesCanAccept(&cid, 1);
2522 int num_supp = CountMatchingProducingIndustries(&cid, 1) + houses_supply + 1;
2523 int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
2524 int num_indrows =
max(num_supp, num_cust);
2525 for (
int i = 0; i < num_indrows; i++) {
2526 this->fields.emplace_back();
2535 this->fields[num_indrows].MakeCargoLabel(0,
false);
2542 if (!indsp->
enabled)
continue;
2544 if (HasCommonValidCargo(&cid, 1, indsp->produced_cargo,
lengthof(indsp->produced_cargo))) {
2545 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2550 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2555 if (houses_supply) {
2556 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2559 if (houses_accept) {
2560 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, NUM_INDUSTRYTYPES);
2564 this->ShortenCargoColumn(1, 1, num_indrows);
2568 this->NotifySmallmap();
2580 if (!gui_scope)
return;
2590 this->ComputeIndustryDisplay(data);
2598 int width = r.right - r.left + 1;
2602 _cur_dpi = &tmp_dpi;
2610 for (uint i = 0; i < this->fields.size(); i++) {
2612 if (vpos + row_height >= 0) {
2613 int xpos = left_pos;
2622 while (col >= 0 && col <= last_column) {
2623 this->fields[i].columns[col].Draw(xpos, vpos);
2629 if (vpos >= height)
break;
2649 if (pt.y < vpos)
return false;
2652 if (row + 1 >= (
int)this->fields.size())
return false;
2657 if (pt.x < xpos)
return false;
2659 for (column = 0; column <= 5; column++) {
2661 if (pt.x < xpos + width)
break;
2665 if (column > num_columns)
return false;
2672 fieldxy->x = num_columns - column;
2675 fieldxy->x = column;
2686 if (!CalculatePositionInWidget(pt, &fieldxy, &xy))
return;
2688 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
2689 switch (fld->
type) {
2695 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
2696 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
2721 this->NotifySmallmap();
2742 if (!indsp->
enabled)
continue;
2746 int selected = (this->ind_cargo <
NUM_INDUSTRYTYPES) ? (
int)this->ind_cargo : -1;
2756 if (index < 0)
return;
2760 this->ComputeCargoDisplay(index);
2764 this->ComputeIndustryDisplay(index);
2774 if (!CalculatePositionInWidget(pt, &fieldxy, &xy))
return false;
2776 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
2778 switch (fld->
type) {
2780 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
2781 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
2793 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, 0,
nullptr, close_cond);
2803 params[0] = csp->
name;
2804 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, 1, params, close_cond);
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Functions related to OTTD's strings.
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
void GenerateIndustries()
This function will create random industries during game creation.
static const int HOR_CARGO_BORDER_SPACE
Amount of space between the left/right edge of a CFT_CARGO field, and the left/right most vertical ca...
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Functions/types related to NewGRF debugging.
static void Swap(T &a, T &b)
Type safe swap operation.
Transfer storage of cargo suffix information.
Base types for having sorted lists in GUIs.
void RebuildDone()
Notify the sortlist that the rebuild is done.
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
bool _networking
are we in networking mode?
static int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
Returns percents of cargo transported if industry produces this cargo, else -1.
static uint minu(const uint a, const uint b)
Returns the minimum of two unsigned integers.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
bool enabled
entity still available (by default true).newgrf can disable it, though
Build (fund or prospect) a new industry,.
byte production_rate[INDUSTRY_NUM_OUTPUTS]
production rate for each cargo
void SortIndustryTypes()
Initialize the list of sorted industry types.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Data about how and where to blit pixels.
static const uint8 PC_WHITE
White palette colour.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Horizontally center the text.
void OnInit() override
Notification that the nested widget tree gets initialized.
static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
Count how many industries have accepted cargoes in common with one of the supplied set...
uint8 raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Offset at right of a matrix cell.
byte landscape
the landscape we're currently in
High level window description.
byte map_colour
colour used for the small map
static int industry_width
Width of an industry field.
uint16 count
How many industries are loaded.
void MakeIndustry(IndustryType ind_type)
Make an industry type field.
below this level, the industry is set to be closing
static Titem * Get(size_t index)
Returns Titem with given index.
static const int VERT_CARGO_SPACE
Amount of vertical space between two connected cargoes at an industry.
int info_height
Height needed for the WID_IV_INFO panel.
Functions for NewGRF industries.
static const int INDUSTRY_LINE_COLOUR
Line colour of the industry type box.
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
void PlaceIndustry(int row, int col, IndustryType it)
Place an industry in the fields.
Offset at top to draw the frame rectangular area.
void OnGameTick() override
Called once per (game) tick.
void ShowSmallMap()
Show the smallmap window.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
Maximal number of cargo types in a game.
CargoSuffixDisplay
Ways of displaying the cargo.
byte cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void BuildSortIndustriesList()
(Re)Build industries list
Specification of a cargo type.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
Display the cargo without sub-type (cb37 result 401).
from the Fund/build window
default level set when the industry is created
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b)
Sort industries by type and name.
static int small_height
Height of the header row.
Editability editable
Mode for changing production.
CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
struct CargoesField::@17::@19 cargo
Cargo data (for CFT_CARGO).
static uint TileX(TileIndex tile)
Get the X component of a tile.
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
static bool HousesCanSupply(const CargoID *cargoes, uint length)
Can houses be used to supply one of the cargoes?
signal set to actually close the industry
Defines the internal data of a functional industry.
static const int BLOB_HEIGHT
Height of the industry legend colour, including border.
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback.
DifficultySettings difficulty
settings related to the difficulty
Industry-directory window.
Tindex index
Index of this pool item.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Offset at top of a matrix cell.
InfoLine
Specific lines in the info panel.
#define lastof(x)
Get the last element of an fixed size array.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Functions related to world/map generation.
static void ShowIndustryCargoesWindow(IndustryType id)
Open the industry and cargoes window.
Stuff related to the text buffer GUI.
static const int MATRIX_TEXT_OFFSET
The offset for the text in the matrix.
static int CountMatchingProducingIndustries(const CargoID *cargoes, uint length)
Count how many industries have produced cargoes in common with one of the supplied set...
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
bool persistent_buildingtools
keep the building tools active after usage
void ComputeCargoDisplay(CargoID cid)
Compute what and where to display for cargo id cid.
Common return value for all commands.
Dimension ind_textsize
Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
bool IsCargoIDValid(CargoID t)
Test whether cargo type is not CT_INVALID.
void MakeHeader(StringID textid)
Make a header above an industry column.
static T max(const T a, const T b)
Returns the maximum of two values.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
the industry is running at full speed
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void SetListing(Listing l)
Import sort conditions.
Large amount of vertical space between two paragraphs of text.
int DrawInfo(uint left, uint right, uint top)
Draw the text in the WID_IV_INFO panel.
Allow changing the production rates.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
static const uint TILE_SIZE
Tile size in world coordinates.
StringID name
Name of this type of cargo.
Industry directory; Window numbers:
static const HouseID NUM_HOUSES
Total number of houses.
void OnPaint() override
The window must be repainted.
StringID name
Displayed name of the industry.
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
bool NeedRebuild() const
Check if a rebuild is needed.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static int cargo_field_width
Width of a cargo field.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Called to determine more text in the fund industry window.
Display the cargo and amount (if useful), but no sub-type (cb37 result 400 or fail).
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
StringID GetIndustryString(const Industry *i) const
Get the StringID to draw and set the appropriate DParams.
HouseZones building_availability
where can it be built (climates, zones)
Class to backup a specific variable and restore it later.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Functions related to (drawing on) viewports.
Pseudo random number generator.
void ForceRebuild()
Force that a rebuild is needed.
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b)
Sort industries by transported cargo and name.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Bottom offset of the text of the frame.
Header of Action 04 "universal holder" structure and functions.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Functions related to low-level strings.
The tile has no ownership.
void OnResize() override
Called after the window got resized.
Types related to cheating.
StringID header
Header text (for CFT_HEADER).
void OnTimeout() override
Called when this window's timeout has been reached.
Functions related to errors.
void OnResize() override
Called after the window got resized.
Offset at bottom of a matrix cell.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
This window is used for construction; close it whenever changing company.
Fill rectangle with a single colour.
SoundSettings sound
sound effect settings
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Listing GetListing() const
Export current sort conditions.
static const NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
void MakeCargoLabel(int column, bool accepting)
Construct a CFT_CARGO_LABEL field.
StringID GetErrorMessage() const
Returns the error message of a command.
Small map; Window numbers:
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
void OnResize() override
Called after the window got resized.
CargoSuffixDisplay display
How to display the cargo and text.
ClientSettings _settings_client
The current settings for this game.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
bool Succeeded() const
Did this command succeed?
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Data about a single field in the IndustryCargoesWindow panel.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition of base types and functions in a cross-platform compatible way.
TileIndex GetCenterTile() const
Get the center tile.
char text[512]
Cargo suffix text.
bool UsesSmoothEconomy() const
Determines whether this industrytype uses smooth economy or whether it uses standard/newgrf productio...
A number of safeguards to prevent using unsafe methods.
CargoesFieldType
Available types of field.
bool value
tells if the bool cheat is active or not
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
IndustryType type
type of industry.
rectangle (stations, depots, ...)
static const int VERT_TEXT_PADDING
Vertical padding around the industry type text.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Fields fields
Fields to display in the WID_IC_PANEL.
Cheat setup_prod
setup raw-material production in game
void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
Make a field displaying cargo type names.
TileArea location
Location of the industry.
additional text in industry window
static const int BLOB_DISTANCE
Distance of the industry legend colour from the edge of the industry box.
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
void Draw(int xpos, int ypos) const
Draw the field.
static const int HOR_CARGO_WIDTH
Width of a vertical cargo column (inclusive the border line).
static const int VERT_INTER_INDUSTRY_SPACE
Amount of space between two industries in a column.
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
Offset at left of a matrix cell.
static const NWidgetPart _nested_industry_view_widgets[]
Widget definition of the view industry gui.
static WindowDesc _build_industry_desc(WDP_AUTO, "build_industry", 170, 212, WC_BUILD_INDUSTRY, WC_NONE, WDF_CONSTRUCTION, _nested_build_industry_widgets, lengthof(_nested_build_industry_widgets))
Window definition of the dynamic place industries gui.
byte bottom_end
Stop at the bottom of the vertical cargoes.
Default zoom level for the industry view.
Defines the data structure for constructing industry.
InfoLine clicked_line
The line of the button that has been clicked.
static WindowDesc _industry_directory_desc(WDP_AUTO, "list_industries", 428, 190, WC_INDUSTRY_DIRECTORY, WC_NONE, 0, _nested_industry_directory_widgets, lengthof(_nested_industry_directory_widgets))
Window definition of the industry directory gui.
CargoesFieldType type
Type of field.
Offset at bottom to draw the frame rectangular area.
std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
Build a string of cargo names with suffixes attached.
Money GetConstructionCost() const
Get the cost for constructing this industry.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
additional text in fund window
Basic functions/variables used all over the place.
static bool HasCommonValidCargo(const CargoID *cargoes1, uint length1, const CargoID *cargoes2, uint length2)
Do the two sets of cargoes have a valid cargo in common?
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Empty small field (for the header).
Right offset of the text of the frame.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Industry view; Window numbers:
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]
incoming cargo waiting to be processed
static const int CARGO_STUB_WIDTH
Width of a cargo not carried in the column (should be less than HOR_CARGO_BORDER_SPACE).
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
#define lengthof(x)
Return the length of an fixed size array.
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
byte prod_level
general production level
GRFFileProps grf_prop
properties related to the grf file
#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var)
Loop header for iterating over 'real' cargoes, sorted by name.
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
Top offset of the text of the frame.
Left offset of the text of the frame.
Types related to the drop down widget.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Functions related to sound.
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
bool Sort(SortFunction *compare)
Sort the list.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
The game does not build industries.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
Calculate in which field was clicked, and within the field, at what position.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void OnTimeout() override
Called when this window's timeout has been reached.
IndustryType selected_type
industry corresponding to the above index
static const uint8 PC_BLACK
Black palette colour.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
12 1000 can appear in temperate climate
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
static const int HOR_CARGO_SPACE
Amount of horizontal space between two vertical cargoes.
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b)
Sort industries by name.
Display then cargo, amount, and string (cb37 result 000-3FF).
int GetCargoBase(int xpos) const
For a CFT_CARGO, compute the left position of the left-most vertical cargo connection.
static int normal_height
Height of the non-header rows.
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Build industry; Window numbers:
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Allow changing the production multiplier.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
bool timer_enabled
timer can be used
TileIndex tile
The base tile of the area.
14 4000 can appear in subtropical climate
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display...
13 2000 can appear in sub-arctic climate below the snow line
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
static bool HousesCanAccept(const CargoID *cargoes, uint length)
Can houses be used as customers of the produced cargoes?
static const uint8 PC_YELLOW
Yellow palette colour.
Functions related to companies.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static WindowDesc _industry_cargoes_desc(WDP_AUTO, "industry_cargoes", 300, 210, WC_INDUSTRY_CARGOES, WC_NONE, 0, _nested_industry_cargoes_widgets, lengthof(_nested_industry_cargoes_widgets))
Window description for the industry cargoes window.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
bool _generating_world
Whether we are generating the map or not.
15 8000 can appear in toyland climate
Both numeric and alphabetic and spaces and stuff.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
GUISettings gui
settings related to the GUI
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Display cargo connections.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix)
Gets the string to display after the cargo name (using callback 37)
byte clicked_button
The button that has been clicked (to raise)
Editability
Modes for changing production.
void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32 grfid=0)
Show the inspect window for a given feature and index.
uint32 TileIndex
The index/ID of a Tile.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
static uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
Production rate of cargo 1.
static size_t GetNumItems()
Returns number of valid items in the pool.
uint ind_cargo
If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
CargoesField columns[5]
One row of fields.
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
TextDirection _current_text_dir
Text direction of the currently selected language.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here...
A single row of CargoesField.
void ConnectIndustryAccepted(int column)
Connect industry accepted cargoes to the cargo column before it.
byte num_cargoes
Number of cargoes.
bool has_newindustries
Set if there are any newindustries loaded.
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Display then cargo and supplied string (cb37 result 800-BFF).
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
Functions for setting GUIs.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static const byte INVALID_CARGO
Constant representing invalid cargo.
static Industry * PlaceIndustry(IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
Try to place the industry in the game.
#define endof(x)
Get the end element of an fixed size array.
Window displaying the cargo connections around an industry (or cargo).
call production callback when cargo arrives at the industry
Functions related to the drop down widget.
void OnInit() override
Notification that the nested widget tree gets initialized.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
CargoSuffixType
Cargo suffix type (for which window is it requested)
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to commands.
Coordinates of a point in 2D.
byte top_end
Stop at the top of the vertical cargoes.
CompanyID _current_company
Company currently doing an action.
CargoID Index() const
Determines index of this cargospec.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Data structure describing how to show the list (what sort direction and criteria).
static const int BLOB_WIDTH
Width of the industry legend colour, including border.
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Window does not do autoscroll,.
ConstructionSettings construction
construction of things in-game
void OnHundredthTick() override
Called once every 100 (game) ticks.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Called to determine text to display after cargo name.
bool left_align
Align all cargo texts to the left (else align to the right).
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
Offset at right to draw the frame rectangular area.
void OnPaint() override
The window must be repainted.
const struct GRFFile * grffile
grf file that introduced this entity
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
bool IsValid() const
Tests for validity of this cargospec.
CargoesFieldType type
Type of field.
CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
Decide which cargo was clicked at in a CFT_CARGO field.
void Restore()
Restore the variable.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
Gets all strings to display after the cargoes of industries (using callback 37)
bool IsDescSortOrder() const
Check if the sort order is descending.
#define CMD_MSG(x)
Used to combine a StringID with the command.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
int32 WindowNumber
Number to differentiate different windows of the same class.
GameCreationSettings game_creation
settings used during the creation of a game (map)
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Specification of a rectangle with absolute coordinates of all edges.
byte CargoID
Cargo slots to indicate a cargo type within a game.
InfoLine editbox_line
The line clicked to open the edit box.
Text is written right-to-left by default.
Right align the text (must be a single bit).
Called to determine more text in the industry window.
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
int ConnectCargo(CargoID cargo, bool producer)
Connect a cargo from an industry to the CFT_CARGO column.
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Find a place automatically.
byte industry_density
The industry density.
void MakeCargo(const CargoID *cargoes, uint length, int count=-1, bool top_end=false, bool bottom_end=false)
Make a piece of cargo column.
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b)
Sort industries by production and name.
GUI functions that shouldn't be here.
void OnResize() override
Called after the window got resized.
CargoID CargoLabelClickedAt(Point pt) const
Decide what cargo the user clicked in the cargo label field.
bool SortFunction(const T &, const T &)
Signature of sort function.
void SetButtons()
Update status of the fund and display-chain widgets.
call production callback every 256 ticks
struct CargoesField::@17::@18 industry
Industry data (for CFT_INDUSTRY).
int production_offset_y
The offset of the production texts/buttons.
Industry cargoes chain; Window numbers:
void ComputeIndustryDisplay(IndustryType it)
Compute what and where to display for industry type it.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static WindowDesc _industry_view_desc(WDP_AUTO, "view_industry", 260, 120, WC_INDUSTRY_VIEW, WC_NONE, 0, _nested_industry_view_widgets, lengthof(_nested_industry_view_widgets))
Window definition of the view industry gui.
Dimensions (a width and height) of a rectangle in 2D.
bool click_beep
Beep on a random selection of buttons.
Offset at left to draw the frame rectangular area.
Class for backupping variables and making sure they are restored later.
void ShortenCargoColumn(int column, int top, int bottom)
Shorten the cargo column to just the part between industries.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
static const int HOR_TEXT_PADDING
Horizontal padding around the industry type text.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
struct CargoesField::@17::@20 cargo_label
Label data (for CFT_CARGO_LABEL).
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
static const int VERT_CARGO_EDGE
Amount of vertical space between top/bottom and the top/bottom connected cargo at an industry...
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Cheats _cheats
All the cheats.
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
int selected_index
index of the element in the matrix
11 800 can appear in sub-arctic climate above the snow line
static uint max_cargoes
Largest number of cargoes actually on any industry.
static const NWidgetPart _nested_industry_directory_widgets[]
Widget definition of the industry directory gui.
Production rate of cargo 2.
uint8 SortType() const
Get the sorttype of the list.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
uint16 callback_timer
timer counter for callback eventual verification