Go to the documentation of this file.
43 #include "table/strings.h"
49 bool _ignore_restrictions;
86 suffix.
text[0] =
'\0';
95 if (
GB(callback, 0, 8) == 0xFF)
return;
96 if (callback < 0x400) {
107 if (callback == 0x400)
return;
108 if (callback == 0x401) {
112 if (callback < 0x400) {
119 if (callback >= 0x800 && callback < 0xC00) {
132 enum CargoSuffixInOut {
147 template <
typename TC,
typename TS>
154 for (uint j = 0; j <
lengthof(suffixes); j++) {
157 uint cargotype = local_id << 16 | use_input;
158 GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
160 suffixes[j].text[0] =
'\0';
166 for (uint j = 0; j <
lengthof(suffixes); j++) {
167 suffixes[j].text[0] =
'\0';
171 case CARGOSUFFIX_OUT:
191 static char industry_name[2][64];
194 GetString(industry_name[0], indsp1->
name,
lastof(industry_name[0]));
197 GetString(industry_name[1], indsp2->
name,
lastof(industry_name[1]));
199 int r =
strnatcmp(industry_name[0], industry_name[1]);
202 return (r != 0) ? r < 0 : (a < b);
231 uint8 indtype =
GB(p1, 0, 8);
241 static const NWidgetPart _nested_build_industry_widgets[] = {
252 SetDataTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
254 SetDataTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
258 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),
265 SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
273 WDP_AUTO,
"build_industry", 170, 212,
276 _nested_build_industry_widgets,
lengthof(_nested_build_industry_widgets)
296 for (uint i = 0; i <
lengthof(this->index); i++) {
298 this->enabled[i] =
false;
313 if (this->selected_type == ind) this->selected_index = -1;
316 this->index[this->
count] = ind;
319 if (this->selected_type == ind) this->selected_index = this->
count;
326 if (this->selected_index == -1) {
327 this->selected_index = 0;
328 this->selected_type = this->index[0];
331 this->vscroll->
SetCount(this->count);
355 std::string cargostring;
360 for (
int j = 0; j < cargolistlen; j++) {
363 if (firstcargo < 0) {
369 GetString(buf, STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION,
lastof(buf));
376 GetString(buf, prefixstr,
lastof(buf));
377 cargostring = std::string(buf) + cargostring;
381 GetString(buf, prefixstr,
lastof(buf));
382 cargostring = std::string(buf);
391 this->selected_index = -1;
401 if (_game_mode != GM_EDITOR) {
412 this->legend.width = this->legend.height * 8 / 5;
422 for (uint16 i = 0; i < this->
count; i++) {
427 d.width += this->legend.width +
ScaleFontTrad(7) + padding.width;
428 d.height = 5 *
resize->height;
435 int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
436 uint extra_lines_req = 0;
437 uint extra_lines_prd = 0;
438 uint extra_lines_newgrf = 0;
441 for (uint16 i = 0; i < this->
count; i++) {
451 if (strdim.width > max_minwidth) {
452 extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
453 strdim.width = max_minwidth;
459 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
461 if (strdim.width > max_minwidth) {
462 extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
463 strdim.width = max_minwidth;
469 extra_lines_newgrf = 4;
474 height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
484 d.width += padding.width;
485 d.height += padding.height;
498 if (_game_mode == GM_EDITOR) {
500 SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
513 uint text_left, text_right, icon_left, icon_right;
516 icon_left = icon_right - this->legend.width;
521 icon_right = icon_left + this->legend.width;
528 int icon_bottom = icon_top + this->legend.height;
532 bool selected = this->selected_index == i + this->vscroll->
GetPosition();
535 DrawString(text_left, text_right, y +
WD_MATRIX_TOP, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
544 GfxFillRect(icon_left + 1, y + icon_top + 1, icon_right - 1, y + icon_bottom - 1, indsp->
map_colour);
564 if (_game_mode != GM_EDITOR) {
566 DrawString(
left, right, y, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
579 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
586 if (callback_res > 0x400) {
590 if (str != STR_UNDEFINED) {
603 static void AskManyRandomIndustriesCallback(
Window *w,
bool confirmed)
605 if (!confirmed)
return;
613 old_generating_world.Restore();
617 static void AskRemoveAllIndustriesCallback(
Window *w,
bool confirmed)
619 if (!confirmed)
return;
637 assert(_game_mode == GM_EDITOR);
639 ShowQuery(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY,
nullptr, AskManyRandomIndustriesCallback);
644 assert(_game_mode == GM_EDITOR);
646 ShowQuery(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY,
nullptr, AskRemoveAllIndustriesCallback);
652 if (y < this->
count) {
653 this->selected_index = y;
654 this->selected_type = this->index[y];
662 !this->enabled[this->selected_index])) {
703 uint32 seed = InteractiveRandom();
704 uint32 layout_index = InteractiveRandomRange((uint32)indsp->
layouts.size());
706 if (_game_mode == GM_EDITOR) {
716 _ignore_restrictions =
true;
718 DoCommandP(tile, (layout_index << 8) | this->selected_type, seed,
722 old_generating_world.
Restore();
723 _ignore_restrictions =
false;
734 if (_game_mode == GM_EDITOR)
return;
741 if (call_back_result != this->enabled[this->selected_index]) {
766 if (!gui_scope)
return;
776 void ShowBuildIndustryWindow()
783 static void UpdateIndustryProduction(
Industry *i);
785 static inline bool IsProductionAlterable(
const Industry *i)
788 bool has_prod =
false;
789 for (
size_t j = 0; j <
lengthof(is->production_rate); j++) {
790 if (is->production_rate[j] != 0) {
830 this->clicked_button = 0;
849 this->info_height = expected + 1;
868 bool has_accept =
false;
893 switch (cargo_suffix[j].display) {
898 str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
905 str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
923 if (this->editable ==
EA_RATE) this->production_offset_y = y;
934 if (this->editable ==
EA_RATE) {
944 this->production_offset_y = y;
957 if (callback_res > 0x400) {
961 if (message != STR_NULL && message != STR_UNDEFINED) {
975 if (!i->
text.empty()) {
1001 switch (this->editable) {
1009 if (pt.y >= this->production_offset_y) {
1024 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
1030 switch (this->editable) {
1053 default: NOT_REACHED();
1056 UpdateIndustryProduction(i);
1059 this->clicked_line = line;
1060 this->clicked_button = button;
1063 this->editbox_line = line;
1064 switch (this->editable) {
1075 default: NOT_REACHED();
1102 this->clicked_button = 0;
1121 uint value = atoi(str);
1122 switch (this->editbox_line) {
1133 UpdateIndustryProduction(i);
1144 if (!gui_scope)
return;
1146 if (IsProductionAlterable(i)) {
1165 static void UpdateIndustryProduction(
Industry *i)
1203 WDP_AUTO,
"view_industry", 260, 120,
1209 void ShowIndustryViewWindow(
int industry)
1258 auto accepted_cargo = cargoes.first;
1259 auto produced_cargo = cargoes.second;
1261 bool accepted_cargo_matches;
1263 switch (accepted_cargo) {
1265 accepted_cargo_matches =
true;
1269 accepted_cargo_matches = std::all_of(std::begin((*industry)->accepts_cargo), std::end((*industry)->accepts_cargo), [](
CargoID cargo) {
1270 return cargo == CT_INVALID;
1275 const auto &ac = (*industry)->accepts_cargo;
1276 accepted_cargo_matches = std::find(std::begin(ac), std::end(ac), accepted_cargo) != std::end(ac);
1280 bool produced_cargo_matches;
1282 switch (produced_cargo) {
1284 produced_cargo_matches =
true;
1288 produced_cargo_matches = std::all_of(std::begin((*industry)->produced_cargo), std::end((*industry)->produced_cargo), [](
CargoID cargo) {
1289 return cargo == CT_INVALID;
1294 const auto &pc = (*industry)->produced_cargo;
1295 produced_cargo_matches = std::find(std::begin(pc), std::end(pc), produced_cargo) != std::end(pc);
1299 return accepted_cargo_matches && produced_cargo_matches;
1314 static const StringID sorter_names[];
1324 static CargoID produced_cargo_filter;
1339 if (this->produced_cargo_filter_criteria != index) {
1340 this->produced_cargo_filter_criteria = index;
1356 if (this->accepted_cargo_filter_criteria != index) {
1357 this->accepted_cargo_filter_criteria = index;
1372 byte filter_items = 0;
1375 this->cargo_filter[filter_items] =
CF_ANY;
1376 this->cargo_filter_texts[filter_items] = STR_INDUSTRY_DIRECTORY_FILTER_ALL_TYPES;
1377 this->produced_cargo_filter_criteria = filter_items;
1378 this->accepted_cargo_filter_criteria = filter_items;
1382 this->cargo_filter[filter_items] =
CF_NONE;
1383 this->cargo_filter_texts[filter_items] = STR_INDUSTRY_DIRECTORY_FILTER_NONE;
1388 this->cargo_filter[filter_items] = cs->Index();
1389 this->cargo_filter_texts[filter_items] = cs->name;
1407 this->industries.clear();
1410 this->industries.push_back(i);
1413 this->industries.shrink_to_fit();
1417 auto filter = std::make_pair(this->cargo_filter[this->accepted_cargo_filter_criteria],
1418 this->cargo_filter[this->produced_cargo_filter_criteria]);
1420 this->industries.
Filter(filter);
1423 this->industries.
Sort();
1425 this->vscroll->
SetCount((uint)this->industries.size());
1454 CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1455 if (filter ==
CF_NONE)
return 0;
1457 int percentage = 0, produced_cargo_count = 0;
1461 if (transported != -1) {
1462 produced_cargo_count++;
1463 percentage += transported;
1473 if (produced_cargo_count == 0)
return percentage;
1474 return percentage / produced_cargo_count;
1480 int r =
strnatcmp(a->GetCachedName(), b->GetCachedName());
1492 int r = it_a - it_b;
1499 CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1502 uint prod_a = 0, prod_b = 0;
1512 int r = prod_a - prod_b;
1547 std::vector<CargoInfo> cargos;
1559 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1560 if (a.production != b.production) return a.production > b.production;
1561 return a.transported > b.transported;
1567 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1568 if (a.transported != b.transported) return a.transported > b.transported;
1569 return a.production > b.production;
1578 auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](
const CargoInfo &ci) ->
bool {
1579 return ci.cargo_id == cid;
1581 if (filtered_ci != cargos.end()) {
1582 std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1587 for (
size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
1588 CargoInfo ci = cargos[j];
1589 SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1600 switch (cargos.size()) {
1601 case 0:
return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1602 case 1:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1603 case 2:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1604 case 3:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1605 default:
return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1615 this->industries.
SetListing(this->last_sorting);
1616 this->industries.
SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1625 this->last_sorting = this->industries.
GetListing();
1637 SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.
SortType()]);
1641 SetDParam(0, this->cargo_filter_texts[this->accepted_cargo_filter_criteria]);
1645 SetDParam(0, this->cargo_filter_texts[this->produced_cargo_filter_criteria]);
1660 if (this->industries.size() == 0) {
1666 for (uint i = this->vscroll->
GetPosition(); i < this->industries.size(); i++) {
1690 d.height += padding.height;
1691 *size =
maxdim(*size, d);
1697 for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] !=
INVALID_STRING_ID; i++) {
1700 d.width += padding.width;
1701 d.height += padding.height;
1702 *size =
maxdim(*size, d);
1708 for (uint i = 0; i < this->industries.size(); i++) {
1711 resize->height = d.height;
1715 *size =
maxdim(*size, d);
1744 if (p < this->industries.size()) {
1760 if (this->industries.
SortType() != index) {
1806 case IDIWD_FORCE_REBUILD:
1811 case IDIWD_PRODUCTION_CHANGE:
1822 Listing IndustryDirectoryWindow::last_sorting = {
false, 0};
1826 &IndustryNameSorter,
1827 &IndustryTypeSorter,
1828 &IndustryProductionSorter,
1829 &IndustryTransportedCargoSorter
1833 const StringID IndustryDirectoryWindow::sorter_names[] = {
1836 STR_SORT_BY_PRODUCTION,
1837 STR_SORT_BY_TRANSPORTED,
1841 CargoID IndustryDirectoryWindow::produced_cargo_filter =
CF_ANY;
1846 WDP_AUTO,
"list_industries", 428, 190,
1852 void ShowIndustryDirectory()
1871 SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1874 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1876 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1888 WDP_AUTO,
"industry_cargoes", 300, 210,
1964 this->u.industry.ind_type =
ind_type;
1982 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
1983 if (
cargo == this->u.cargo.vertical_cargoes[i]) {
1988 if (column < 0)
return -1;
1991 assert(this->u.cargo.supp_cargoes[column] ==
INVALID_CARGO);
1992 this->u.cargo.supp_cargoes[column] = column;
1994 assert(this->u.cargo.cust_cargoes[column] ==
INVALID_CARGO);
1995 this->u.cargo.cust_cargoes[column] = column;
2009 if (this->u.cargo.supp_cargoes[i] !=
INVALID_CARGO)
return true;
2010 if (this->u.cargo.cust_cargoes[i] !=
INVALID_CARGO)
return true;
2031 this->u.cargo.vertical_cargoes[num] =
cargoes[i];
2035 this->u.cargo.num_cargoes = (count < 0) ? num : count;
2037 this->u.cargo.top_end =
top_end;
2053 for (i = 0; i <
MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] =
cargoes[i];
2065 this->u.header = textid;
2076 int n = this->u.cargo.num_cargoes;
2086 void Draw(
int xpos,
int ypos)
const
2088 switch (this->type) {
2112 int blob_left, blob_right;
2127 const CargoID *other_right, *other_left;
2129 other_right = this->u.industry.other_accepted;
2130 other_left = this->u.industry.other_produced;
2132 other_right = this->u.industry.other_produced;
2133 other_left = this->u.industry.other_accepted;
2158 int colpos = cargo_base;
2159 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
2171 const CargoID *hor_left, *hor_right;
2173 hor_left = this->u.cargo.cust_cargoes;
2174 hor_right = this->u.cargo.supp_cargoes;
2176 hor_left = this->u.cargo.supp_cargoes;
2177 hor_right = this->u.cargo.cust_cargoes;
2182 int col = hor_left[i];
2185 for (; col > 0; col--) {
2193 int col = hor_right[i];
2196 for (; col < this->u.cargo.num_cargoes - 1; col++) {
2239 for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2240 if (pt.x < cpos)
break;
2257 if (this->u.cargo.supp_cargoes[row] !=
INVALID_CARGO)
return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
2258 if (left !=
nullptr) {
2264 if (col == this->u.cargo.num_cargoes) {
2265 if (this->u.cargo.cust_cargoes[row] !=
INVALID_CARGO)
return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
2266 if (right !=
nullptr) {
2277 return (this->u.cargo.supp_cargoes[row] !=
INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]] :
INVALID_CARGO;
2280 return (this->u.cargo.cust_cargoes[row] !=
INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]] :
INVALID_CARGO;
2301 return this->u.cargo_label.cargoes[row];
2359 int other_count = 0;
2364 int col = cargo_fld->
ConnectCargo(indsp->produced_cargo[i],
true);
2365 if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2369 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2374 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2376 if (cid == CT_PASSENGERS || cid == CT_MAIL) cargo_fld->
ConnectCargo(cid,
true);
2392 CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2395 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2396 int col = cargo_fld->
ConnectCargo(cargo_fld->u.
cargo.vertical_cargoes[i], !accepting);
2397 if (col >= 0) cargoes[col] = cargo_fld->u.
cargo.vertical_cargoes[i];
2417 int other_count = 0;
2423 if (col < 0) others[other_count++] = indsp->
accepts_cargo[i];
2427 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2432 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2481 typedef std::vector<CargoesRow> Fields;
2528 this->ind_textsize.width = 0;
2529 this->ind_textsize.height = 0;
2533 if (!indsp->
enabled)
continue;
2538 d.width = std::max(d.width, this->ind_textsize.width);
2539 d.height = this->ind_textsize.height;
2543 this->cargo_textsize.width = 0;
2544 this->cargo_textsize.height = 0;
2547 if (!csp->
IsValid())
continue;
2550 d =
maxdim(d, this->cargo_textsize);
2575 size->width = std::max(size->width, this->ind_textsize.width + padding.width);
2579 size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
2609 while (length1 > 0) {
2611 for (uint i = 0; i < length2; i++)
if (*cargoes1 == cargoes2[i])
return true;
2627 for (uint i = 0; i < length; i++) {
2629 if (cargoes[i] == CT_PASSENGERS || cargoes[i] == CT_MAIL)
return true;
2644 case LT_TEMPERATE: climate_mask =
HZ_TEMP;
break;
2647 case LT_TOYLAND: climate_mask =
HZ_TOYLND;
break;
2648 default: NOT_REACHED();
2650 for (uint i = 0; i < length; i++) {
2676 if (!indsp->
enabled)
continue;
2694 if (!indsp->
enabled)
continue;
2709 while (top < bottom && !this->
fields[
top].columns[column].HasConnection()) {
2710 this->fields[
top].columns[column].MakeEmpty(
CFT_EMPTY);
2713 this->fields[
top].columns[column].u.cargo.top_end =
true;
2715 while (bottom >
top && !this->fields[bottom].columns[column].HasConnection()) {
2716 this->fields[bottom].columns[column].MakeEmpty(
CFT_EMPTY);
2719 this->fields[bottom].columns[column].u.cargo.bottom_end =
true;
2731 this->fields[row].columns[col].MakeIndustry(it);
2733 this->fields[row].ConnectIndustryProduced(col);
2735 this->fields[row].ConnectIndustryAccepted(col);
2757 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
2758 this->ind_cargo = displayed_it;
2762 this->fields.clear();
2763 CargoesRow &row = this->fields.emplace_back();
2776 int num_indrows = std::max(3, std::max(num_supp, num_cust));
2777 for (
int i = 0; i < num_indrows; i++) {
2778 CargoesRow &row = this->fields.emplace_back();
2786 int central_row = 1 + num_indrows / 2;
2787 this->fields[central_row].columns[2].MakeIndustry(displayed_it);
2788 this->fields[central_row].ConnectIndustryProduced(2);
2789 this->fields[central_row].ConnectIndustryAccepted(2);
2792 this->fields[central_row - 1].MakeCargoLabel(2,
true);
2793 this->fields[central_row + 1].MakeCargoLabel(2,
false);
2800 if (!indsp->
enabled)
continue;
2803 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2808 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
2813 if (houses_supply) {
2817 if (houses_accept) {
2824 this->vscroll->
SetCount(num_indrows);
2835 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
2839 this->fields.clear();
2840 CargoesRow &row = this->fields.emplace_back();
2851 int num_indrows = std::max(num_supp, num_cust);
2852 for (
int i = 0; i < num_indrows; i++) {
2853 CargoesRow &row = this->fields.emplace_back();
2861 this->fields[num_indrows].MakeCargoLabel(0,
false);
2868 if (!indsp->
enabled)
continue;
2871 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2876 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2881 if (houses_supply) {
2885 if (houses_accept) {
2891 this->vscroll->
SetCount(num_indrows);
2905 if (!gui_scope)
return;
2923 int width = r.right - r.left + 1;
2927 _cur_dpi = &tmp_dpi;
2935 for (uint i = 0; i < this->fields.size(); i++) {
2937 if (vpos + row_height >= 0) {
2938 int xpos = left_pos;
2947 while (col >= 0 && col <= last_column) {
2948 this->fields[i].columns[col].Draw(xpos, vpos);
2954 if (vpos >=
height)
break;
2974 if (pt.y < vpos)
return false;
2977 if (row + 1 >= (
int)this->fields.size())
return false;
2982 if (pt.x < xpos)
return false;
2984 for (column = 0; column <= 5; column++) {
2986 if (pt.x < xpos +
width)
break;
2990 if (column > num_columns)
return false;
2997 fieldxy->x = num_columns - column;
3000 fieldxy->x = column;
3013 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3014 switch (fld->
type) {
3020 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3021 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3066 if (!indsp->
enabled)
continue;
3080 if (index < 0)
return;
3100 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3102 switch (fld->
type) {
3104 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3105 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3117 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, 0,
nullptr, close_cond);
3127 params[0] = csp->
name;
3128 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, 1, params, close_cond);
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
static const uint8 PC_WHITE
White palette colour.
struct CargoesField::@17::@20 cargo_label
Label data (for CFT_CARGO_LABEL).
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ TC_FORCED
Ignore colour changes from strings.
static const byte INVALID_CARGO
Constant representing invalid cargo.
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.
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.
@ IDW_SORT_BY_TYPE
Sorter type to sort by type.
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
uint16 count
How many industries are loaded.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
#define CMD_MSG(x)
Used to combine a StringID with the command.
uint32 TileIndex
The index/ID of a Tile.
static bool HousesCanAccept(const CargoID *cargoes, uint length)
Can houses be used as customers of the produced cargoes?
@ ID_FUND_ONLY
The game does not build industries.
@ 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
@ CBM_IND_CARGO_SUFFIX
cargo sub-type display
uint8 SortType() const
Get the sorttype of the list.
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.
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.
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
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.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
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.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
bool Sort(Comp compare)
Sort the list.
static int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
Returns percents of cargo transported if industry produces this cargo, else -1.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
static const uint8 PC_YELLOW
Yellow palette colour.
int production_offset_y
The offset of the production texts/buttons.
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 ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Dimension ind_textsize
Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
void SetFilterType(uint8 n_type)
Set the filtertype of the list.
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
void OnResize() override
Called after the window got resized.
byte bottom_end
Stop at the bottom of the vertical cargoes.
CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
@ CMD_BUILD_INDUSTRY
build a new industry
void OnResize() override
Called after the window got resized.
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
@ 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).
@ 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.
ViewportData * viewport
Pointer to viewport data, if present.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
A single row of CargoesField.
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.
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
static Dimension cargo_stub
Dimensions of cargo stub (unconnected cargo line.)
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
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.
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)
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
void SortIndustryTypes()
Initialize the list of sorted industry types.
DifficultySettings difficulty
settings related to the difficulty
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
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 _ctrl_pressed
Is Ctrl pressed?
@ SND_15_BEEP
19 == 0x13 GUI button click
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ 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.
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b)
Sort industries by type and name.
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.
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.
Specification of a cargo type.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
int32 WindowNumber
Number to differentiate different windows of the same class.
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
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 StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
@ SA_RIGHT
Right align the text (must be a single bit).
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
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)
@ PRODLEVEL_DEFAULT
default level set when the industry is created
int selected_index
index of the element in the matrix
Defines the internal data of a functional industry.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
@ CFT_INDUSTRY
Display industry.
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
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.
struct CargoesField::@17::@19 cargo
Cargo data (for CFT_CARGO).
StringID GetErrorMessage() const
Returns the error message of a command.
uint ind_cargo
If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static bool CDECL CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
@ CBM_IND_FUND_MORE_TEXT
additional text in fund window
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
CargoesFieldType type
Type of field.
void OnTimeout() override
Called when this window's timeout has been reached.
bool Succeeded() const
Did this command succeed?
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
int GetCargoBase(int xpos) const
For a CFT_CARGO, compute the left position of the left-most vertical cargo connection.
static uint TileX(TileIndex tile)
Get the X component of a tile.
@ CBID_INDUSTRY_FUND_MORE_TEXT
Called to determine more text in the fund industry window.
bool enabled[NUM_INDUSTRYTYPES+1]
availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever)
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.
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.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
void OnInit() override
Notification that the nested widget tree gets initialized.
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
High level window description.
@ CFT_CARGO
Display cargo connections.
CargoID cargo_filter[NUM_CARGO+2]
Available cargo filters; CargoID or CF_ANY or CF_NONE.
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.
@ IDW_SORT_BY_TRANSPORTED
Sorter type to sort by transported percentage.
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback.
static ClearGround GetRawClearGround(TileIndex t)
Get the type of clear tile but never return CLEAR_SNOW.
CargoSuffixDisplay
Ways of displaying the cargo.
Window displaying the cargo connections around an industry (or cargo).
bool IsDescSortOrder() const
Check if the sort order is descending.
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).
void SetFilterState(bool state)
Enable or disable the filter.
static uint MapSize()
Get the size of the map.
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b)
Sort industries by transported cargo and name.
ResizeInfo resize
Resize information.
Common return value for all commands.
TileArea location
Location of the industry.
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
Editability editable
Mode for changing production.
SoundSettings sound
sound effect settings
static const HouseID NUM_HOUSES
Total number of houses.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
void OnInit() override
Notification that the nested widget tree gets initialized.
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.
IndustryType type
type of industry.
int height
Height of the window (number of pixels down in y direction)
char text[512]
Cargo suffix text.
bool SortFunction(const const Industry * &, const const Industry * &)
Signature of sort function.
bool IsValid() const
Tests for validity of this cargospec.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void OnResize() override
Called after the window got resized.
void SetListing(Listing l)
Import sort conditions.
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
void OnPaint() override
The window must be repainted.
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
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.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
static const int BLOB_DISTANCE
Distance of the industry legend colour from the edge of the industry box.
bool IsCargoIDValid(CargoID t)
Test whether cargo type is not CT_INVALID.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
void MakeIndustry(IndustryType ind_type)
Make an industry type field.
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
void OnTimeout() override
Called when this window's timeout has been reached.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Data about a single field in the IndustryCargoesWindow panel.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
CargoID cargoes[MAX_CARGOES]
Cargoes to display (or INVALID_CARGO).
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]
incoming cargo waiting to be processed
CargoSuffixDisplay display
How to display the cargo and text.
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
void OnPaint() override
The window must be repainted.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
uint8 raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
StringID GetIndustryString(const Industry *i) const
Get the StringID to draw and set the appropriate DParams.
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.
static uint max_cargoes
Largest number of cargoes actually on any industry.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
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
static const NWidgetPart _nested_industry_view_widgets[]
Widget definition of the view industry gui.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
int left
x position of left edge of the window
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
@ CST_VIEW
View-industry window.
WindowFlags flags
Window flags.
Dimension legend
Dimension of the legend 'blob'.
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
byte industry_density
The industry density.
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
bool _networking
are we in networking mode?
StringID header
Header text (for CFT_HEADER).
CargoID vertical_cargoes[MAX_CARGOES]
Cargoes running from top to bottom (cargo ID or INVALID_CARGO).
StringID cargo_filter_texts[NUM_CARGO+3]
Texts for filter_cargo, terminated by INVALID_STRING_ID.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
struct CargoesField::@17::@18 industry
Industry data (for CFT_INDUSTRY).
@ 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.
Coordinates of a point in 2D.
static const int VERT_TEXT_PADDING
Vertical padding around the industry type text.
@ CFT_SMALL_EMPTY
Empty small field (for the header).
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.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
void Draw(int xpos, int ypos) const
Draw the field.
Editability
Modes for changing production.
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
static const uint8 PC_BLACK
Black palette colour.
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.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
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)
uint step_height
Step-size of height resize changes.
Defines the data structure for constructing industry.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b)
Sort industries by name.
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.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
TileIndex GetCenterTile() const
Get the center tile.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
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.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
static Dimension cargo_space
Dimensions of space between cargo lines.
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
@ EA_RATE
Allow changing the production rates.
bool _generating_world
Whether we are generating the map or not.
CargoFilterSpecialType
Special cargo filter criteria.
bool NeedRebuild() const
Check if a rebuild is needed.
static const NWidgetPart _nested_industry_directory_widgets[]
Widget definition of the industry directory gui.
static Dimension cargo_border
Dimensions of border between cargo lines and industry boxes.
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 IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
@ 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
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
CargoID cust_cargoes[MAX_CARGOES]
Cargoes leaving to the right (index in vertical_cargoes, or INVALID_CARGO).
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
@ SBS_DOWN
Sort ascending.
CompanyID _current_company
Company currently doing an action.
void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
Make a field displaying cargo type names.
@ CF_ANY
Show all industries (i.e. no filtering)
@ IL_RATE1
Production rate of cargo 1.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
CargoesField columns[5]
One row of fields.
span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
@ 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.
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
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.
bool IsShaded() const
Is window shaded currently?
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.
void Restore()
Restore the variable.
InfoLine editbox_line
The line clicked to open the edit box.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
byte num_cargoes
Number of cargoes.
@ CST_FUND
Fund-industry window.
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
CargoesFieldType
Available types of field.
IndustryType selected_type
industry corresponding to the above index
void ComputeCargoDisplay(CargoID cid)
Compute what and where to display for cargo id cid.
bool CDECL FilterFunction(const const Industry * *, const std::pair< CargoID, CargoID > &)
Signature of filter function.
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 OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ IDW_SORT_BY_NAME
Sorter type to sort by name.
Listing GetListing() const
Export current sort conditions.
@ OWNER_NONE
The tile has no ownership.
static int cargo_field_width
Width of a cargo field.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void ShowSmallMap()
Show the smallmap window.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
GRFFileProps grf_prop
properties related to the grf file
static const int VERT_INTER_INDUSTRY_SPACE
Amount of space between two industries in a column.
@ NUM_CARGO
Maximal number of cargo types in a game.
@ CSD_CARGO_TEXT
Display then cargo and supplied string (cb37 result 800-BFF).
@ HT_RECT
rectangle (stations, depots, ...)
InfoLine clicked_line
The line of the button that has been clicked.
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
InfoLine
Specific lines in the info panel.
HouseZones building_availability
where can it be built (climates, zones)
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.
StringID name
Name of this type of cargo.
@ CBM_IND_WINDOW_MORE_TEXT
additional text in industry window
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static const NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
int DrawInfo(uint left, uint right, uint top)
Draw the text in the WID_IV_INFO panel.
void ConnectIndustryAccepted(int column)
Connect industry accepted cargoes to the cargo column before it.
void GenerateIndustries()
This function will create random industries during game creation.
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 ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
@ SA_LEFT
Left align the text.
IndustryType index[NUM_INDUSTRYTYPES+1]
Type of industry, in the order it was loaded.
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
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.
void ForceRebuild()
Force that a rebuild is needed.
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
bool click_beep
Beep on a random selection of buttons.
#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.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Transfer storage of cargo suffix information.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
static const int HOR_TEXT_PADDING
Horizontal padding around the industry type text.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
@ CBID_INDUSTRY_WINDOW_MORE_TEXT
Called to determine more text in the industry window.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
void SetAcceptedCargoFilterIndex(byte index)
Set cargo filter list item index.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
void SetButtons()
Update status of the fund and display-chain widgets.
ConstructionSettings construction
construction of things in-game
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
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.
void RebuildDone()
Notify the sortlist that the rebuild is done.
byte clicked_button
The button that has been clicked (to raise)
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
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.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
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
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
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.
CargoesFieldType type
Type of field.
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
@ CT_INVALID
Invalid cargo type.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
byte accepted_cargo_filter_criteria
Selected accepted cargo filter index.
Specification of a rectangle with absolute coordinates of all edges.
CargoID supp_cargoes[MAX_CARGOES]
Cargoes entering from the left (index in vertical_cargoes, or INVALID_CARGO).
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.
@ CT_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
byte production_rate[INDUSTRY_NUM_OUTPUTS]
production rate for each cargo
@ IL_RATE2
Production rate of cargo 2.
#define lastof(x)
Get the last element of an fixed size array.
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
void SetProducedCargoFilterIndex(byte index)
Set cargo filter list item index.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
static const int MAX_MINWIDTH_LINEHEIGHTS
The largest allowed minimum-width of the window, given in line heights.
@ WC_SMALLMAP
Small map; Window numbers:
byte top_end
Stop at the top of the vertical cargoes.
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
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.
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
@ 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.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
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)
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b)
Sort industries by production and name.
GUISettings gui
settings related to the GUI
static Dimension cargo_line
Dimensions of cargo lines.
byte produced_cargo_filter_criteria
Selected produced cargo filter index.
CargoID other_accepted[MAX_CARGOES]
Cargoes accepted but not used in this figure.
@ CF_NONE
Show only industries which do not produce/accept cargo.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Data about how and where to blit pixels.
bool persistent_buildingtools
keep the building tools active after usage
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
@ IDW_SORT_BY_PRODUCTION
Sorter type to sort by production amount.