1
0
Fork 0

Compare commits

..

No commits in common. "fd2dd4397feaca12a57046290caa4bfd0f0e2a7f" and "6580ff1adb835a3a10898a0acec60baac03dcc5c" have entirely different histories.

22 changed files with 129 additions and 129 deletions

View File

@ -73,15 +73,10 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
include: include:
- name: Clang - Debug - name: Clang
compiler: clang compiler: clang
cxxcompiler: clang++ cxxcompiler: clang++
libraries: libsdl2-dev libraries: libsdl2-dev
- name: Clang - Release
compiler: clang
cxxcompiler: clang++
libraries: libsdl2-dev
extra-cmake-parameters: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPTION_USE_ASSERTS=OFF
- name: GCC - SDL2 - name: GCC - SDL2
compiler: gcc compiler: gcc
cxxcompiler: g++ cxxcompiler: g++

View File

@ -87,7 +87,7 @@ struct BuildAirToolbarWindow : Window {
this->InitNested(window_number); this->InitNested(window_number);
this->OnInvalidateData(); this->OnInvalidateData();
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this); if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
this->last_user_action = INVALID_WID_AT; this->last_user_action = WIDGET_LIST_END;
} }
void Close() override void Close() override

View File

@ -41,33 +41,41 @@ void SetupCargoForClimate(LandscapeID l)
{ {
assert(l < lengthof(_default_climate_cargo)); assert(l < lengthof(_default_climate_cargo));
_cargo_mask = 0; /* Reset and disable all cargo types */
for (CargoID i = 0; i < lengthof(CargoSpec::array); i++) {
*CargoSpec::Get(i) = {};
CargoSpec::Get(i)->bitnum = INVALID_CARGO;
/* Copy from default cargo by label or index. */ /* Set defaults for newer properties, which old GRFs do not know */
auto insert = std::begin(CargoSpec::array); CargoSpec::Get(i)->multiplier = 0x100;
for (const CargoLabel &cl : _default_climate_cargo[l]) {
/* Check if value is an index into the cargo table */
if (cl < lengthof(_default_cargo)) {
/* Copy the default cargo by index. */
*insert = _default_cargo[cl];
} else {
/* Search for label in default cargo types and copy if found. */
auto found = std::find_if(std::begin(_default_cargo), std::end(_default_cargo), [&cl](const CargoSpec &cs) { return cs.label == cl; });
if (found != std::end(_default_cargo)) {
*insert = *found;
} else {
/* Index or label is invalid, this should not happen. */
NOT_REACHED();
}
}
if (insert->IsValid()) SetBit(_cargo_mask, insert->Index());
++insert;
} }
/* Reset and disable remaining cargo types. */ _cargo_mask = 0;
std::fill(insert, std::end(CargoSpec::array), CargoSpec{});
for (CargoID i = 0; i < lengthof(_default_climate_cargo[l]); i++) {
CargoLabel cl = _default_climate_cargo[l][i];
/* Bzzt: check if cl is just an index into the cargo table */
if (cl < lengthof(_default_cargo)) {
/* Copy the indexed cargo */
CargoSpec *cargo = CargoSpec::Get(i);
*cargo = _default_cargo[cl];
if (cargo->bitnum != INVALID_CARGO) SetBit(_cargo_mask, i);
continue;
}
/* Loop through each of the default cargo types to see if
* the label matches */
for (uint j = 0; j < lengthof(_default_cargo); j++) {
if (_default_cargo[j].label == cl) {
*CargoSpec::Get(i) = _default_cargo[j];
/* Populate the available cargo mask */
SetBit(_cargo_mask, i);
break;
}
}
}
} }
/** /**
@ -115,7 +123,7 @@ CargoID GetCargoIDByLabel(CargoLabel cl)
*/ */
CargoID GetCargoIDByBitnum(uint8_t bitnum) CargoID GetCargoIDByBitnum(uint8_t bitnum)
{ {
if (bitnum == INVALID_CARGO_BITNUM) return CT_INVALID; if (bitnum == INVALID_CARGO) return CT_INVALID;
for (const CargoSpec *cs : CargoSpec::Iterate()) { for (const CargoSpec *cs : CargoSpec::Iterate()) {
if (cs->bitnum == bitnum) return cs->Index(); if (cs->bitnum == bitnum) return cs->Index();

View File

@ -50,17 +50,16 @@ enum CargoClass {
CC_SPECIAL = 1 << 15, ///< Special bit used for livery refit tricks instead of normal cargoes. CC_SPECIAL = 1 << 15, ///< Special bit used for livery refit tricks instead of normal cargoes.
}; };
static const byte INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invalid cargo static const byte INVALID_CARGO = 0xFF; ///< Constant representing invalid cargo
/** Specification of a cargo type. */ /** Specification of a cargo type. */
struct CargoSpec { struct CargoSpec {
uint8_t bitnum; ///< Cargo bit number, is #INVALID_CARGO for a non-used spec.
CargoLabel label; ///< Unique label of the cargo type. CargoLabel label; ///< Unique label of the cargo type.
uint8_t bitnum{INVALID_CARGO_BITNUM}; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec.
uint8_t legend_colour; uint8_t legend_colour;
uint8_t rating_colour; uint8_t rating_colour;
uint8_t weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg). uint8_t weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
uint16_t multiplier{0x100}; ///< Capacity multiplier for vehicles. (8 fractional bits) uint16_t multiplier; ///< Capacity multiplier for vehicles. (8 fractional bits)
uint16_t classes; ///< Classes of this cargo type. @see CargoClass
int32_t initial_payment; ///< Initial payment rate before inflation is applied. int32_t initial_payment; ///< Initial payment rate before inflation is applied.
uint8_t transit_periods[2]; uint8_t transit_periods[2];
@ -76,6 +75,7 @@ struct CargoSpec {
SpriteID sprite; ///< Icon to display this cargo type, may be \c 0xFFF (which means to resolve an action123 chain). SpriteID sprite; ///< Icon to display this cargo type, may be \c 0xFFF (which means to resolve an action123 chain).
uint16_t classes; ///< Classes of this cargo type. @see CargoClass
const struct GRFFile *grffile; ///< NewGRF where #group belongs to. const struct GRFFile *grffile; ///< NewGRF where #group belongs to.
const struct SpriteGroup *group; const struct SpriteGroup *group;
@ -97,7 +97,7 @@ struct CargoSpec {
*/ */
inline bool IsValid() const inline bool IsValid() const
{ {
return this->bitnum != INVALID_CARGO_BITNUM; return this->bitnum != INVALID_CARGO;
} }
/** /**

View File

@ -884,10 +884,16 @@ struct GenerateLandscapeWindow : public Window {
void OnTimeout() override void OnTimeout() override
{ {
if (mode == GLWM_HEIGHTMAP) { static const int newgame_raise_widgets[] = {WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN, WIDGET_LIST_END};
this->RaiseWidgetsWhenLowered(WID_GL_HEIGHTMAP_HEIGHT_DOWN, WID_GL_HEIGHTMAP_HEIGHT_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN); static const int heightmap_raise_widgets[] = {WID_GL_HEIGHTMAP_HEIGHT_DOWN, WID_GL_HEIGHTMAP_HEIGHT_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN, WIDGET_LIST_END};
} else {
this->RaiseWidgetsWhenLowered(WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN); const int *widget = (mode == GLWM_HEIGHTMAP) ? heightmap_raise_widgets : newgame_raise_widgets;
for (; *widget != WIDGET_LIST_END; widget++) {
if (this->IsWidgetLowered(*widget)) {
this->RaiseWidget(*widget);
this->SetWidgetDirty(*widget);
}
} }
} }
@ -1226,7 +1232,13 @@ struct CreateScenarioWindow : public Window
void OnTimeout() override void OnTimeout() override
{ {
this->RaiseWidgetsWhenLowered(WID_CS_START_DATE_DOWN, WID_CS_START_DATE_UP, WID_CS_FLAT_LAND_HEIGHT_DOWN, WID_CS_FLAT_LAND_HEIGHT_UP); static const int raise_widgets[] = {WID_CS_START_DATE_DOWN, WID_CS_START_DATE_UP, WID_CS_FLAT_LAND_HEIGHT_DOWN, WID_CS_FLAT_LAND_HEIGHT_UP, WIDGET_LIST_END};
for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
if (this->IsWidgetLowered(*widget)) {
this->RaiseWidget(*widget);
this->SetWidgetDirty(*widget);
}
}
} }
void OnDropdownSelect(int widget, int index) override void OnDropdownSelect(int widget, int index) override

View File

@ -1947,15 +1947,15 @@ struct CargoesField {
CargoID other_accepted[MAX_CARGOES]; ///< Cargoes accepted but not used in this figure. CargoID other_accepted[MAX_CARGOES]; ///< Cargoes accepted but not used in this figure.
} industry; ///< Industry data (for #CFT_INDUSTRY). } industry; ///< Industry data (for #CFT_INDUSTRY).
struct { struct {
CargoID vertical_cargoes[MAX_CARGOES]; ///< Cargoes running from top to bottom (cargo ID or #CT_INVALID). CargoID vertical_cargoes[MAX_CARGOES]; ///< Cargoes running from top to bottom (cargo ID or #INVALID_CARGO).
byte num_cargoes; ///< Number of cargoes. byte num_cargoes; ///< Number of cargoes.
CargoID supp_cargoes[MAX_CARGOES]; ///< Cargoes entering from the left (index in #vertical_cargoes, or #CT_INVALID). CargoID supp_cargoes[MAX_CARGOES]; ///< Cargoes entering from the left (index in #vertical_cargoes, or #INVALID_CARGO).
byte top_end; ///< Stop at the top of the vertical cargoes. byte top_end; ///< Stop at the top of the vertical cargoes.
CargoID cust_cargoes[MAX_CARGOES]; ///< Cargoes leaving to the right (index in #vertical_cargoes, or #CT_INVALID). CargoID cust_cargoes[MAX_CARGOES]; ///< Cargoes leaving to the right (index in #vertical_cargoes, or #INVALID_CARGO).
byte bottom_end; ///< Stop at the bottom of the vertical cargoes. byte bottom_end; ///< Stop at the bottom of the vertical cargoes.
} cargo; ///< Cargo data (for #CFT_CARGO). } cargo; ///< Cargo data (for #CFT_CARGO).
struct { struct {
CargoID cargoes[MAX_CARGOES]; ///< Cargoes to display (or #CT_INVALID). CargoID cargoes[MAX_CARGOES]; ///< Cargoes to display (or #INVALID_CARGO).
bool left_align; ///< Align all cargo texts to the left (else align to the right). bool left_align; ///< Align all cargo texts to the left (else align to the right).
} cargo_label; ///< Label data (for #CFT_CARGO_LABEL). } cargo_label; ///< Label data (for #CFT_CARGO_LABEL).
StringID header; ///< Header text (for #CFT_HEADER). StringID header; ///< Header text (for #CFT_HEADER).
@ -1979,8 +1979,8 @@ struct CargoesField {
{ {
this->type = CFT_INDUSTRY; this->type = CFT_INDUSTRY;
this->u.industry.ind_type = ind_type; this->u.industry.ind_type = ind_type;
MemSetT(this->u.industry.other_accepted, CT_INVALID, MAX_CARGOES); MemSetT(this->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
MemSetT(this->u.industry.other_produced, CT_INVALID, MAX_CARGOES); MemSetT(this->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
} }
/** /**
@ -2031,7 +2031,7 @@ struct CargoesField {
/** /**
* Make a piece of cargo column. * Make a piece of cargo column.
* @param cargoes Array of #CargoID (may contain #CT_INVALID). * @param cargoes Array of #CargoID (may contain #INVALID_CARGO).
* @param length Number of cargoes in \a cargoes. * @param length Number of cargoes in \a cargoes.
* @param count Number of cargoes to display (should be at least the number of valid cargoes, or \c -1 to let the method compute it). * @param count Number of cargoes to display (should be at least the number of valid cargoes, or \c -1 to let the method compute it).
* @param top_end This is the first cargo field of this column. * @param top_end This is the first cargo field of this column.
@ -2050,16 +2050,16 @@ struct CargoesField {
} }
} }
this->u.cargo.num_cargoes = (count < 0) ? num : count; this->u.cargo.num_cargoes = (count < 0) ? num : count;
for (; num < MAX_CARGOES; num++) this->u.cargo.vertical_cargoes[num] = CT_INVALID; for (; num < MAX_CARGOES; num++) this->u.cargo.vertical_cargoes[num] = INVALID_CARGO;
this->u.cargo.top_end = top_end; this->u.cargo.top_end = top_end;
this->u.cargo.bottom_end = bottom_end; this->u.cargo.bottom_end = bottom_end;
MemSetT(this->u.cargo.supp_cargoes, CT_INVALID, MAX_CARGOES); MemSetT(this->u.cargo.supp_cargoes, INVALID_CARGO, MAX_CARGOES);
MemSetT(this->u.cargo.cust_cargoes, CT_INVALID, MAX_CARGOES); MemSetT(this->u.cargo.cust_cargoes, INVALID_CARGO, MAX_CARGOES);
} }
/** /**
* Make a field displaying cargo type names. * Make a field displaying cargo type names.
* @param cargoes Array of #CargoID (may contain #CT_INVALID). * @param cargoes Array of #CargoID (may contain #INVALID_CARGO).
* @param length Number of cargoes in \a cargoes. * @param length Number of cargoes in \a cargoes.
* @param left_align ALign texts to the left (else to the right). * @param left_align ALign texts to the left (else to the right).
*/ */
@ -2068,7 +2068,7 @@ struct CargoesField {
this->type = CFT_CARGO_LABEL; this->type = CFT_CARGO_LABEL;
uint i; uint i;
for (i = 0; i < MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] = cargoes[i]; for (i = 0; i < MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] = cargoes[i];
for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = CT_INVALID; for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = INVALID_CARGO;
this->u.cargo_label.left_align = left_align; this->u.cargo_label.left_align = left_align;
} }
@ -2244,7 +2244,7 @@ struct CargoesField {
* @param left Left industry neighbour if available (else \c nullptr should be supplied). * @param left Left industry neighbour if available (else \c nullptr should be supplied).
* @param right Right industry neighbour if available (else \c nullptr should be supplied). * @param right Right industry neighbour if available (else \c nullptr should be supplied).
* @param pt Click position in the cargo field. * @param pt Click position in the cargo field.
* @return Cargo clicked at, or #CT_INVALID if none. * @return Cargo clicked at, or #INVALID_CARGO if none.
*/ */
CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
{ {
@ -2263,11 +2263,11 @@ struct CargoesField {
int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.width; int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.width;
uint row; uint row;
for (row = 0; row < MAX_CARGOES; row++) { for (row = 0; row < MAX_CARGOES; row++) {
if (pt.y < vpos) return CT_INVALID; if (pt.y < vpos) return INVALID_CARGO;
if (pt.y < vpos + FONT_HEIGHT_NORMAL) break; if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
vpos += FONT_HEIGHT_NORMAL + CargoesField::cargo_space.width; vpos += FONT_HEIGHT_NORMAL + CargoesField::cargo_space.width;
} }
if (row == MAX_CARGOES) return CT_INVALID; if (row == MAX_CARGOES) return INVALID_CARGO;
/* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */ /* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */
if (col == 0) { if (col == 0) {
@ -2276,7 +2276,7 @@ struct CargoesField {
if (left->type == CFT_INDUSTRY) return left->u.industry.other_produced[row]; if (left->type == CFT_INDUSTRY) return left->u.industry.other_produced[row];
if (left->type == CFT_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row]; if (left->type == CFT_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row];
} }
return CT_INVALID; return INVALID_CARGO;
} }
if (col == this->u.cargo.num_cargoes) { if (col == this->u.cargo.num_cargoes) {
if (IsValidCargoID(this->u.cargo.cust_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]]; if (IsValidCargoID(this->u.cargo.cust_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
@ -2284,25 +2284,24 @@ struct CargoesField {
if (right->type == CFT_INDUSTRY) return right->u.industry.other_accepted[row]; if (right->type == CFT_INDUSTRY) return right->u.industry.other_accepted[row];
if (right->type == CFT_CARGO_LABEL && right->u.cargo_label.left_align) return right->u.cargo_label.cargoes[row]; if (right->type == CFT_CARGO_LABEL && right->u.cargo_label.left_align) return right->u.cargo_label.cargoes[row];
} }
return CT_INVALID; return INVALID_CARGO;
} }
if (row >= col) { if (row >= col) {
/* Clicked somewhere in-between vertical cargo connection. /* Clicked somewhere in-between vertical cargo connection.
* Since the horizontal connection is made in the same order as the vertical list, the above condition * Since the horizontal connection is made in the same order as the vertical list, the above condition
* ensures we are left-below the main diagonal, thus at the supplying side. * ensures we are left-below the main diagonal, thus at the supplying side.
*/ */
if (IsValidCargoID(this->u.cargo.supp_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]]; return (IsValidCargoID(this->u.cargo.supp_cargoes[row])) ? this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]] : INVALID_CARGO;
return CT_INVALID; } else {
/* Clicked at a customer connection. */
return (IsValidCargoID(this->u.cargo.cust_cargoes[row])) ? this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]] : INVALID_CARGO;
} }
/* Clicked at a customer connection. */
if (IsValidCargoID(this->u.cargo.cust_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
return CT_INVALID;
} }
/** /**
* Decide what cargo the user clicked in the cargo label field. * Decide what cargo the user clicked in the cargo label field.
* @param pt Click position in the cargo label field. * @param pt Click position in the cargo label field.
* @return Cargo clicked at, or #CT_INVALID if none. * @return Cargo clicked at, or #INVALID_CARGO if none.
*/ */
CargoID CargoLabelClickedAt(Point pt) const CargoID CargoLabelClickedAt(Point pt) const
{ {
@ -2311,11 +2310,11 @@ struct CargoesField {
int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.height; int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.height;
uint row; uint row;
for (row = 0; row < MAX_CARGOES; row++) { for (row = 0; row < MAX_CARGOES; row++) {
if (pt.y < vpos) return CT_INVALID; if (pt.y < vpos) return INVALID_CARGO;
if (pt.y < vpos + FONT_HEIGHT_NORMAL) break; if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
vpos += FONT_HEIGHT_NORMAL + CargoesField::cargo_space.height; vpos += FONT_HEIGHT_NORMAL + CargoesField::cargo_space.height;
} }
if (row == MAX_CARGOES) return CT_INVALID; if (row == MAX_CARGOES) return INVALID_CARGO;
return this->u.cargo_label.cargoes[row]; return this->u.cargo_label.cargoes[row];
} }
@ -2370,7 +2369,7 @@ struct CargoesRow {
CargoesField *cargo_fld = this->columns + column + 1; CargoesField *cargo_fld = this->columns + column + 1;
assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO); assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
MemSetT(ind_fld->u.industry.other_produced, CT_INVALID, MAX_CARGOES); MemSetT(ind_fld->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) { if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column. CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column.
@ -2404,7 +2403,7 @@ struct CargoesRow {
void MakeCargoLabel(int column, bool accepting) void MakeCargoLabel(int column, bool accepting)
{ {
CargoID cargoes[MAX_CARGOES]; CargoID cargoes[MAX_CARGOES];
MemSetT(cargoes, CT_INVALID, lengthof(cargoes)); MemSetT(cargoes, INVALID_CARGO, lengthof(cargoes));
CargoesField *label_fld = this->columns + column; CargoesField *label_fld = this->columns + column;
CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1); CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
@ -2428,7 +2427,7 @@ struct CargoesRow {
CargoesField *cargo_fld = this->columns + column - 1; CargoesField *cargo_fld = this->columns + column - 1;
assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO); assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
MemSetT(ind_fld->u.industry.other_accepted, CT_INVALID, MAX_CARGOES); MemSetT(ind_fld->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) { if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column. CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column.
@ -2923,7 +2922,10 @@ struct IndustryCargoesWindow : public Window {
{ {
if (!gui_scope) return; if (!gui_scope) return;
if (data == NUM_INDUSTRYTYPES) { if (data == NUM_INDUSTRYTYPES) {
this->RaiseWidgetWhenLowered(WID_IC_NOTIFY); if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
this->RaiseWidget(WID_IC_NOTIFY);
this->SetWidgetDirty(WID_IC_NOTIFY);
}
return; return;
} }
@ -3111,7 +3113,7 @@ struct IndustryCargoesWindow : public Window {
if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false; if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x; const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
CargoID cid = CT_INVALID; CargoID cid = INVALID_CARGO;
switch (fld->type) { switch (fld->type) {
case CFT_CARGO: { case CFT_CARGO: {
CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr; CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;

View File

@ -189,7 +189,7 @@ public:
} }
/** Bare constructor, only for save/load. */ /** Bare constructor, only for save/load. */
LinkGraph() : cargo(CT_INVALID), last_compression(0) {} LinkGraph() : cargo(INVALID_CARGO), last_compression(0) {}
/** /**
* Real constructor. * Real constructor.
* @param cargo Cargo the link graph is about. * @param cargo Cargo the link graph is about.

View File

@ -1180,7 +1180,13 @@ struct NetworkStartServerWindow : public Window {
void OnTimeout() override void OnTimeout() override
{ {
this->RaiseWidgetsWhenLowered(WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU); static const int raise_widgets[] = {WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU, WIDGET_LIST_END};
for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
if (this->IsWidgetLowered(*widget)) {
this->RaiseWidget(*widget);
this->SetWidgetDirty(*widget);
}
}
} }
void OnQueryTextFinished(char *str) override void OnQueryTextFinished(char *str) override

View File

@ -414,7 +414,7 @@ struct BuildRailToolbarWindow : Window {
this->InitNested(TRANSPORT_RAIL); this->InitNested(TRANSPORT_RAIL);
this->SetupRailToolbar(railtype); this->SetupRailToolbar(railtype);
this->DisableWidget(WID_RAT_REMOVE); this->DisableWidget(WID_RAT_REMOVE);
this->last_user_action = INVALID_WID_RAT; this->last_user_action = WIDGET_LIST_END;
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this); if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
} }

View File

@ -324,7 +324,7 @@ struct BuildRoadToolbarWindow : Window {
} }
this->OnInvalidateData(); this->OnInvalidateData();
this->last_started_action = INVALID_WID_ROT; this->last_started_action = WIDGET_LIST_END;
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this); if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
} }

View File

@ -27,7 +27,7 @@
* And the following sprite: * And the following sprite:
* - SPR_CARGO_<str_plural> * - SPR_CARGO_<str_plural>
* *
* @param bt Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec. * @param bt Cargo bit number, is #INVALID_CARGO for a non-used spec.
* @param label Unique label of the cargo type. * @param label Unique label of the cargo type.
* @param colour CargoSpec->legend_colour and CargoSpec->rating_colour. * @param colour CargoSpec->legend_colour and CargoSpec->rating_colour.
* @param weight Weight of a single unit of this cargo type in 1/16 ton (62.5 kg). * @param weight Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
@ -44,9 +44,9 @@
* @param classes Classes of this cargo type. @see CargoClass * @param classes Classes of this cargo type. @see CargoClass
*/ */
#define MK(bt, label, colour, weight, mult, ip, td1, td2, freight, te, str_plural, str_singular, str_volume, classes) \ #define MK(bt, label, colour, weight, mult, ip, td1, td2, freight, te, str_plural, str_singular, str_volume, classes) \
{label, bt, colour, colour, weight, mult, classes, ip, {td1, td2}, freight, te, 0, \ {bt, label, colour, colour, weight, mult, ip, {td1, td2}, freight, te, 0, \
MK_STR_CARGO_PLURAL(str_plural), MK_STR_CARGO_SINGULAR(str_singular), str_volume, MK_STR_QUANTITY(str_plural), MK_STR_ABBREV(str_plural), \ MK_STR_CARGO_PLURAL(str_plural), MK_STR_CARGO_SINGULAR(str_singular), str_volume, MK_STR_QUANTITY(str_plural), MK_STR_ABBREV(str_plural), \
MK_SPRITE(str_plural), nullptr, nullptr, 0} MK_SPRITE(str_plural), classes, nullptr, nullptr, 0}
/** Cargo types available by default. */ /** Cargo types available by default. */
static const CargoSpec _default_cargo[] = { static const CargoSpec _default_cargo[] = {

View File

@ -161,7 +161,7 @@ struct TerraformToolbarWindow : Window {
/* This is needed as we like to have the tree available on OnInit. */ /* This is needed as we like to have the tree available on OnInit. */
this->CreateNestedTree(); this->CreateNestedTree();
this->FinishInitNested(window_number); this->FinishInitNested(window_number);
this->last_user_action = INVALID_WID_TT; this->last_user_action = WIDGET_LIST_END;
} }
~TerraformToolbarWindow() ~TerraformToolbarWindow()
@ -542,7 +542,7 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
NWidgetStacked *show_desert = this->GetWidget<NWidgetStacked>(WID_ETT_SHOW_PLACE_DESERT); NWidgetStacked *show_desert = this->GetWidget<NWidgetStacked>(WID_ETT_SHOW_PLACE_DESERT);
show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE); show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE);
this->FinishInitNested(window_number); this->FinishInitNested(window_number);
this->last_user_action = INVALID_WID_ETT; this->last_user_action = WIDGET_LIST_END;
} }
void OnPaint() override void OnPaint() override
@ -649,7 +649,10 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
{ {
for (uint i = WID_ETT_START; i < this->nested_array_size; i++) { for (uint i = WID_ETT_START; i < this->nested_array_size; i++) {
if (i == WID_ETT_BUTTONS_START) i = WID_ETT_BUTTONS_END; // skip the buttons if (i == WID_ETT_BUTTONS_START) i = WID_ETT_BUTTONS_END; // skip the buttons
this->RaiseWidgetWhenLowered(i); if (this->IsWidgetLowered(i)) {
this->RaiseWidget(i);
this->SetWidgetDirty(i);
}
} }
} }

View File

@ -2128,7 +2128,10 @@ struct MainToolbarWindow : Window {
/* We do not want to automatically raise the pause, fast forward and /* We do not want to automatically raise the pause, fast forward and
* switchbar buttons; they have to stay down when pressed etc. */ * switchbar buttons; they have to stay down when pressed etc. */
for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) { for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) {
this->RaiseWidgetWhenLowered(i); if (this->IsWidgetLowered(i)) {
this->RaiseWidget(i);
this->SetWidgetDirty(i);
}
} }
} }

View File

@ -1421,18 +1421,16 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, bool sell_chain, b
/* First normalise the sub types of the chain. */ /* First normalise the sub types of the chain. */
NormaliseSubtypes(new_head); NormaliseSubtypes(new_head);
if (v == first && !sell_chain && new_head != nullptr && new_head->IsFrontEngine()) { if (v == first && v->IsEngine() && !sell_chain && new_head != nullptr && new_head->IsFrontEngine()) {
if (v->IsEngine()) { /* We are selling the front engine. In this case we want to
/* We are selling the front engine. In this case we want to * 'give' the order, unit number and such to the new head. */
* 'give' the order, unit number and such to the new head. */ new_head->orders = first->orders;
new_head->orders = first->orders; new_head->AddToShared(first);
new_head->AddToShared(first); DeleteVehicleOrders(first);
DeleteVehicleOrders(first);
/* Copy other important data from the front engine */ /* Copy other important data from the front engine */
new_head->CopyVehicleConfigAndStatistics(first); new_head->CopyVehicleConfigAndStatistics(first);
} GroupStatistics::CountVehicle(new_head, 1); // after copying over the profit
GroupStatistics::CountVehicle(new_head, 1); // after copying over the profit, if required
} else if (v->IsPrimaryVehicle() && backup_order) { } else if (v->IsPrimaryVehicle() && backup_order) {
OrderBackup::Backup(v, user); OrderBackup::Backup(v, user);
} }

View File

@ -274,7 +274,7 @@ static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &su
if (!v->GetEngine()->CanCarryCargo()) continue; if (!v->GetEngine()->CanCarryCargo()) continue;
CargoSummaryItem new_item; CargoSummaryItem new_item;
new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : (CargoID)CT_INVALID; new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : INVALID_CARGO;
new_item.subtype = GetCargoSubtypeText(v); new_item.subtype = GetCargoSubtypeText(v);
if (!IsValidCargoID(new_item.cargo) && new_item.subtype == STR_EMPTY) continue; if (!IsValidCargoID(new_item.cargo) && new_item.subtype == STR_EMPTY) continue;

View File

@ -2616,7 +2616,8 @@ struct VehicleDetailsWindow : Window {
/* Disable service-scroller when interval is set to disabled */ /* Disable service-scroller when interval is set to disabled */
this->SetWidgetsDisabledState(!IsVehicleServiceIntervalEnabled(v->type, v->owner), this->SetWidgetsDisabledState(!IsVehicleServiceIntervalEnabled(v->type, v->owner),
WID_VD_INCREASE_SERVICING_INTERVAL, WID_VD_INCREASE_SERVICING_INTERVAL,
WID_VD_DECREASE_SERVICING_INTERVAL); WID_VD_DECREASE_SERVICING_INTERVAL,
WIDGET_LIST_END);
StringID str = v->ServiceIntervalIsCustom() ? StringID str = v->ServiceIntervalIsCustom() ?
(v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT : STR_VEHICLE_DETAILS_DAYS) : (v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT : STR_VEHICLE_DETAILS_DAYS) :
@ -2656,7 +2657,9 @@ struct VehicleDetailsWindow : Window {
WID_VD_DETAILS_CARGO_CARRIED, WID_VD_DETAILS_CARGO_CARRIED,
WID_VD_DETAILS_TRAIN_VEHICLES, WID_VD_DETAILS_TRAIN_VEHICLES,
WID_VD_DETAILS_CAPACITY_OF_EACH, WID_VD_DETAILS_CAPACITY_OF_EACH,
WID_VD_DETAILS_TOTAL_CARGO); WID_VD_DETAILS_TOTAL_CARGO,
widget,
WIDGET_LIST_END);
this->tab = (TrainDetailsWindowTabs)(widget - WID_VD_DETAILS_CARGO_CARRIED); this->tab = (TrainDetailsWindowTabs)(widget - WID_VD_DETAILS_CARGO_CARRIED);
this->SetDirty(); this->SetDirty();

View File

@ -17,6 +17,8 @@
#include "gfx_type.h" #include "gfx_type.h"
#include "window_type.h" #include "window_type.h"
static const int WIDGET_LIST_END = -1; ///< indicate the end of widgets' list for vararg functions
/** Bits of the #WWT_MATRIX widget data. */ /** Bits of the #WWT_MATRIX widget data. */
enum MatrixWidgetValues { enum MatrixWidgetValues {
/* Number of column bits of the WWT_MATRIX widget data. */ /* Number of column bits of the WWT_MATRIX widget data. */

View File

@ -14,8 +14,6 @@
enum AirportToolbarWidgets { enum AirportToolbarWidgets {
WID_AT_AIRPORT, ///< Build airport button. WID_AT_AIRPORT, ///< Build airport button.
WID_AT_DEMOLISH, ///< Demolish button. WID_AT_DEMOLISH, ///< Demolish button.
INVALID_WID_AT = -1,
}; };
/** Widgets of the #BuildAirportWindow class. */ /** Widgets of the #BuildAirportWindow class. */

View File

@ -28,8 +28,6 @@ enum RailToolbarWidgets {
WID_RAT_BUILD_TUNNEL, ///< Build a tunnel. WID_RAT_BUILD_TUNNEL, ///< Build a tunnel.
WID_RAT_REMOVE, ///< Bulldozer to remove rail. WID_RAT_REMOVE, ///< Bulldozer to remove rail.
WID_RAT_CONVERT_RAIL, ///< Convert other rail to this type. WID_RAT_CONVERT_RAIL, ///< Convert other rail to this type.
INVALID_WID_RAT = -1,
}; };
/** Widgets of the #BuildRailStationWindow class. */ /** Widgets of the #BuildRailStationWindow class. */

View File

@ -26,8 +26,6 @@ enum RoadToolbarWidgets {
WID_ROT_BUILD_TUNNEL, ///< Build tunnel. WID_ROT_BUILD_TUNNEL, ///< Build tunnel.
WID_ROT_REMOVE, ///< Remove road. WID_ROT_REMOVE, ///< Remove road.
WID_ROT_CONVERT_ROAD, ///< Convert road. WID_ROT_CONVERT_ROAD, ///< Convert road.
INVALID_WID_ROT = -1,
}; };
/** Widgets of the #BuildRoadDepotWindow class. */ /** Widgets of the #BuildRoadDepotWindow class. */

View File

@ -22,8 +22,6 @@ enum TerraformToolbarWidgets {
WID_TT_PLANT_TREES, ///< Plant trees button (note: opens separate window, no place-push-button). WID_TT_PLANT_TREES, ///< Plant trees button (note: opens separate window, no place-push-button).
WID_TT_PLACE_SIGN, ///< Place sign button. WID_TT_PLACE_SIGN, ///< Place sign button.
WID_TT_PLACE_OBJECT, ///< Place object button. WID_TT_PLACE_OBJECT, ///< Place object button.
INVALID_WID_TT = -1,
}; };
/** Widgets of the #ScenarioEditorLandscapeGenerationWindow class. */ /** Widgets of the #ScenarioEditorLandscapeGenerationWindow class. */
@ -44,8 +42,6 @@ enum EditorTerraformToolbarWidgets {
WID_ETT_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size. WID_ETT_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size.
WID_ETT_NEW_SCENARIO, ///< Button for generating a new scenario. WID_ETT_NEW_SCENARIO, ///< Button for generating a new scenario.
WID_ETT_RESET_LANDSCAPE, ///< Button for removing all company-owned property. WID_ETT_RESET_LANDSCAPE, ///< Button for removing all company-owned property.
INVALID_WID_ETT = -1,
}; };
#endif /* WIDGETS_TERRAFORM_WIDGET_H */ #endif /* WIDGETS_TERRAFORM_WIDGET_H */

View File

@ -413,18 +413,6 @@ public:
SetWidgetLoweredState(widget_index, false); SetWidgetLoweredState(widget_index, false);
} }
/**
* Marks a widget as raised and dirty (redraw), when it is marked as lowered.
* @param widget_index index of this widget in the window
*/
inline void RaiseWidgetWhenLowered(byte widget_index)
{
if (this->IsWidgetLowered(widget_index)) {
this->RaiseWidget(widget_index);
this->SetWidgetDirty(widget_index);
}
}
/** /**
* Gets the lowered state of a widget. * Gets the lowered state of a widget.
* @param widget_index index of this widget in the window * @param widget_index index of this widget in the window
@ -470,16 +458,6 @@ public:
{ {
(SetWidgetLoweredState(widgets, lowered_stat), ...); (SetWidgetLoweredState(widgets, lowered_stat), ...);
} }
/**
* Raises the widgets and sets widgets dirty that are lowered.
* @param widgets list of widgets
*/
template<typename... Args>
void RaiseWidgetsWhenLowered(Args... widgets) {
(this->RaiseWidgetWhenLowered(widgets), ...);
}
void SetWidgetDirty(byte widget_index) const; void SetWidgetDirty(byte widget_index) const;
void DrawWidgets() const; void DrawWidgets() const;