Codechange: Use correct constant for invalid cargo type.

This commit is contained in:
Peter Nelson 2023-05-23 08:33:49 +01:00 committed by PeterN
parent 7ef22af2bb
commit 9d1b131c44
3 changed files with 31 additions and 30 deletions

View File

@ -1947,15 +1947,15 @@ struct CargoesField {
CargoID other_accepted[MAX_CARGOES]; ///< Cargoes accepted but not used in this figure.
} industry; ///< Industry data (for #CFT_INDUSTRY).
struct {
CargoID vertical_cargoes[MAX_CARGOES]; ///< Cargoes running from top to bottom (cargo ID or #INVALID_CARGO).
CargoID vertical_cargoes[MAX_CARGOES]; ///< Cargoes running from top to bottom (cargo ID or #CT_INVALID).
byte num_cargoes; ///< Number of cargoes.
CargoID supp_cargoes[MAX_CARGOES]; ///< Cargoes entering from the left (index in #vertical_cargoes, or #INVALID_CARGO).
CargoID supp_cargoes[MAX_CARGOES]; ///< Cargoes entering from the left (index in #vertical_cargoes, or #CT_INVALID).
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 #INVALID_CARGO).
CargoID cust_cargoes[MAX_CARGOES]; ///< Cargoes leaving to the right (index in #vertical_cargoes, or #CT_INVALID).
byte bottom_end; ///< Stop at the bottom of the vertical cargoes.
} cargo; ///< Cargo data (for #CFT_CARGO).
struct {
CargoID cargoes[MAX_CARGOES]; ///< Cargoes to display (or #INVALID_CARGO).
CargoID cargoes[MAX_CARGOES]; ///< Cargoes to display (or #CT_INVALID).
bool left_align; ///< Align all cargo texts to the left (else align to the right).
} cargo_label; ///< Label data (for #CFT_CARGO_LABEL).
StringID header; ///< Header text (for #CFT_HEADER).
@ -1979,8 +1979,8 @@ struct CargoesField {
{
this->type = CFT_INDUSTRY;
this->u.industry.ind_type = ind_type;
MemSetT(this->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
MemSetT(this->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
MemSetT(this->u.industry.other_accepted, CT_INVALID, MAX_CARGOES);
MemSetT(this->u.industry.other_produced, CT_INVALID, MAX_CARGOES);
}
/**
@ -2031,7 +2031,7 @@ struct CargoesField {
/**
* Make a piece of cargo column.
* @param cargoes Array of #CargoID (may contain #INVALID_CARGO).
* @param cargoes Array of #CargoID (may contain #CT_INVALID).
* @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 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;
for (; num < MAX_CARGOES; num++) this->u.cargo.vertical_cargoes[num] = INVALID_CARGO;
for (; num < MAX_CARGOES; num++) this->u.cargo.vertical_cargoes[num] = CT_INVALID;
this->u.cargo.top_end = top_end;
this->u.cargo.bottom_end = bottom_end;
MemSetT(this->u.cargo.supp_cargoes, INVALID_CARGO, MAX_CARGOES);
MemSetT(this->u.cargo.cust_cargoes, INVALID_CARGO, MAX_CARGOES);
MemSetT(this->u.cargo.supp_cargoes, CT_INVALID, MAX_CARGOES);
MemSetT(this->u.cargo.cust_cargoes, CT_INVALID, MAX_CARGOES);
}
/**
* Make a field displaying cargo type names.
* @param cargoes Array of #CargoID (may contain #INVALID_CARGO).
* @param cargoes Array of #CargoID (may contain #CT_INVALID).
* @param length Number of cargoes in \a cargoes.
* @param left_align ALign texts to the left (else to the right).
*/
@ -2068,7 +2068,7 @@ struct CargoesField {
this->type = CFT_CARGO_LABEL;
uint 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] = INVALID_CARGO;
for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = CT_INVALID;
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 right Right industry neighbour if available (else \c nullptr should be supplied).
* @param pt Click position in the cargo field.
* @return Cargo clicked at, or #INVALID_CARGO if none.
* @return Cargo clicked at, or #CT_INVALID if none.
*/
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;
uint row;
for (row = 0; row < MAX_CARGOES; row++) {
if (pt.y < vpos) return INVALID_CARGO;
if (pt.y < vpos) return CT_INVALID;
if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
vpos += FONT_HEIGHT_NORMAL + CargoesField::cargo_space.width;
}
if (row == MAX_CARGOES) return INVALID_CARGO;
if (row == MAX_CARGOES) return CT_INVALID;
/* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */
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_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row];
}
return INVALID_CARGO;
return CT_INVALID;
}
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]];
@ -2284,24 +2284,25 @@ struct CargoesField {
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];
}
return INVALID_CARGO;
return CT_INVALID;
}
if (row >= col) {
/* Clicked somewhere in-between vertical cargo connection.
* 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.
*/
return (IsValidCargoID(this->u.cargo.supp_cargoes[row])) ? this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]] : INVALID_CARGO;
} 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;
if (IsValidCargoID(this->u.cargo.supp_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
return CT_INVALID;
}
/* 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.
* @param pt Click position in the cargo label field.
* @return Cargo clicked at, or #INVALID_CARGO if none.
* @return Cargo clicked at, or #CT_INVALID if none.
*/
CargoID CargoLabelClickedAt(Point pt) const
{
@ -2310,11 +2311,11 @@ struct CargoesField {
int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.height;
uint row;
for (row = 0; row < MAX_CARGOES; row++) {
if (pt.y < vpos) return INVALID_CARGO;
if (pt.y < vpos) return CT_INVALID;
if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
vpos += FONT_HEIGHT_NORMAL + CargoesField::cargo_space.height;
}
if (row == MAX_CARGOES) return INVALID_CARGO;
if (row == MAX_CARGOES) return CT_INVALID;
return this->u.cargo_label.cargoes[row];
}
@ -2369,7 +2370,7 @@ struct CargoesRow {
CargoesField *cargo_fld = this->columns + column + 1;
assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
MemSetT(ind_fld->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
MemSetT(ind_fld->u.industry.other_produced, CT_INVALID, MAX_CARGOES);
if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column.
@ -2403,7 +2404,7 @@ struct CargoesRow {
void MakeCargoLabel(int column, bool accepting)
{
CargoID cargoes[MAX_CARGOES];
MemSetT(cargoes, INVALID_CARGO, lengthof(cargoes));
MemSetT(cargoes, CT_INVALID, lengthof(cargoes));
CargoesField *label_fld = this->columns + column;
CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
@ -2427,7 +2428,7 @@ struct CargoesRow {
CargoesField *cargo_fld = this->columns + column - 1;
assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
MemSetT(ind_fld->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
MemSetT(ind_fld->u.industry.other_accepted, CT_INVALID, MAX_CARGOES);
if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column.
@ -3110,7 +3111,7 @@ struct IndustryCargoesWindow : public Window {
if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
CargoID cid = INVALID_CARGO;
CargoID cid = CT_INVALID;
switch (fld->type) {
case CFT_CARGO: {
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. */
LinkGraph() : cargo(INVALID_CARGO), last_compression(0) {}
LinkGraph() : cargo(CT_INVALID), last_compression(0) {}
/**
* Real constructor.
* @param cargo Cargo the link graph is about.

View File

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