Go to the documentation of this file.
49 #include "table/strings.h"
55 bool _ignore_restrictions;
102 if (
GB(callback, 0, 8) == 0xFF)
return;
103 if (callback < 0x400) {
114 if (callback == 0x400)
return;
115 if (callback == 0x401) {
119 if (callback < 0x400) {
126 if (callback >= 0x800 && callback < 0xC00) {
139 enum CargoSuffixInOut {
154 template <
typename TC,
typename TS>
161 for (uint j = 0; j <
lengthof(suffixes); j++) {
164 uint cargotype = local_id << 16 | use_input;
165 GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
167 suffixes[j].text[0] =
'\0';
173 for (uint j = 0; j <
lengthof(suffixes); j++) {
174 suffixes[j].text[0] =
'\0';
178 case CARGOSUFFIX_OUT:
206 suffix.
text[0] =
'\0';
211 uint cargotype = local_id << 16 | use_input;
213 }
else if (use_input == CARGOSUFFIX_IN) {
214 if (slot < 3)
GetCargoSuffix(slot, cst, ind, ind_type, indspec, suffix);
215 }
else if (use_input == CARGOSUFFIX_OUT) {
216 if (slot < 2)
GetCargoSuffix(slot + 3, cst, ind, ind_type, indspec, suffix);
228 return (r != 0) ? r < 0 : (a < b);
264 static constexpr
NWidgetPart _nested_build_industry_widgets[] = {
275 SetDataTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
277 SetDataTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
281 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),
288 SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
296 WDP_AUTO,
"build_industry", 170, 212,
299 std::begin(_nested_build_industry_widgets), std::end(_nested_build_industry_widgets)
305 std::vector<IndustryType>
list;
313 void UpdateAvailability()
338 this->list.push_back(ind);
343 if (this->selected_type ==
INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0];
345 this->UpdateAvailability();
347 this->vscroll->
SetCount(this->list.size());
371 std::string cargostring;
375 for (
int j = 0; j < cargolistlen; j++) {
378 if (firstcargo < 0) {
384 cargostring +=
GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION);
390 cargostring =
GetString(prefixstr) + cargostring;
408 if (_game_mode != GM_EDITOR) {
420 this->legend.width = this->legend.height * 9 / 6;
430 for (
const auto &indtype : this->list) {
435 d.height = 5 *
resize->height;
442 int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
443 uint extra_lines_req = 0;
444 uint extra_lines_prd = 0;
445 uint extra_lines_newgrf = 0;
448 for (
const auto &indtype : this->list) {
456 if (strdim.width > max_minwidth) {
457 extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
458 strdim.width = max_minwidth;
464 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
466 if (strdim.width > max_minwidth) {
467 extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
468 strdim.width = max_minwidth;
474 extra_lines_newgrf = 4;
479 height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
481 size->width = d.width + padding.width;
489 d.width += padding.width;
490 d.height += padding.height;
497 void SetStringParameters(
WidgetID widget)
const override
503 if (_game_mode == GM_EDITOR) {
505 SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
511 SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
518 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
528 icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
529 icon.bottom = icon.top + this->legend.height - 1;
532 IndustryType type = this->list[i];
533 bool selected = this->selected_type == type;
543 text = text.
Translate(0, this->resize.step_height);
544 icon = icon.
Translate(0, this->resize.step_height);
559 if (_game_mode != GM_EDITOR) {
561 DrawString(ir, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
574 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
581 if (callback_res > 0x400) {
585 if (str != STR_UNDEFINED) {
598 static void AskManyRandomIndustriesCallback(
Window *,
bool confirmed)
600 if (!confirmed)
return;
609 old_generating_world.Restore();
613 static void AskRemoveAllIndustriesCallback(
Window *,
bool confirmed)
615 if (!confirmed)
return;
629 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
633 assert(_game_mode == GM_EDITOR);
635 ShowQuery(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY,
nullptr, AskManyRandomIndustriesCallback);
640 assert(_game_mode == GM_EDITOR);
642 ShowQuery(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY,
nullptr, AskRemoveAllIndustriesCallback);
648 if (it != this->list.end()) {
649 this->selected_type = *it;
650 this->UpdateAvailability();
693 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
698 uint32_t seed = InteractiveRandom();
699 uint32_t layout_index = InteractiveRandomRange((uint32_t)indsp->
layouts.size());
701 if (_game_mode == GM_EDITOR) {
711 _ignore_restrictions =
true;
715 cur_company.Restore();
716 old_generating_world.Restore();
717 _ignore_restrictions =
false;
727 if (_game_mode == GM_EDITOR)
return;
731 this->UpdateAvailability();
732 if (
enabled != this->enabled) {
753 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
755 if (!gui_scope)
return;
762 void ShowBuildIndustryWindow()
769 static void UpdateIndustryProduction(
Industry *i);
771 static inline bool IsProductionAlterable(
const Industry *i)
774 bool has_prod =
false;
775 for (
size_t j = 0; j <
lengthof(is->production_rate); j++) {
776 if (is->production_rate[j] != 0) {
818 this->clicked_button = 0;
841 const Rect r = this->GetWidget<NWidgetBase>(
WID_IV_INFO)->GetCurrentRect();
843 if (expected != r.bottom) {
844 this->info_height = expected - r.top + 1;
850 void DrawCargoIcon(
const Rect &r,
CargoID cid)
const
871 bool has_accept =
false;
874 DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
890 DrawCargoIcon(ir, a.cargo);
905 str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
912 str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
932 if (this->editable ==
EA_RATE) this->production_offset_y = ir.top;
936 DrawCargoIcon(ir, p.cargo);
942 SetDParam(1, p.history[LAST_MONTH].production);
947 if (this->editable ==
EA_RATE) {
949 p.rate > 0, p.rate < 255);
951 ir.top += line_height;
960 this->production_offset_y = ir.top;
965 ir.top += line_height;
972 if (callback_res > 0x400) {
976 if (message != STR_NULL && message != STR_UNDEFINED) {
990 if (!i->
text.empty()) {
993 ir.top =
DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
1000 void SetStringParameters(
WidgetID widget)
const override
1010 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1017 switch (this->editable) {
1025 if (pt.y >= this->production_offset_y) {
1027 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1046 switch (this->editable) {
1069 default: NOT_REACHED();
1072 UpdateIndustryProduction(i);
1075 this->clicked_line = line;
1076 this->clicked_button = (decrease ^ rtl) ? 1 : 2;
1079 this->editbox_line = line;
1080 switch (this->editable) {
1091 default: NOT_REACHED();
1118 this->clicked_button = 0;
1132 void OnQueryTextFinished(
char *str)
override
1137 uint value = atoi(str);
1138 switch (this->editbox_line) {
1149 UpdateIndustryProduction(i);
1158 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1160 if (!gui_scope)
return;
1162 if (IsProductionAlterable(i)) {
1181 static void UpdateIndustryProduction(
Industry *i)
1219 WDP_AUTO,
"view_industry", 260, 120,
1225 void ShowIndustryViewWindow(
int industry)
1273 auto accepted_cargo = cargoes.first;
1274 auto produced_cargo = cargoes.second;
1276 bool accepted_cargo_matches;
1278 switch (accepted_cargo) {
1280 accepted_cargo_matches =
true;
1284 accepted_cargo_matches = !(*industry)->IsCargoAccepted();
1288 accepted_cargo_matches = (*industry)->IsCargoAccepted(accepted_cargo);
1292 bool produced_cargo_matches;
1294 switch (produced_cargo) {
1296 produced_cargo_matches =
true;
1300 produced_cargo_matches = !(*industry)->IsCargoProduced();
1304 produced_cargo_matches = (*industry)->IsCargoProduced(produced_cargo);
1308 return accepted_cargo_matches && produced_cargo_matches;
1326 static const StringID sorter_names[];
1329 GUIIndustryList industries{IndustryDirectoryWindow::produced_cargo_filter};
1335 static CargoID produced_cargo_filter;
1354 if (this->produced_cargo_filter_criteria != cid) {
1355 this->produced_cargo_filter_criteria = cid;
1371 if (this->accepted_cargo_filter_criteria != cid) {
1372 this->accepted_cargo_filter_criteria = cid;
1413 for (
const Industry *i : this->industries) {
1423 this->industries.clear();
1426 if (this->string_filter.
IsEmpty()) {
1427 this->industries.push_back(i);
1431 this->string_filter.
AddLine(i->GetCachedName());
1432 if (this->string_filter.
GetState()) this->industries.push_back(i);
1435 this->industries.shrink_to_fit();
1438 auto filter = std::make_pair(this->accepted_cargo_filter_criteria, this->produced_cargo_filter_criteria);
1440 this->industries.
Filter(filter);
1443 this->vscroll->
SetCount(this->industries.size());
1447 this->industries.
Sort();
1474 CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1477 int percentage = 0, produced_cargo_count = 0;
1478 for (
const auto &p : i->
produced) {
1481 if (transported != -1) {
1482 produced_cargo_count++;
1483 percentage += transported;
1485 if (produced_cargo_count == 0 && &p == &i->
produced.back() && percentage == 0) {
1488 }
else if (filter == p.cargo) {
1493 if (produced_cargo_count == 0)
return percentage;
1494 return percentage / produced_cargo_count;
1512 int r = it_a - it_b;
1521 uint prod_a = 0, prod_b = 0;
1523 for (
const auto &pa : a->
produced) {
1524 if (
IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
1526 for (
const auto &pb : b->
produced) {
1527 if (
IsValidCargoID(pb.cargo)) prod_b += pb.history[LAST_MONTH].production;
1530 if (
auto ita = a->
GetCargoProduced(filter); ita != std::end(a->
produced)) prod_a = ita->history[LAST_MONTH].production;
1531 if (
auto itb = b->
GetCargoProduced(filter); itb != std::end(b->
produced)) prod_b = itb->history[LAST_MONTH].production;
1533 int r = prod_a - prod_b;
1563 uint16_t production;
1567 std::vector<CargoInfo> cargos;
1569 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1572 cargos.push_back({ itp->cargo, itp->history[LAST_MONTH].production, cargo_suffix[itp - std::begin(i->
produced)].
text.c_str(),
ToPercent8(itp->history[LAST_MONTH].PctTransported()) });
1580 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1581 if (a.production != b.production) return a.production > b.production;
1582 return a.transported > b.transported;
1588 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1589 if (a.transported != b.transported) return a.transported > b.transported;
1590 return a.production > b.production;
1599 auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](
const CargoInfo &ci) ->
bool {
1600 return ci.cargo_id == cid;
1602 if (filtered_ci != cargos.end()) {
1603 std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1608 for (
size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
1609 CargoInfo ci = cargos[j];
1610 SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1621 switch (cargos.size()) {
1622 case 0:
return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1623 case 1:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1624 case 2:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1625 case 3:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1626 default:
return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1637 this->industries.
SetListing(this->last_sorting);
1638 this->industries.
SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1651 this->last_sorting = this->industries.
GetListing();
1659 void SetStringParameters(
WidgetID widget)
const override
1663 SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.
SortType()]);
1667 SetDParam(0, this->GetCargoFilterLabel(this->accepted_cargo_filter_criteria));
1671 SetDParam(0, this->GetCargoFilterLabel(this->produced_cargo_filter_criteria));
1676 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1690 tmp_dpi.left += ir.left;
1691 tmp_dpi.top += ir.top;
1698 if (this->industries.empty()) {
1704 for (uint i = this->vscroll->
GetPosition(); i < this->industries.size(); i++) {
1714 ir.top += this->resize.step_height;
1728 d.height += padding.height;
1729 *size =
maxdim(*size, d);
1735 for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] !=
INVALID_STRING_ID; i++) {
1738 d.width += padding.width;
1739 d.height += padding.height;
1740 *size =
maxdim(*size, d);
1746 resize->height = d.height;
1748 d.width += padding.width;
1749 d.height += padding.height;
1750 *size =
maxdim(*size, d);
1768 list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false));
1774 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1787 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->accepted_cargo_filter_criteria, widget);
1791 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->produced_cargo_filter_criteria, widget);
1796 if (it != this->industries.end()) {
1808 void OnDropdownSelect(
WidgetID widget,
int index)
override
1812 if (this->industries.
SortType() != index) {
1839 void OnEditboxChanged(
WidgetID wid)
override
1864 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1867 case IDIWD_FORCE_REBUILD:
1872 case IDIWD_PRODUCTION_CHANGE:
1895 static inline HotkeyList hotkeys {
"industrydirectory", {
1900 Listing IndustryDirectoryWindow::last_sorting = {
false, 0};
1904 &IndustryNameSorter,
1905 &IndustryTypeSorter,
1906 &IndustryProductionSorter,
1907 &IndustryTransportedCargoSorter
1911 const StringID IndustryDirectoryWindow::sorter_names[] = {
1914 STR_SORT_BY_PRODUCTION,
1915 STR_SORT_BY_TRANSPORTED,
1924 WDP_AUTO,
"list_industries", 428, 190,
1928 &IndustryDirectoryWindow::hotkeys
1931 void ShowIndustryDirectory()
1951 SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1954 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1956 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1963 WDP_AUTO,
"industry_cargoes", 300, 210,
2000 using Cargoes = uint16_t;
2042 this->u.industry.ind_type =
ind_type;
2043 std::fill(std::begin(this->u.industry.other_accepted), std::end(this->u.industry.other_accepted), INVALID_CARGO);
2044 std::fill(std::begin(this->u.industry.other_produced), std::end(this->u.industry.other_produced), INVALID_CARGO);
2060 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
2061 if (
cargo == this->u.cargo.vertical_cargoes[i]) {
2066 if (column < 0)
return -1;
2069 assert(!
HasBit(this->u.cargo.supp_cargoes, column));
2070 SetBit(this->u.cargo.supp_cargoes, column);
2072 assert(!
HasBit(this->u.cargo.cust_cargoes, column));
2073 SetBit(this->u.cargo.cust_cargoes, column);
2086 return this->u.cargo.supp_cargoes != 0 || this->u.cargo.cust_cargoes != 0;
2101 auto insert = std::begin(this->u.cargo.vertical_cargoes);
2102 for (uint i = 0; insert != std::end(this->u.cargo.vertical_cargoes) && i < length; i++) {
2108 this->u.cargo.num_cargoes = (count < 0) ? static_cast<uint8_t>(insert - std::begin(this->u.cargo.vertical_cargoes)) : count;
2110 std::sort(std::begin(this->u.cargo.vertical_cargoes), insert, comparator);
2111 std::fill(insert, std::end(this->u.cargo.vertical_cargoes), INVALID_CARGO);
2112 this->u.cargo.top_end =
top_end;
2114 this->u.cargo.supp_cargoes = 0;
2115 this->u.cargo.cust_cargoes = 0;
2128 for (i = 0; i <
MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] =
cargoes[i];
2129 for (; i <
MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = INVALID_CARGO;
2140 this->u.header = textid;
2151 int n = this->u.cargo.num_cargoes;
2161 void Draw(
int xpos,
int ypos)
const
2163 switch (this->type) {
2184 int blob_left, blob_right;
2199 const CargoID *other_right, *other_left;
2201 other_right = this->u.industry.other_accepted;
2202 other_left = this->u.industry.other_produced;
2204 other_right = this->u.industry.other_produced;
2205 other_left = this->u.industry.other_accepted;
2230 int colpos = cargo_base;
2231 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
2243 Cargoes hor_left, hor_right;
2245 hor_left = this->u.cargo.cust_cargoes;
2246 hor_right = this->u.cargo.supp_cargoes;
2248 hor_left = this->u.cargo.supp_cargoes;
2249 hor_right = this->u.cargo.cust_cargoes;
2253 if (
HasBit(hor_left, i)) {
2257 for (; col > 0; col--) {
2264 if (
HasBit(hor_right, i)) {
2268 for (; col < this->u.cargo.num_cargoes - 1; col++) {
2311 for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2312 if (pt.x < cpos)
break;
2321 if (pt.y < vpos)
return INVALID_CARGO;
2329 if (
HasBit(this->u.cargo.supp_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2330 if (left !=
nullptr) {
2334 return INVALID_CARGO;
2336 if (col == this->u.cargo.num_cargoes) {
2337 if (
HasBit(this->u.cargo.cust_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2338 if (right !=
nullptr) {
2342 return INVALID_CARGO;
2349 if (
HasBit(this->u.cargo.supp_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2350 return INVALID_CARGO;
2353 if (
HasBit(this->u.cargo.cust_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2354 return INVALID_CARGO;
2369 if (pt.y < vpos)
return INVALID_CARGO;
2374 return this->u.cargo_label.cargoes[row];
2428 std::fill(std::begin(ind_fld->u.
industry.other_produced), std::end(ind_fld->u.
industry.other_produced), INVALID_CARGO);
2432 int other_count = 0;
2437 int col = cargo_fld->
ConnectCargo(indsp->produced_cargo[i],
true);
2438 if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2442 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2443 if (
HasBit(cargo_fld->u.
cargo.supp_cargoes, i)) ind_fld->u.
industry.other_produced[i] = others[--other_count];
2447 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2463 std::fill(std::begin(cargoes), std::end(cargoes), INVALID_CARGO);
2466 CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2469 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2470 int col = cargo_fld->
ConnectCargo(cargo_fld->u.
cargo.vertical_cargoes[i], !accepting);
2471 if (col >= 0) cargoes[col] = cargo_fld->u.
cargo.vertical_cargoes[i];
2487 std::fill(std::begin(ind_fld->u.
industry.other_accepted), std::end(ind_fld->u.
industry.other_accepted), INVALID_CARGO);
2491 int other_count = 0;
2497 if (col < 0) others[other_count++] = indsp->
accepts_cargo[i];
2501 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2502 if (!
HasBit(cargo_fld->u.
cargo.cust_cargoes, i)) ind_fld->u.
industry.other_accepted[i] = others[--other_count];
2506 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2553 typedef std::vector<CargoesRow> Fields;
2603 this->ind_textsize.width = 0;
2604 this->ind_textsize.height = 0;
2608 if (!indsp->
enabled)
continue;
2613 d.width = std::max(d.width, this->ind_textsize.width);
2614 d.height = this->ind_textsize.height;
2618 this->cargo_textsize.width = 0;
2619 this->cargo_textsize.height = 0;
2621 if (!csp->IsValid())
continue;
2624 d =
maxdim(d, this->cargo_textsize);
2649 size->width = std::max(size->width, this->ind_textsize.width + padding.width);
2653 size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
2660 void SetStringParameters (
WidgetID widget)
const override
2683 while (length1 > 0) {
2685 for (uint i = 0; i < length2; i++)
if (*cargoes1 == cargoes2[i])
return true;
2701 for (uint i = 0; i < length; i++) {
2720 case LT_TEMPERATE: climate_mask =
HZ_TEMP;
break;
2723 case LT_TOYLAND: climate_mask =
HZ_TOYLND;
break;
2724 default: NOT_REACHED();
2726 for (uint i = 0; i < length; i++) {
2752 if (!indsp->
enabled)
continue;
2770 if (!indsp->
enabled)
continue;
2785 while (top < bottom && !this->
fields[
top].columns[column].HasConnection()) {
2786 this->fields[
top].columns[column].MakeEmpty(
CFT_EMPTY);
2789 this->fields[
top].columns[column].u.cargo.top_end =
true;
2791 while (bottom >
top && !this->fields[bottom].columns[column].HasConnection()) {
2792 this->fields[bottom].columns[column].MakeEmpty(
CFT_EMPTY);
2795 this->fields[bottom].columns[column].u.cargo.bottom_end =
true;
2807 this->fields[row].columns[col].MakeIndustry(it);
2809 this->fields[row].ConnectIndustryProduced(col);
2811 this->fields[row].ConnectIndustryAccepted(col);
2833 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
2834 this->ind_cargo = displayed_it;
2838 this->fields.clear();
2839 CargoesRow &first_row = this->fields.emplace_back();
2852 int num_indrows = std::max(3, std::max(num_supp, num_cust));
2853 for (
int i = 0; i < num_indrows; i++) {
2854 CargoesRow &row = this->fields.emplace_back();
2862 int central_row = 1 + num_indrows / 2;
2863 this->fields[central_row].columns[2].MakeIndustry(displayed_it);
2864 this->fields[central_row].ConnectIndustryProduced(2);
2865 this->fields[central_row].ConnectIndustryAccepted(2);
2868 this->fields[central_row - 1].MakeCargoLabel(2,
true);
2869 this->fields[central_row + 1].MakeCargoLabel(2,
false);
2876 if (!indsp->
enabled)
continue;
2879 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2884 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
2889 if (houses_supply) {
2893 if (houses_accept) {
2900 this->vscroll->
SetCount(num_indrows);
2911 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
2915 this->fields.clear();
2916 CargoesRow &first_row = this->fields.emplace_back();
2927 int num_indrows = std::max(num_supp, num_cust);
2928 for (
int i = 0; i < num_indrows; i++) {
2929 CargoesRow &row = this->fields.emplace_back();
2937 this->fields[num_indrows].MakeCargoLabel(0,
false);
2944 if (!indsp->
enabled)
continue;
2947 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2952 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2957 if (houses_supply) {
2961 if (houses_accept) {
2967 this->vscroll->
SetCount(num_indrows);
2979 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2981 if (!gui_scope)
return;
2991 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
3007 for (
const auto &field : this->fields) {
3008 if (vpos + row_height >= 0) {
3009 int xpos = left_pos;
3018 while (col >= 0 && col <= last_column) {
3019 field.columns[col].Draw(xpos, vpos);
3025 if (vpos >=
height)
break;
3044 if (pt.y < vpos)
return false;
3047 if (row + 1 >= (
int)this->fields.size())
return false;
3052 if (pt.x < xpos)
return false;
3054 for (column = 0; column <= 5; column++) {
3056 if (pt.x < xpos +
width)
break;
3060 if (column > num_columns)
return false;
3067 fieldxy->x = num_columns - column;
3070 fieldxy->x = column;
3076 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
3083 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3084 switch (fld->
type) {
3090 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3091 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3124 lst.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false));
3137 if (!indsp->
enabled)
continue;
3138 lst.push_back(std::make_unique<DropDownListStringItem>(indsp->
name, ind,
false));
3149 void OnDropdownSelect(
WidgetID widget,
int index)
override
3151 if (index < 0)
return;
3164 bool OnTooltip([[maybe_unused]]
Point pt,
WidgetID widget, TooltipCloseCondition close_cond)
override
3171 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3173 switch (fld->
type) {
3175 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3176 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3188 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond);
3198 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, close_cond, 1);
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
@ ES_HANDLED
The passed event is handled.
static constexpr NWidgetPart _nested_industry_view_widgets[]
Widget definition of the view industry gui.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ TC_FORCED
Ignore colour changes from strings.
constexpr uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
static int CountMatchingProducingIndustries(const CargoID *cargoes, uint length)
Count how many industries have produced cargoes in common with one of the supplied set.
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
static bool HousesCanAccept(const CargoID *cargoes, uint length)
Can houses be used as customers of the produced cargoes?
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
byte map_colour
colour used for the small map
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
@ TPE_MAIL
Cargo behaves mail-like for production.
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
@ CBM_IND_CARGO_SUFFIX
cargo sub-type display
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
uint8_t num_cargoes
Number of cargoes.
void MakeCargo(const CargoID *cargoes, uint length, int count=-1, bool top_end=false, bool bottom_end=false)
Make a piece of cargo column.
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
static bool HousesCanSupply(const CargoID *cargoes, uint length)
Can houses be used to supply one of the cargoes?
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
static const int INDUSTRY_LINE_COLOUR
Line colour of the industry type box.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
void OnInit() override
Notification that the nested widget tree gets initialized.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
List of hotkeys for a window.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
void ComputeIndustryDisplay(IndustryType displayed_it)
Compute what and where to display for industry type it.
CargoID other_produced[MAX_CARGOES]
Cargoes produced but not used in this figure.
Dimensions (a width and height) of a rectangle in 2D.
@ ByType
Sorter type to sort by type.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
uint8_t top_end
Stop at the top of the vertical cargoes.
void SetFilterState(bool state)
Enable or disable the filter.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int production_offset_y
The offset of the production texts/buttons.
bool IsEmpty() const
Check whether any filter words were entered.
byte landscape
the landscape we're currently in
Class to backup a specific variable and restore it later.
void BuildSortIndustriesList()
(Re)Build industries list
void SetFilterTerm(const char *str)
Set the term to filter on.
Dimension ind_textsize
Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
void OnResize() override
Called after the window got resized.
CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
std::array< ProducedHistory, 2 > history
History of cargo produced and transported.
void OnResize() override
Called after the window got resized.
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
@ PRODLEVEL_CLOSURE
signal set to actually close the industry
Money GetConstructionCost() const
Get the cost for constructing this industry.
@ CSD_CARGO
Display the cargo without sub-type (cb37 result 401).
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ EA_MULTIPLIER
Allow changing the production multiplier.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
List template of 'things' T to sort in a GUI.
static const uint8_t PC_WHITE
White palette colour.
ViewportData * viewport
Pointer to viewport data, if present.
A single row of CargoesField.
void SetAcceptedCargoFilter(CargoID cid)
Set accepted cargo filter for the industry list.
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ ByName
Sorter type to sort by name.
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static Dimension cargo_stub
Dimensions of cargo stub (unconnected cargo line.)
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
IntervalTimer< TimerWindow > rebuild_interval
Rebuild the industry list on a regular interval.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
void PlaceIndustry(int row, int col, IndustryType it)
Place an industry in the fields.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
void SortIndustryTypes()
Initialize the list of sorted industry types.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
void ShortenCargoColumn(int column, int top, int bottom)
Shorten the cargo column to just the part between industries.
@ CST_DIR
Industry-directory window.
static Dimension legend
Dimension of the legend blob.
Cheat setup_prod
setup raw-material production in game
bool enabled
Availability state of the selected industry.
bool _ctrl_pressed
Is Ctrl pressed?
@ SND_15_BEEP
19 == 0x13 GUI button click
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
static const uint TILE_SIZE
Tile size in world coordinates.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
ProducedCargoArray produced
INDUSTRY_NUM_OUTPUTS production cargo slots.
void RecomputeProductionMultipliers()
Recompute #production_rate for current prod_level.
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
ClientSettings _settings_client
The current settings for this game.
int ConnectCargo(CargoID cargo, bool producer)
Connect a cargo from an industry to the CFT_CARGO column.
ProducedCargoArray::iterator GetCargoProduced(CargoID cargo)
Get produced cargo slot for a specific cargo type.
Specification of a cargo type.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
Cargoes cust_cargoes
Cargoes in vertical_cargoes leaving to the right.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
@ SA_RIGHT
Right align the text (must be a single bit).
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)
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
static WindowDesc _industry_view_desc(__FILE__, __LINE__, WDP_AUTO, "view_industry", 260, 120, WC_INDUSTRY_VIEW, WC_NONE, 0, std::begin(_nested_industry_view_widgets), std::end(_nested_industry_view_widgets))
Window definition of the view industry gui.
@ PRODLEVEL_DEFAULT
default level set when the industry is created
Defines the internal data of a functional industry.
uint GetIndustryListWidth() const
Get the width needed to draw the longest industry line.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
@ CFT_INDUSTRY
Display industry.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
StringID GetErrorMessage() const
Returns the error message of a command.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
uint ind_cargo
If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by transported cargo and name.
static bool CDECL CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
bool NeedRebuild() const
Check if a rebuild is needed.
@ CBM_IND_FUND_MORE_TEXT
additional text in fund window
Data stored about a string that can be modified in the GUI.
@ ByProduction
Sorter type to sort by production amount.
CargoesFieldType type
Type of field.
void OnTimeout() override
Called when this window's timeout has been reached.
bool Succeeded() const
Did this command succeed?
int GetCargoBase(int xpos) const
For a CFT_CARGO, compute the left position of the left-most vertical cargo connection.
char *const buf
buffer in which text is saved
@ CBID_INDUSTRY_FUND_MORE_TEXT
Called to determine more text in the fund industry window.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
void CcBuildIndustry(Commands, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32_t, bool, uint32_t)
Command callback.
void OnInit() override
Notification that the nested widget tree gets initialized.
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
High level window description.
std::vector< IndustryType > list
List of industries.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
uint ScaleByCargoScale(uint num, bool town)
Scale a number by the cargo scale setting.
@ CFT_CARGO
Display cargo connections.
const int MAX_FILTER_LENGTH
The max length of the filter, in chars.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
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.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
constexpr 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.
CargoSuffixDisplay
Ways of displaying the cargo.
Window displaying the cargo connections around an industry (or cargo).
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
@ WDP_AUTO
Find a place automatically.
Data structure describing how to show the list (what sort direction and criteria).
ResizeInfo resize
Resize information.
Common return value for all commands.
TileArea location
Location of the industry.
static WindowDesc _build_industry_desc(__FILE__, __LINE__, WDP_AUTO, "build_industry", 170, 212, WC_BUILD_INDUSTRY, WC_NONE, WDF_CONSTRUCTION, std::begin(_nested_build_industry_widgets), std::end(_nested_build_industry_widgets))
Window definition of the dynamic place industries gui.
Editability editable
Mode for changing production.
SoundSettings sound
sound effect settings
int32_t WindowNumber
Number to differentiate different windows of the same class.
static const HouseID NUM_HOUSES
Total number of houses.
void OnInit() override
Notification that the nested widget tree gets initialized.
@ FS_NORMAL
Index of the normal font in the font tables.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
struct CargoesField::@5::@8 cargo_label
Label data (for CFT_CARGO_LABEL).
void MakeCargoLabel(int column, bool accepting)
Construct a CFT_CARGO_LABEL field.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
static int vert_inter_industry_space
Amount of space between two industries in a column.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
IndustryType type
type of industry.
int height
Height of the window (number of pixels down in y direction)
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void OnResize() override
Called after the window got resized.
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
void OnPaint() override
The window must be repainted.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
@ FS_SMALL
Index of the small font in the font tables.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
static int industry_width
Width of an industry field.
Cheats _cheats
All the cheats.
@ HZ_TEMP
12 1000 can appear in temperate climate
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
void MakeIndustry(IndustryType ind_type)
Make an industry type field.
void OnTimeout() override
Called when this window's timeout has been reached.
ClearGround GetRawClearGround(Tile t)
Get the type of clear tile but never return CLEAR_SNOW.
Data about a single field in the IndustryCargoesWindow panel.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
CargoID cargoes[MAX_CARGOES]
Cargoes to display (or #INVALID_CARGO).
CargoSuffixDisplay display
How to display the cargo and text.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
void OnPaint() override
The window must be repainted.
struct CargoesField::@5::@6 industry
Industry data (for CFT_INDUSTRY).
StringID GetIndustryString(const Industry *i) const
Get the StringID to draw and set the appropriate DParams.
uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void ShowIndustryCargoesWindow(IndustryType id)
Open the industry and cargoes window.
@ ZOOM_LVL_INDUSTRY
Default zoom level for the industry view.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
AcceptedCargoArray accepted
INDUSTRY_NUM_INPUTS input cargo slots.
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
static uint max_cargoes
Largest number of cargoes actually on any industry.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
bool IsDescSortOrder() const
Check if the sort order is descending.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ PRODLEVEL_MAXIMUM
the industry is running at full speed
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
@ CST_VIEW
View-industry window.
WindowFlags flags
Window flags.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Dimension legend
Dimension of the legend 'blob'.
static constexpr NWidgetPart _nested_industry_directory_widgets[]
Widget definition of the industry directory gui.
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
void SetProducedCargoFilter(CargoID cid)
Set produced cargo filter for the industry list.
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
bool _networking
are we in networking mode?
StringID header
Header text (for CFT_HEADER).
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
CargoID vertical_cargoes[MAX_CARGOES]
Cargoes running from top to bottom (cargo ID or #INVALID_CARGO).
CargoID accepted_cargo_filter_criteria
Selected accepted cargo filter index.
@ ByTransported
Sorter type to sort by transported percentage.
@ CBID_INDUSTRY_CARGO_SUFFIX
Called to determine text to display after cargo name.
bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
Calculate in which field was clicked, and within the field, at what position.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Coordinates of a point in 2D.
@ CFT_SMALL_EMPTY
Empty small field (for the header).
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
static int GetCargoTransportedPercentsIfValid(const Industry::ProducedCargo &p)
Returns percents of cargo transported if industry produces this cargo, else -1.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
void Draw(int xpos, int ypos) const
Draw the field.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Editability
Modes for changing production.
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
WindowNumber window_number
Window number within the window class.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
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.
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)
Defines the data structure for constructing industry.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
bool value
tells if the bool cheat is active or not
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ CFT_CARGO_LABEL
Display cargo labels.
static int normal_height
Height of the non-header rows.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
std::string text
General text with additional information.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
static int small_height
Height of the header row.
@ IACT_USERCREATION
from the Fund/build window
@ SA_HOR_CENTER
Horizontally center the text.
TileIndex GetCenterTile() const
Get the center tile.
byte cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
static Dimension cargo_space
Dimensions of space between cargo lines.
uint16_t callback_mask
Bitmask of industry callbacks that have to be called.
@ EA_RATE
Allow changing the production rates.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool _generating_world
Whether we are generating the map or not.
static Dimension cargo_border
Dimensions of border between cargo lines and industry boxes.
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b, const CargoID &)
Sort industries by name.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
CargoID produced_cargo_filter_criteria
Selected produced cargo filter index.
void ForceRebuild()
Force that a rebuild is needed.
@ IL_MULTIPLIER
Production multiplier.
bool left_align
Align all cargo texts to the left (else align to the right).
std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
Build a string of cargo names with suffixes attached.
bool enabled
entity still available (by default true).newgrf can disable it, though
int cheat_line_height
Height of each line for the WID_IV_INFO panel.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Cargoes supp_cargoes
Cargoes in vertical_cargoes entering from the left.
uint8_t raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
static const uint8_t PC_YELLOW
Yellow palette colour.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
@ SBS_DOWN
Sort ascending.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Dimension cargo_icon_size
Largest cargo icon dimension.
CompanyID _current_company
Company currently doing an action.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
Make a field displaying cargo type names.
TownProductionEffect town_production_effect
The effect on town cargo production.
@ IL_RATE1
Production rate of cargo 1.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
CargoesField columns[5]
One row of fields.
@ CSD_CARGO_AMOUNT_TEXT
Display then cargo, amount, and string (cb37 result 000-3FF).
void MakeHeader(StringID textid)
Make a header above an industry column.
bool IsShaded() const
Is window shaded currently?
Listing GetListing() const
Export current sort conditions.
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
static size_t GetNumItems()
Returns number of valid items in the pool.
InfoLine editbox_line
The line clicked to open the edit box.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
@ CST_FUND
Fund-industry window.
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
static debug_inline uint Size()
Get the size of the map.
CargoesFieldType
Available types of field.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
IndustryType selected_type
industry corresponding to the above index
void ComputeCargoDisplay(CargoID cid)
Compute what and where to display for cargo id cid.
TileIndex tile
The base tile of the area.
#define endof(x)
Get the end element of an fixed size array.
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...
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
void ResetState()
Reset the matching state to process a new item.
@ OWNER_NONE
The tile has no ownership.
static int cargo_field_width
Width of a cargo field.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
void ShowSmallMap()
Show the smallmap window.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
GRFFileProps grf_prop
properties related to the grf file
@ CSD_CARGO_TEXT
Display then cargo and supplied string (cb37 result 800-BFF).
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
EventState
State of handling an event.
@ HT_RECT
rectangle (stations, depots, ...)
InfoLine clicked_line
The line of the button that has been clicked.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by type and name.
bool GetState() const
Get the matching state of the current item.
InfoLine
Specific lines in the info panel.
HouseZones building_availability
where can it be built (climates, zones)
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
StringID name
Name of this type of cargo.
@ CBM_IND_WINDOW_MORE_TEXT
additional text in industry window
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static const uint8_t PC_BLACK
Black palette colour.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
static const int ACTION_CLEAR
Clear editbox.
void ConnectIndustryAccepted(int column)
Connect industry accepted cargoes to the cargo column before it.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
int top
y position of top edge of the window
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
@ SA_LEFT
Left align the text.
TownProductionEffect
Town effect when producing cargo.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
uint8_t SortType() const
Get the sorttype of the list.
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?
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
bool click_beep
Beep on a random selection of buttons.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
@ HZ_TOYLND
15 8000 can appear in toyland climate
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Comparator to sort CargoID by according to desired order.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
bool CDECL FilterFunction(const const Industry * *, const std::pair< CargoID, CargoID > &)
Signature of filter function.
Transfer storage of cargo suffix information.
uint8_t bottom_end
Stop at the bottom of the vertical cargoes.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
static int blob_distance
Distance of the industry legend colour from the edge of the industry box.
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
static void SwitchMode(PersistentStorageMode mode, bool ignore_prev_mode=false)
Clear temporary changes made since the last call to SwitchMode, and set whether subsequent changes sh...
@ CBID_INDUSTRY_WINDOW_MORE_TEXT
Called to determine more text in the industry window.
void OnInit() override
Notification that the nested widget tree gets initialized.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
static WindowDesc _industry_directory_desc(__FILE__, __LINE__, WDP_AUTO, "list_industries", 428, 190, WC_INDUSTRY_DIRECTORY, WC_NONE, 0, std::begin(_nested_industry_directory_widgets), std::end(_nested_industry_directory_widgets), &IndustryDirectoryWindow::hotkeys)
Window definition of the industry directory gui.
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by production and name.
void SetButtons()
Update status of the fund and display-chain widgets.
StringFilter string_filter
Filter for industries.
ConstructionSettings construction
construction of things in-game
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
CargoSuffixType
Cargo suffix type (for which window is it requested)
Data structure for an opened window.
Commands
List of commands.
byte clicked_button
The button that has been clicked (to raise)
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
StringID name
Displayed name of the industry.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
int DrawInfo(const Rect &r)
Draw the text in the WID_IV_INFO panel.
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
void DrawWidgets() const
Paint all widgets of a window.
const struct GRFFile * grffile
grf file that introduced this entity
byte prod_level
general production level
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
CargoesFieldType type
Type of field.
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
void RaiseWidgetWhenLowered(byte widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
Specification of a rectangle with absolute coordinates of all edges.
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
Decide which cargo was clicked at in a CFT_CARGO field.
bool Sort(Comp compare)
Sort the list.
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
@ IL_RATE2
Production rate of cargo 2.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
std::string text
Cargo suffix text.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
static const int MAX_MINWIDTH_LINEHEIGHTS
The largest allowed minimum-width of the window, given in line heights.
@ WC_SMALLMAP
Small map; Window numbers:
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
Count how many industries have accepted cargoes in common with one of the supplied set.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
Fields fields
Fields to display in the WID_IC_PANEL.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
@ CSD_CARGO_AMOUNT
Display the cargo and amount (if useful), but no sub-type (cb37 result 400 or fail).
int info_height
Height needed for the WID_IV_INFO panel.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
@ IDHK_FOCUS_FILTER_BOX
Focus the filter box.
struct CargoesField::@5::@7 cargo
Cargo data (for CFT_CARGO).
void GenerateIndustries()
This function will create random industries during game creation.
QueryString industry_editbox
Filter editbox.
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
Build (fund or prospect) a new industry,.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
static Dimension cargo_line
Dimensions of cargo lines.
CargoID other_accepted[MAX_CARGOES]
Cargoes accepted but not used in this figure.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Data about how and where to blit pixels.
bool persistent_buildingtools
keep the building tools active after usage
void SetListing(Listing l)
Import sort conditions.
All data for a single hotkey.
IndustryDirectoryHotkeys
Enum referring to the Hotkeys in the industry directory window.
static WindowDesc _industry_cargoes_desc(__FILE__, __LINE__, WDP_AUTO, "industry_cargoes", 300, 210, WC_INDUSTRY_CARGOES, WC_NONE, 0, std::begin(_nested_industry_cargoes_widgets), std::end(_nested_industry_cargoes_widgets))
Window description for the industry cargoes window.
static constexpr NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.