Merge remote-tracking branch 'upstream/master'

This commit is contained in:
pelya
2021-01-25 00:50:42 +02:00
1076 changed files with 25433 additions and 61762 deletions

View File

@@ -145,7 +145,7 @@ enum CargoSuffixInOut {
template <typename TC, typename TS>
static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
{
assert_compile(lengthof(cargoes) <= lengthof(suffixes));
static_assert(lengthof(cargoes) <= lengthof(suffixes));
if (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) {
/* Reworked behaviour with new many-in-many-out scheme */
@@ -270,8 +270,6 @@ static WindowDesc _build_industry_desc(
class BuildIndustryWindow : public Window {
int selected_index; ///< index of the element in the matrix
IndustryType selected_type; ///< industry corresponding to the above index
uint16 callback_timer; ///< timer counter for callback eventual verification
bool timer_enabled; ///< timer can be used
uint16 count; ///< How many industries are loaded
IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever)
@@ -293,7 +291,6 @@ class BuildIndustryWindow : public Window {
this->index[this->count] = INVALID_INDUSTRYTYPE;
this->enabled[this->count] = true;
this->count++;
this->timer_enabled = false;
}
/* Fill the arrays with industries.
* The tests performed after the enabled allow to load the industries
@@ -385,13 +382,9 @@ class BuildIndustryWindow : public Window {
public:
BuildIndustryWindow() : Window(&_build_industry_desc)
{
this->timer_enabled = _loaded_newgrf_features.has_newindustries;
this->selected_index = -1;
this->selected_type = INVALID_INDUSTRYTYPE;
this->callback_timer = DAY_TICKS;
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
this->FinishInitNested(0);
@@ -425,10 +418,11 @@ public:
}
case WID_DPI_INFOPANEL: {
/* Extra line for cost outside of editor + extra lines for 'extra' information for NewGRFs. */
int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1) + (_loaded_newgrf_features.has_newindustries ? 4 : 0);
/* Extra line for cost outside of editor. */
int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
uint extra_lines_req = 0;
uint extra_lines_prd = 0;
uint extra_lines_newgrf = 0;
uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
Dimension d = {0, 0};
for (byte i = 0; i < this->count; i++) {
@@ -442,7 +436,7 @@ public:
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
Dimension strdim = GetStringBoundingBox(cargostring.c_str());
if (strdim.width > max_minwidth) {
extra_lines_req = max(extra_lines_req, strdim.width / max_minwidth + 1);
extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
strdim.width = max_minwidth;
}
d = maxdim(d, strdim);
@@ -452,14 +446,19 @@ public:
cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
strdim = GetStringBoundingBox(cargostring.c_str());
if (strdim.width > max_minwidth) {
extra_lines_prd = max(extra_lines_prd, strdim.width / max_minwidth + 1);
extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
strdim.width = max_minwidth;
}
d = maxdim(d, strdim);
if (indsp->grf_prop.grffile != nullptr) {
/* Reserve a few extra lines for text from an industry NewGRF. */
extra_lines_newgrf = 4;
}
}
/* Set it to something more sane :) */
height += extra_lines_prd + extra_lines_req;
height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
size->height = height * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
size->width = d.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
break;
@@ -692,25 +691,19 @@ public:
if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
}
void OnGameTick() override
void OnHundredthTick() override
{
if (!this->timer_enabled) return;
if (--this->callback_timer == 0) {
/* We have just passed another day.
* See if we need to update availability of currently selected industry */
this->callback_timer = DAY_TICKS; // restart counter
if (_game_mode == GM_EDITOR) return;
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
if (indsp->enabled) {
bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
if (indsp->enabled) {
bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
/* Only if result does match the previous state would it require a redraw. */
if (call_back_result != this->enabled[this->selected_index]) {
this->enabled[this->selected_index] = call_back_result;
this->SetButtons();
this->SetDirty();
}
/* Only if result does match the previous state would it require a redraw. */
if (call_back_result != this->enabled[this->selected_index]) {
this->enabled[this->selected_index] = call_back_result;
this->SetButtons();
this->SetDirty();
}
}
}
@@ -942,6 +935,13 @@ public:
}
}
}
if (!i->text.empty()) {
SetDParamStr(0, i->text.c_str());
y += WD_PAR_VSEP_WIDE;
y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
}
return y + WD_FRAMERECT_BOTTOM;
}
@@ -997,22 +997,22 @@ public:
case EA_MULTIPLIER:
if (button == 1) {
if (i->prod_level <= PRODLEVEL_MINIMUM) return;
i->prod_level = max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM);
i->prod_level = std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM);
} else {
if (i->prod_level >= PRODLEVEL_MAXIMUM) return;
i->prod_level = minu(i->prod_level * 2, PRODLEVEL_MAXIMUM);
i->prod_level = std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
}
break;
case EA_RATE:
if (button == 1) {
if (i->production_rate[line - IL_RATE1] <= 0) return;
i->production_rate[line - IL_RATE1] = max(i->production_rate[line - IL_RATE1] / 2, 0);
i->production_rate[line - IL_RATE1] = std::max(i->production_rate[line - IL_RATE1] / 2, 0);
} else {
if (i->production_rate[line - IL_RATE1] >= 255) return;
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
i->production_rate[line - IL_RATE1] = minu(new_prod, 255);
i->production_rate[line - IL_RATE1] = std::min<uint>(new_prod, 255);
}
break;
@@ -1047,7 +1047,7 @@ public:
case WID_IV_GOTO: {
Industry *i = Industry::Get(this->window_number);
if (_ctrl_pressed) {
ShowExtraViewPortWindow(i->location.GetCenterTile());
ShowExtraViewportWindow(i->location.GetCenterTile());
} else {
ScrollMainWindowToTile(i->location.GetCenterTile());
}
@@ -1111,7 +1111,7 @@ public:
const Industry *i = Industry::Get(this->window_number);
if (IsProductionAlterable(i)) {
const IndustrySpec *ind = GetIndustrySpec(i->type);
this->editable = ind->UsesSmoothEconomy() ? EA_RATE : EA_MULTIPLIER;
this->editable = ind->UsesOriginalEconomy() ? EA_MULTIPLIER : EA_RATE;
} else {
this->editable = EA_NONE;
}
@@ -1131,7 +1131,7 @@ public:
static void UpdateIndustryProduction(Industry *i)
{
const IndustrySpec *indspec = GetIndustrySpec(i->type);
if (!indspec->UsesSmoothEconomy()) i->RecomputeProductionMultipliers();
if (indspec->UsesOriginalEconomy()) i->RecomputeProductionMultipliers();
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->produced_cargo[j] != CT_INVALID) {
@@ -1145,6 +1145,7 @@ static const NWidgetPart _nested_industry_view_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_CREAM),
NWidget(WWT_CAPTION, COLOUR_CREAM, WID_IV_CAPTION), SetDataTip(STR_INDUSTRY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHIMGBTN, COLOUR_CREAM, WID_IV_GOTO), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_INDUSTRY_VIEW_LOCATION_TOOLTIP),
NWidget(WWT_DEBUGBOX, COLOUR_CREAM),
NWidget(WWT_SHADEBOX, COLOUR_CREAM),
NWidget(WWT_DEFSIZEBOX, COLOUR_CREAM),
@@ -1158,7 +1159,6 @@ static const NWidgetPart _nested_industry_view_widgets[] = {
NWidget(WWT_PANEL, COLOUR_CREAM, WID_IV_INFO), SetMinimalSize(260, 2), SetResize(1, 0),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_GOTO), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_BUTTON_LOCATION, STR_INDUSTRY_VIEW_LOCATION_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_DISPLAY), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
NWidget(WWT_RESIZEBOX, COLOUR_CREAM),
EndContainer(),
@@ -1285,14 +1285,14 @@ protected:
CargoID cargo_filter[NUM_CARGO + 2]; ///< Available cargo filters; CargoID or CF_ANY or CF_NONE
StringID cargo_filter_texts[NUM_CARGO + 3]; ///< Texts for filter_cargo, terminated by INVALID_STRING_ID
CargoID produced_cargo_filter_criteria; ///< Selected produced cargo filter
CargoID accepted_cargo_filter_criteria; ///< Selected accepted cargo filter
byte produced_cargo_filter_criteria; ///< Selected produced cargo filter index
byte accepted_cargo_filter_criteria; ///< Selected accepted cargo filter index
/**
* Set cargo filter list item index.
* @param index The index of the cargo to be set
*/
void SetProducedCargoFilterIndex(int index)
void SetProducedCargoFilterIndex(byte index)
{
if (this->produced_cargo_filter_criteria != index) {
this->produced_cargo_filter_criteria = index;
@@ -1309,7 +1309,7 @@ protected:
* Set cargo filter list item index.
* @param index The index of the cargo to be set
*/
void SetAcceptedCargoFilterIndex(int index)
void SetAcceptedCargoFilterIndex(byte index)
{
if (this->accepted_cargo_filter_criteria != index) {
this->accepted_cargo_filter_criteria = index;
@@ -1327,7 +1327,7 @@ protected:
*/
void SetCargoFilterArray()
{
uint filter_items = 0;
byte filter_items = 0;
/* Add item for disabling filtering. */
this->cargo_filter[filter_items] = CF_ANY;
@@ -1499,7 +1499,7 @@ protected:
}
/* Display first 3 cargos */
for (size_t j = 0; j < min<size_t>(3, cargos.size()); j++) {
for (size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
CargoInfo ci = cargos[j];
SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
SetDParam(p++, std::get<0>(ci));
@@ -1658,7 +1658,7 @@ public:
uint p = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_ID_INDUSTRY_LIST, WD_FRAMERECT_TOP);
if (p < this->industries.size()) {
if (_ctrl_pressed) {
ShowExtraViewPortWindow(this->industries[p]->location.tile);
ShowExtraViewportWindow(this->industries[p]->location.tile);
} else {
ScrollMainWindowToTile(this->industries[p]->location.tile);
}
@@ -2232,8 +2232,8 @@ private:
}
};
assert_compile(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
assert_compile(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
int CargoesField::small_height; ///< Height of the header row.
int CargoesField::normal_height; ///< Height of the non-header rows.
@@ -2430,10 +2430,10 @@ struct IndustryCargoesWindow : public Window {
const IndustrySpec *indsp = GetIndustrySpec(it);
if (!indsp->enabled) continue;
this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
CargoesField::max_cargoes = max<uint>(CargoesField::max_cargoes, std::count_if(indsp->accepts_cargo, endof(indsp->accepts_cargo), IsCargoIDValid));
CargoesField::max_cargoes = max<uint>(CargoesField::max_cargoes, std::count_if(indsp->produced_cargo, endof(indsp->produced_cargo), IsCargoIDValid));
CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->accepts_cargo, endof(indsp->accepts_cargo), IsCargoIDValid));
CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->produced_cargo, endof(indsp->produced_cargo), IsCargoIDValid));
}
d.width = max(d.width, this->ind_textsize.width);
d.width = std::max(d.width, this->ind_textsize.width);
d.height = this->ind_textsize.height;
this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY));
@@ -2451,7 +2451,7 @@ struct IndustryCargoesWindow : public Window {
d.width += 2 * HOR_TEXT_PADDING;
/* Ensure the height is enough for the industry type text, for the horizontal connections, and for the cargo labels. */
uint min_ind_height = CargoesField::VERT_CARGO_EDGE * 2 + CargoesField::max_cargoes * FONT_HEIGHT_NORMAL + (CargoesField::max_cargoes - 1) * CargoesField::VERT_CARGO_SPACE;
d.height = max(d.height + 2 * VERT_TEXT_PADDING, min_ind_height);
d.height = std::max(d.height + 2 * VERT_TEXT_PADDING, min_ind_height);
CargoesField::industry_width = d.width;
CargoesField::normal_height = d.height + CargoesField::VERT_INTER_INDUSTRY_SPACE;
@@ -2468,11 +2468,11 @@ struct IndustryCargoesWindow : public Window {
break;
case WID_IC_IND_DROPDOWN:
size->width = max(size->width, this->ind_textsize.width + padding.width);
size->width = std::max(size->width, this->ind_textsize.width + padding.width);
break;
case WID_IC_CARGO_DROPDOWN:
size->width = max(size->width, this->cargo_textsize.width + padding.width);
size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
break;
}
}
@@ -2656,8 +2656,7 @@ struct IndustryCargoesWindow : public Window {
_displayed_industries.set(it);
this->fields.clear();
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
CargoesRow &row = this->fields.emplace_back();
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[2].MakeEmpty(CFT_SMALL_EMPTY);
@@ -2670,10 +2669,9 @@ struct IndustryCargoesWindow : public Window {
/* Make a field consisting of two cargo columns. */
int num_supp = CountMatchingProducingIndustries(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)) + houses_supply;
int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept;
int num_indrows = max(3, max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels.
int num_indrows = std::max(3, std::max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels.
for (int i = 0; i < num_indrows; i++) {
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
CargoesRow &row = this->fields.emplace_back();
row.columns[0].MakeEmpty(CFT_EMPTY);
row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
row.columns[2].MakeEmpty(CFT_EMPTY);
@@ -2736,8 +2734,7 @@ struct IndustryCargoesWindow : public Window {
_displayed_industries.reset();
this->fields.clear();
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
CargoesRow &row = this->fields.emplace_back();
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
@@ -2748,10 +2745,9 @@ struct IndustryCargoesWindow : public Window {
bool houses_accept = HousesCanAccept(&cid, 1);
int num_supp = CountMatchingProducingIndustries(&cid, 1) + houses_supply + 1; // Ensure room for the cargo label.
int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
int num_indrows = max(num_supp, num_cust);
int num_indrows = std::max(num_supp, num_cust);
for (int i = 0; i < num_indrows; i++) {
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
CargoesRow &row = this->fields.emplace_back();
row.columns[0].MakeEmpty(CFT_EMPTY);
row.columns[1].MakeCargo(&cid, 1);
row.columns[2].MakeEmpty(CFT_EMPTY);