Remove various uses of lengthof on std::array
This commit is contained in:
@@ -2365,7 +2365,7 @@ struct CompanyWindow : Window
|
||||
/* Owners of company */
|
||||
{
|
||||
int plane = SZSP_HORIZONTAL;
|
||||
for (uint i = 0; i < lengthof(c->share_owners); i++) {
|
||||
for (size_t i = 0; i < std::size(c->share_owners); i++) {
|
||||
if (c->share_owners[i] != INVALID_COMPANY) {
|
||||
plane = 0;
|
||||
break;
|
||||
|
@@ -1403,11 +1403,11 @@ static void TriggerIndustryProduction(Industry *i)
|
||||
SetWindowDirty(WC_INDUSTRY_VIEW, i->index);
|
||||
}
|
||||
} else {
|
||||
for (uint ci_in = 0; ci_in < lengthof(i->incoming_cargo_waiting); ci_in++) {
|
||||
for (size_t ci_in = 0; ci_in < std::size(i->incoming_cargo_waiting); ci_in++) {
|
||||
uint cargo_waiting = i->incoming_cargo_waiting[ci_in];
|
||||
if (cargo_waiting == 0 || i->accepts_cargo[ci_in] == INVALID_CARGO) continue;
|
||||
|
||||
for (uint ci_out = 0; ci_out < lengthof(i->produced_cargo_waiting); ci_out++) {
|
||||
for (size_t ci_out = 0; ci_out < std::size(i->produced_cargo_waiting); ci_out++) {
|
||||
if (i->produced_cargo[ci_out] == INVALID_CARGO) continue;
|
||||
i->produced_cargo_waiting[ci_out] = ClampTo<uint16_t>(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256));
|
||||
}
|
||||
|
@@ -525,7 +525,7 @@ static bool TransportIndustryGoods(TileIndex tile)
|
||||
bool moved_cargo = false;
|
||||
|
||||
const uint step_limit = _industry_cargo_scaler.Scale(255);
|
||||
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo_waiting); j++) {
|
||||
uint cw = std::min<uint>(i->produced_cargo_waiting[j], step_limit);
|
||||
if (cw > indspec->minimal_cargo && i->produced_cargo[j] != INVALID_CARGO) {
|
||||
i->produced_cargo_waiting[j] -= cw;
|
||||
@@ -1023,7 +1023,7 @@ bool IsTileForestIndustry(TileIndex tile)
|
||||
if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
|
||||
|
||||
/* Check for wood production */
|
||||
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
|
||||
for (size_t i = 0; i < std::size(ind->produced_cargo); i++) {
|
||||
/* The industry produces wood. */
|
||||
if (ind->produced_cargo[i] != INVALID_CARGO && CargoSpec::Get(ind->produced_cargo[i])->label == CT_WOOD) return true;
|
||||
}
|
||||
@@ -1189,7 +1189,7 @@ static void ChopLumberMillTrees(Industry *i)
|
||||
|
||||
static void ProduceIndustryGoodsFromRate(Industry *i, bool scale)
|
||||
{
|
||||
for (size_t j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo_waiting); j++) {
|
||||
if (i->produced_cargo[j] == INVALID_CARGO) continue;
|
||||
uint amount = i->production_rate[j];
|
||||
if (amount != 0 && scale) {
|
||||
@@ -1209,7 +1209,7 @@ static void ProduceIndustryGoods(Industry *i)
|
||||
if ((i->counter & 0x3F) == 0) {
|
||||
uint32_t r;
|
||||
if (Chance16R(1, 14, r) && indsp->number_of_sounds != 0 && _settings_client.sound.ambient) {
|
||||
for (size_t j = 0; j < lengthof(i->last_month_production); j++) {
|
||||
for (size_t j = 0; j < std::size(i->last_month_production); j++) {
|
||||
if (i->last_month_production[j] > 0) {
|
||||
/* Play sound since last month had production */
|
||||
SndPlayTileFx(
|
||||
@@ -1845,7 +1845,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
|
||||
/* Randomize inital production if non-original economy is used and there are no production related callbacks. */
|
||||
if (!indspec->UsesOriginalEconomy()) {
|
||||
for (size_t ci = 0; ci < lengthof(i->production_rate); ci++) {
|
||||
for (size_t ci = 0; ci < std::size(i->production_rate); ci++) {
|
||||
i->production_rate[ci] = ClampTo<byte>((RandomRange(256) + 128) * i->production_rate[ci] >> 8);
|
||||
}
|
||||
}
|
||||
@@ -1893,13 +1893,13 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
if (_generating_world) {
|
||||
if (HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
|
||||
IndustryProductionCallback(i, 1);
|
||||
for (size_t ci = 0; ci < lengthof(i->last_month_production); ci++) {
|
||||
for (size_t ci = 0; ci < std::size(i->last_month_production); ci++) {
|
||||
i->last_month_production[ci] = i->produced_cargo_waiting[ci] * 8;
|
||||
i->produced_cargo_waiting[ci] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t ci = 0; ci < lengthof(i->last_month_production); ci++) {
|
||||
for (size_t ci = 0; ci < std::size(i->last_month_production); ci++) {
|
||||
i->last_month_production[ci] += i->production_rate[ci] * 8;
|
||||
}
|
||||
}
|
||||
@@ -1916,7 +1916,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
/* Clear all input cargo types */
|
||||
for (size_t j = 0; j < i->accepts_cargo.size(); j++) i->accepts_cargo[j] = INVALID_CARGO;
|
||||
/* Query actual types */
|
||||
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? lengthof(i->accepts_cargo) : 3;
|
||||
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? std::size(i->accepts_cargo) : 3;
|
||||
for (uint j = 0; j < maxcargoes; j++) {
|
||||
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
|
||||
if (res == CALLBACK_FAILED || GB(res, 0, 8) == UINT8_MAX) break;
|
||||
@@ -1948,7 +1948,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
/* Clear all output cargo types */
|
||||
for (size_t j = 0; j < i->produced_cargo.size(); j++) i->produced_cargo[j] = INVALID_CARGO;
|
||||
/* Query actual types */
|
||||
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? lengthof(i->produced_cargo) : 2;
|
||||
uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? std::size(i->produced_cargo) : 2;
|
||||
for (uint j = 0; j < maxcargoes; j++) {
|
||||
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
|
||||
if (res == CALLBACK_FAILED || GB(res, 0, 8) == UINT8_MAX) break;
|
||||
@@ -2573,7 +2573,7 @@ void GenerateIndustries()
|
||||
*/
|
||||
static void UpdateIndustryStatistics(Industry *i)
|
||||
{
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] != INVALID_CARGO) {
|
||||
byte pct = 0;
|
||||
if (i->this_month_production[j] != 0) {
|
||||
@@ -2601,7 +2601,7 @@ void Industry::RecomputeProductionMultipliers()
|
||||
assert(indspec->UsesOriginalEconomy());
|
||||
|
||||
/* Rates are rounded up, so e.g. oilrig always produces some passengers */
|
||||
for (size_t i = 0; i < lengthof(this->production_rate); i++) {
|
||||
for (size_t i = 0; i < std::size(this->production_rate); i++) {
|
||||
this->production_rate[i] = ClampTo<byte>(CeilDiv(indspec->production_rate[i] * this->prod_level, PRODLEVEL_DEFAULT));
|
||||
}
|
||||
}
|
||||
@@ -2940,7 +2940,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
|
||||
}
|
||||
} else if (_settings_game.economy.type == ET_SMOOTH) {
|
||||
closeit = !(i->ctlflags & (INDCTL_NO_CLOSURE | INDCTL_NO_PRODUCTION_DECREASE));
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] == INVALID_CARGO) continue;
|
||||
uint32_t r = Random();
|
||||
int old_prod, new_prod, percent;
|
||||
|
@@ -172,11 +172,11 @@ 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)
|
||||
{
|
||||
static_assert(lengthof(cargoes) <= lengthof(suffixes));
|
||||
static_assert(std::tuple_size_v<std::remove_reference_t<decltype(cargoes)>> <= std::tuple_size_v<std::remove_reference_t<decltype(suffixes)>>);
|
||||
|
||||
if (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) {
|
||||
/* Reworked behaviour with new many-in-many-out scheme */
|
||||
for (uint j = 0; j < lengthof(suffixes); j++) {
|
||||
for (size_t j = 0; j < std::size(suffixes); j++) {
|
||||
if (cargoes[j] != INVALID_CARGO) {
|
||||
byte local_id = indspec->grf_prop.grffile->cargo_map[cargoes[j]]; // should we check the value for valid?
|
||||
uint cargotype = local_id << 16 | use_input;
|
||||
@@ -188,7 +188,7 @@ static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixTy
|
||||
}
|
||||
} else {
|
||||
/* Compatible behaviour with old 3-in-2-out scheme */
|
||||
for (uint j = 0; j < lengthof(suffixes); j++) {
|
||||
for (size_t j = 0; j < std::size(suffixes); j++) {
|
||||
suffixes[j].text[0] = '\0';
|
||||
suffixes[j].display = CSD_CARGO;
|
||||
}
|
||||
@@ -444,11 +444,11 @@ public:
|
||||
Dimension d = {0, 0};
|
||||
for (const auto &indtype : this->list) {
|
||||
const IndustrySpec *indsp = GetIndustrySpec(indtype);
|
||||
CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
|
||||
std::array<CargoSuffix, std::tuple_size_v<decltype(indsp->accepts_cargo)>> cargo_suffix{};
|
||||
|
||||
/* Measure the accepted cargoes, if any. */
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix);
|
||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix, indsp->accepts_cargo.size(), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix.data(), indsp->accepts_cargo.size(), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
||||
Dimension strdim = GetStringBoundingBox(cargostring);
|
||||
if (strdim.width > max_minwidth) {
|
||||
extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
|
||||
@@ -458,7 +458,7 @@ public:
|
||||
|
||||
/* Measure the produced cargoes, if any. */
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix);
|
||||
cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix, indsp->produced_cargo.size(), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||
cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix.data(), indsp->produced_cargo.size(), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||
strdim = GetStringBoundingBox(cargostring);
|
||||
if (strdim.width > max_minwidth) {
|
||||
extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
|
||||
@@ -560,16 +560,16 @@ public:
|
||||
ir.top += GetCharacterHeight(FS_NORMAL);
|
||||
}
|
||||
|
||||
CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
|
||||
std::array<CargoSuffix, std::tuple_size_v<decltype(indsp->accepts_cargo)>> cargo_suffix{};
|
||||
|
||||
/* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
|
||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix, indsp->accepts_cargo.size(), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix.data(), indsp->accepts_cargo.size(), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
||||
ir.top = DrawStringMultiLine(ir, cargostring);
|
||||
|
||||
/* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
|
||||
cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix, indsp->produced_cargo.size(), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||
cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix.data(), indsp->produced_cargo.size(), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||
ir.top = DrawStringMultiLine(ir, cargostring);
|
||||
|
||||
/* Get the additional purchase info text, if it has not already been queried. */
|
||||
@@ -804,7 +804,7 @@ static inline bool IsProductionAlterable(const Industry *i)
|
||||
{
|
||||
const IndustrySpec *is = GetIndustrySpec(i->type);
|
||||
bool has_prod = false;
|
||||
for (size_t j = 0; j < lengthof(is->production_rate); j++) {
|
||||
for (size_t j = 0; j < std::size(is->production_rate); j++) {
|
||||
if (is->production_rate[j] != 0) {
|
||||
has_prod = true;
|
||||
break;
|
||||
@@ -907,13 +907,13 @@ public:
|
||||
ir.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
|
||||
}
|
||||
|
||||
CargoSuffix cargo_suffix[lengthof(i->accepts_cargo)];
|
||||
std::array<CargoSuffix, std::tuple_size_v<decltype(i->accepts_cargo)>> cargo_suffix{};
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
|
||||
|
||||
const int label_indent = WidgetDimensions::scaled.hsep_normal + this->cargo_icon_size.width;
|
||||
bool stockpiling = HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS);
|
||||
|
||||
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(i->accepts_cargo); j++) {
|
||||
if (i->accepts_cargo[j] == INVALID_CARGO) continue;
|
||||
has_accept = true;
|
||||
if (first) {
|
||||
@@ -956,7 +956,7 @@ public:
|
||||
int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
|
||||
int button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
|
||||
first = true;
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] == INVALID_CARGO) continue;
|
||||
if (first) {
|
||||
if (has_accept) ir.top += WidgetDimensions::scaled.vsep_wide;
|
||||
@@ -1054,7 +1054,7 @@ public:
|
||||
case EA_RATE:
|
||||
if (pt.y >= this->production_offset_y) {
|
||||
int row = (pt.y - this->production_offset_y) / this->cheat_line_height;
|
||||
for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] == INVALID_CARGO) continue;
|
||||
row--;
|
||||
if (row < 0) {
|
||||
@@ -1213,7 +1213,7 @@ static void UpdateIndustryProduction(Industry *i)
|
||||
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
||||
if (indspec->UsesOriginalEconomy()) i->RecomputeProductionMultipliers();
|
||||
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] != INVALID_CARGO) {
|
||||
i->last_month_production[j] = _industry_cargo_scaler.Scale(8 * i->production_rate[j]);
|
||||
}
|
||||
@@ -1488,7 +1488,7 @@ protected:
|
||||
*/
|
||||
static inline int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
|
||||
{
|
||||
assert(id < lengthof(i->produced_cargo));
|
||||
assert((size_t)id < std::size(i->produced_cargo));
|
||||
|
||||
if (i->produced_cargo[id] == INVALID_CARGO) return -1;
|
||||
return ToPercent8(i->last_month_pct_transported[id]);
|
||||
@@ -1507,14 +1507,14 @@ protected:
|
||||
if (filter == CargoFilterCriteria::CF_NONE) return 0;
|
||||
|
||||
int percentage = 0, produced_cargo_count = 0;
|
||||
for (uint id = 0; id < lengthof(i->produced_cargo); id++) {
|
||||
for (size_t id = 0; id < std::size(i->produced_cargo); id++) {
|
||||
if (filter == CargoFilterCriteria::CF_ANY) {
|
||||
int transported = GetCargoTransportedPercentsIfValid(i, id);
|
||||
if (transported != -1) {
|
||||
produced_cargo_count++;
|
||||
percentage += transported;
|
||||
}
|
||||
if (produced_cargo_count == 0 && id == lengthof(i->produced_cargo) - 1 && percentage == 0) {
|
||||
if (produced_cargo_count == 0 && id == std::size(i->produced_cargo) - 1 && percentage == 0) {
|
||||
return transported;
|
||||
}
|
||||
} else if (filter == i->produced_cargo[id]) {
|
||||
@@ -1551,7 +1551,7 @@ protected:
|
||||
if (filter == CargoFilterCriteria::CF_NONE) return IndustryTypeSorter(a, b, filter);
|
||||
|
||||
uint prod_a = 0, prod_b = 0;
|
||||
for (uint i = 0; i < lengthof(a->produced_cargo); i++) {
|
||||
for (size_t i = 0; i < std::size(a->produced_cargo); i++) {
|
||||
if (filter == CargoFilterCriteria::CF_ANY) {
|
||||
if (a->produced_cargo[i] != INVALID_CARGO) prod_a += a->last_month_production[i];
|
||||
if (b->produced_cargo[i] != INVALID_CARGO) prod_b += b->last_month_production[i];
|
||||
@@ -1585,7 +1585,7 @@ protected:
|
||||
/* Industry name */
|
||||
SetDParam(p++, i->index);
|
||||
|
||||
static CargoSuffix cargo_suffix[lengthof(i->produced_cargo)];
|
||||
std::array<CargoSuffix, std::tuple_size_v<decltype(i->produced_cargo)>> cargo_suffix{};
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_DIR, i, i->type, indsp, i->produced_cargo, cargo_suffix);
|
||||
|
||||
/* Get industry productions (CargoID, production, suffix, transported) */
|
||||
@@ -1597,7 +1597,7 @@ protected:
|
||||
};
|
||||
std::vector<CargoInfo> cargos;
|
||||
|
||||
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(i->produced_cargo); j++) {
|
||||
if (i->produced_cargo[j] == INVALID_CARGO) continue;
|
||||
cargos.push_back({ i->produced_cargo[j], i->last_month_production[j], cargo_suffix[j].text.c_str(), ToPercent8(i->last_month_pct_transported[j]) });
|
||||
}
|
||||
@@ -2471,7 +2471,7 @@ struct CargoesRow {
|
||||
int other_count = 0;
|
||||
|
||||
const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
|
||||
assert(CargoesField::max_cargoes <= lengthof(indsp->produced_cargo));
|
||||
assert(CargoesField::max_cargoes <= std::size(indsp->produced_cargo));
|
||||
for (uint i = 0; i < CargoesField::max_cargoes; i++) {
|
||||
int col = cargo_fld->ConnectCargo(indsp->produced_cargo[i], true);
|
||||
if (col < 0) others[other_count++] = indsp->produced_cargo[i];
|
||||
@@ -2530,7 +2530,7 @@ struct CargoesRow {
|
||||
int other_count = 0;
|
||||
|
||||
const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
|
||||
assert(CargoesField::max_cargoes <= lengthof(indsp->accepts_cargo));
|
||||
assert(CargoesField::max_cargoes <= std::size(indsp->accepts_cargo));
|
||||
for (uint i = 0; i < CargoesField::max_cargoes; i++) {
|
||||
int col = cargo_fld->ConnectCargo(indsp->accepts_cargo[i], false);
|
||||
if (col < 0) others[other_count++] = indsp->accepts_cargo[i];
|
||||
@@ -2547,7 +2547,7 @@ struct CargoesRow {
|
||||
HouseSpec *hs = HouseSpec::Get(h);
|
||||
if (!hs->enabled) continue;
|
||||
|
||||
for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(hs->accepts_cargo); j++) {
|
||||
if (hs->cargo_acceptance[j] > 0 && cargo_fld->u.cargo.vertical_cargoes[i] == hs->accepts_cargo[j]) {
|
||||
cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], false);
|
||||
goto next_cargo;
|
||||
@@ -2769,7 +2769,7 @@ struct IndustryCargoesWindow : public Window {
|
||||
HouseSpec *hs = HouseSpec::Get(h);
|
||||
if (!hs->enabled || !(hs->building_availability & climate_mask)) continue;
|
||||
|
||||
for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
|
||||
for (size_t j = 0; j < std::size(hs->accepts_cargo); j++) {
|
||||
if (hs->cargo_acceptance[j] > 0 && cargoes[i] == hs->accepts_cargo[j]) return true;
|
||||
}
|
||||
}
|
||||
@@ -3341,9 +3341,9 @@ void ShowIndustryTooltip(Window *w, const TileIndex tile)
|
||||
}
|
||||
|
||||
if (_settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled) {
|
||||
const size_t accepted_cargo_count = lengthof(industry->accepts_cargo);
|
||||
const size_t accepted_cargo_count = std::size(industry->accepts_cargo);
|
||||
|
||||
CargoSuffix suffixes[accepted_cargo_count];
|
||||
std::array<CargoSuffix, std::tuple_size_v<decltype(industry->accepts_cargo)>> suffixes{};
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, industry, industry->type, industry_spec, industry->accepts_cargo, suffixes);
|
||||
|
||||
// Have to query the stockpiling right now, in case callback 37 returns fail.
|
||||
@@ -3411,9 +3411,9 @@ void ShowIndustryTooltip(Window *w, const TileIndex tile)
|
||||
}
|
||||
|
||||
if (_settings_client.gui.industry_tooltip_show_produced) {
|
||||
const size_t produced_cargo_count = lengthof(industry->produced_cargo);
|
||||
const size_t produced_cargo_count = std::size(industry->produced_cargo);
|
||||
|
||||
CargoSuffix suffixes[produced_cargo_count];
|
||||
std::array<CargoSuffix, std::tuple_size_v<decltype(industry->produced_cargo)>> suffixes{};
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, industry, industry->type, industry_spec, industry->produced_cargo, suffixes);
|
||||
|
||||
// Print out amounts of produced cargo.
|
||||
|
@@ -3818,12 +3818,12 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
|
||||
|
||||
case 0x25: { // variable length produced cargoes
|
||||
byte num_cargoes = buf->ReadByte();
|
||||
if (num_cargoes > lengthof(indsp->produced_cargo)) {
|
||||
if (num_cargoes > std::size(indsp->produced_cargo)) {
|
||||
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_LIST_PROPERTY_TOO_LONG);
|
||||
error->param_value[1] = prop;
|
||||
return CIR_DISABLED;
|
||||
}
|
||||
for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) {
|
||||
for (uint i = 0; i < std::size(indsp->produced_cargo); i++) {
|
||||
if (i < num_cargoes) {
|
||||
CargoID cargo = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
|
||||
indsp->produced_cargo[i] = cargo;
|
||||
@@ -3837,12 +3837,12 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
|
||||
|
||||
case 0x26: { // variable length accepted cargoes
|
||||
byte num_cargoes = buf->ReadByte();
|
||||
if (num_cargoes > lengthof(indsp->accepts_cargo)) {
|
||||
if (num_cargoes > std::size(indsp->accepts_cargo)) {
|
||||
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_LIST_PROPERTY_TOO_LONG);
|
||||
error->param_value[1] = prop;
|
||||
return CIR_DISABLED;
|
||||
}
|
||||
for (uint i = 0; i < lengthof(indsp->accepts_cargo); i++) {
|
||||
for (uint i = 0; i < std::size(indsp->accepts_cargo); i++) {
|
||||
if (i < num_cargoes) {
|
||||
CargoID cargo = GetCargoTranslation(buf->ReadByte(), _cur.grffile);
|
||||
indsp->accepts_cargo[i] = cargo;
|
||||
@@ -3856,12 +3856,12 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
|
||||
|
||||
case 0x27: { // variable length production rates
|
||||
byte num_cargoes = buf->ReadByte();
|
||||
if (num_cargoes > lengthof(indsp->production_rate)) {
|
||||
if (num_cargoes > std::size(indsp->production_rate)) {
|
||||
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_LIST_PROPERTY_TOO_LONG);
|
||||
error->param_value[1] = prop;
|
||||
return CIR_DISABLED;
|
||||
}
|
||||
for (uint i = 0; i < lengthof(indsp->production_rate); i++) {
|
||||
for (uint i = 0; i < std::size(indsp->production_rate); i++) {
|
||||
if (i < num_cargoes) {
|
||||
indsp->production_rate[i] = buf->ReadByte();
|
||||
} else {
|
||||
@@ -3874,13 +3874,13 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
|
||||
case 0x28: { // variable size input/output production multiplier table
|
||||
byte num_inputs = buf->ReadByte();
|
||||
byte num_outputs = buf->ReadByte();
|
||||
if (num_inputs > lengthof(indsp->accepts_cargo) || num_outputs > lengthof(indsp->produced_cargo)) {
|
||||
if (num_inputs > std::size(indsp->accepts_cargo) || num_outputs > std::size(indsp->produced_cargo)) {
|
||||
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_LIST_PROPERTY_TOO_LONG);
|
||||
error->param_value[1] = prop;
|
||||
return CIR_DISABLED;
|
||||
}
|
||||
for (uint i = 0; i < lengthof(indsp->accepts_cargo); i++) {
|
||||
for (uint j = 0; j < lengthof(indsp->produced_cargo); j++) {
|
||||
for (uint i = 0; i < std::size(indsp->accepts_cargo); i++) {
|
||||
for (uint j = 0; j < std::size(indsp->produced_cargo); j++) {
|
||||
uint16_t mult = 0;
|
||||
if (i < num_inputs && j < num_outputs) mult = buf->ReadWord();
|
||||
indsp->input_cargo_multiplier[i][j] = mult;
|
||||
@@ -11151,10 +11151,10 @@ static void FinaliseIndustriesArray()
|
||||
}
|
||||
|
||||
/* Apply default cargo translation map for unset cargo slots */
|
||||
for (uint i = 0; i < lengthof(indsp.produced_cargo); ++i) {
|
||||
for (uint i = 0; i < std::size(indsp.produced_cargo); ++i) {
|
||||
if (!IsValidCargoID(indsp.produced_cargo[i])) indsp.produced_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indsp.produced_cargo_label[i]));
|
||||
}
|
||||
for (uint i = 0; i < lengthof(indsp.accepts_cargo); ++i) {
|
||||
for (uint i = 0; i < std::size(indsp.accepts_cargo); ++i) {
|
||||
if (!IsValidCargoID(indsp.accepts_cargo[i])) indsp.accepts_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indsp.accepts_cargo_label[i]));
|
||||
}
|
||||
}
|
||||
|
@@ -653,20 +653,20 @@ struct NewGRFInspectWindow : Window {
|
||||
|
||||
TextColour colour = (this->selected_sprite_group == group && group != nullptr) ? TC_LIGHT_BLUE : TC_BLACK;
|
||||
if (highlight_tag != 0) {
|
||||
for (uint i = 0; i < lengthof(this->selected_highlight_tags); i++) {
|
||||
for (uint i = 0; i < std::size(this->selected_highlight_tags); i++) {
|
||||
if (this->selected_highlight_tags[i] == highlight_tag) {
|
||||
static const TextColour text_colours[] = { TC_YELLOW, TC_GREEN, TC_ORANGE, TC_CREAM, TC_BROWN, TC_RED };
|
||||
static_assert(lengthof(this->selected_highlight_tags) == lengthof(text_colours));
|
||||
static_assert(std::tuple_size_v<decltype(this->selected_highlight_tags)> == lengthof(text_colours));
|
||||
colour = text_colours[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (group != nullptr) {
|
||||
for (uint i = 0; i < lengthof(this->marked_groups); i++) {
|
||||
for (uint i = 0; i < std::size(this->marked_groups); i++) {
|
||||
if (this->marked_groups[i] == group) {
|
||||
static const uint8_t mark_colours[] = { PC_YELLOW, PC_GREEN, PC_ORANGE, PC_DARK_BLUE, PC_RED, PC_LIGHT_BLUE, 0xAE /* purple */, 0x6C /* brown */ };
|
||||
static_assert(lengthof(this->marked_groups) == lengthof(mark_colours));
|
||||
static_assert(std::tuple_size_v<decltype(this->marked_groups)> == lengthof(mark_colours));
|
||||
Rect mark_ir = ir.Indent(WidgetDimensions::scaled.hsep_normal, rtl).WithWidth(WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, (scroll_offset * this->resize.step_height));
|
||||
GfxFillRect(mark_ir.left, mark_ir.top, mark_ir.right, mark_ir.top + this->resize.step_height - 1, mark_colours[i]);
|
||||
break;
|
||||
|
@@ -113,7 +113,7 @@ void ResetHouseClassIDs()
|
||||
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32_t grfid)
|
||||
{
|
||||
/* Start from 1 because 0 means that no class has been assigned. */
|
||||
for (int i = 1; i != lengthof(_class_mapping); i++) {
|
||||
for (size_t i = 1; i != std::size(_class_mapping); i++) {
|
||||
HouseClassMapping *map = &_class_mapping[i];
|
||||
|
||||
if (map->class_id == grf_class_id && map->grfid == grfid) return (HouseClassID)i;
|
||||
|
@@ -3650,7 +3650,7 @@ bool AfterLoadGame()
|
||||
if (IsSavegameVersionBefore(SLV_EXTEND_INDUSTRY_CARGO_SLOTS)) {
|
||||
/* Make sure added industry cargo slots are cleared */
|
||||
for (Industry *i : Industry::Iterate()) {
|
||||
for (size_t ci = 2; ci < lengthof(i->produced_cargo); ci++) {
|
||||
for (size_t ci = 2; ci < std::size(i->produced_cargo); ci++) {
|
||||
i->produced_cargo[ci] = INVALID_CARGO;
|
||||
i->produced_cargo_waiting[ci] = 0;
|
||||
i->production_rate[ci] = 0;
|
||||
@@ -3660,13 +3660,13 @@ bool AfterLoadGame()
|
||||
i->this_month_production[ci] = 0;
|
||||
i->this_month_transported[ci] = 0;
|
||||
}
|
||||
for (size_t ci = 3; ci < lengthof(i->accepts_cargo); ci++) {
|
||||
for (size_t ci = 3; ci < std::size(i->accepts_cargo); ci++) {
|
||||
i->accepts_cargo[ci] = INVALID_CARGO;
|
||||
i->incoming_cargo_waiting[ci] = 0;
|
||||
}
|
||||
/* Make sure last_cargo_accepted_at is copied to elements for every valid input cargo.
|
||||
* The loading routine should put the original singular value into the first array element. */
|
||||
for (size_t ci = 0; ci < lengthof(i->accepts_cargo); ci++) {
|
||||
for (size_t ci = 0; ci < std::size(i->accepts_cargo); ci++) {
|
||||
if (i->accepts_cargo[ci] != INVALID_CARGO) {
|
||||
i->last_cargo_accepted_at[ci] = i->last_cargo_accepted_at[0];
|
||||
} else {
|
||||
|
@@ -29,7 +29,7 @@ ScriptCargoList_IndustryAccepting::ScriptCargoList_IndustryAccepting(IndustryID
|
||||
if (!ScriptIndustry::IsValidIndustry(industry_id)) return;
|
||||
|
||||
Industry *ind = ::Industry::Get(industry_id);
|
||||
for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
|
||||
for (size_t i = 0; i < ind->accepts_cargo.size(); i++) {
|
||||
CargoID cargo_id = ind->accepts_cargo[i];
|
||||
if (cargo_id != INVALID_CARGO) {
|
||||
this->AddItem(cargo_id);
|
||||
@@ -42,7 +42,7 @@ ScriptCargoList_IndustryProducing::ScriptCargoList_IndustryProducing(IndustryID
|
||||
if (!ScriptIndustry::IsValidIndustry(industry_id)) return;
|
||||
|
||||
Industry *ind = ::Industry::Get(industry_id);
|
||||
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
|
||||
for (size_t i = 0; i < ind->produced_cargo.size(); i++) {
|
||||
CargoID cargo_id = ind->produced_cargo[i];
|
||||
if (cargo_id != INVALID_CARGO) {
|
||||
this->AddItem(cargo_id);
|
||||
|
@@ -97,7 +97,7 @@ ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID in
|
||||
CargoArray acceptance = ::GetAcceptanceAroundTiles(cur_tile, 1, 1, radius);
|
||||
{
|
||||
bool cargo_accepts = false;
|
||||
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
||||
for (size_t j = 0; j < i->accepts_cargo.size(); j++) {
|
||||
if (i->accepts_cargo[j] != INVALID_CARGO && acceptance[i->accepts_cargo[j]] != 0) cargo_accepts = true;
|
||||
}
|
||||
if (!cargo_accepts) continue;
|
||||
|
@@ -16,8 +16,8 @@
|
||||
|
||||
static void Save_NSID()
|
||||
{
|
||||
SlSetLength(4 + (lengthof(_new_signal_style_mapping) * 5));
|
||||
SlWriteUint32(lengthof(_new_signal_style_mapping));
|
||||
SlSetLength(4 + (_new_signal_style_mapping.size() * 5));
|
||||
SlWriteUint32(_new_signal_style_mapping.size());
|
||||
for (const NewSignalStyleMapping &mapping : _new_signal_style_mapping) {
|
||||
SlWriteUint32(mapping.grfid);
|
||||
SlWriteByte(mapping.grf_local_id);
|
||||
@@ -33,7 +33,7 @@ static void Load_NSID()
|
||||
NewSignalStyleMapping mapping;
|
||||
mapping.grfid = SlReadUint32();
|
||||
mapping.grf_local_id = SlReadByte();
|
||||
if (i < lengthof(_new_signal_style_mapping)) _new_signal_style_mapping[i] = mapping;
|
||||
if (i < _new_signal_style_mapping.size()) _new_signal_style_mapping[i] = mapping;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -166,7 +166,7 @@ static bool CMSAMine(TileIndex tile)
|
||||
/* No extractive industry */
|
||||
if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
|
||||
|
||||
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
|
||||
for (uint i = 0; i < std::size(ind->produced_cargo); i++) {
|
||||
/* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine.
|
||||
* Also the production of passengers and mail is ignored. */
|
||||
if (ind->produced_cargo[i] != INVALID_CARGO &&
|
||||
@@ -639,7 +639,7 @@ CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
|
||||
/* Skip industry with neutral station */
|
||||
if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) continue;
|
||||
|
||||
for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||
for (uint j = 0; j < std::size(i->produced_cargo); j++) {
|
||||
CargoID cargo = i->produced_cargo[j];
|
||||
if (cargo != INVALID_CARGO) produced[cargo]++;
|
||||
}
|
||||
|
@@ -406,12 +406,12 @@ bool FindSubsidyIndustryCargoRoute()
|
||||
/* Randomize cargo type */
|
||||
int num_cargos = 0;
|
||||
uint cargo_index;
|
||||
for (cargo_index = 0; cargo_index < lengthof(src_ind->produced_cargo); cargo_index++) {
|
||||
for (cargo_index = 0; cargo_index < std::size(src_ind->produced_cargo); cargo_index++) {
|
||||
if (src_ind->produced_cargo[cargo_index] != INVALID_CARGO) num_cargos++;
|
||||
}
|
||||
if (num_cargos == 0) return false; // industry produces nothing
|
||||
int cargo_num = RandomRange(num_cargos) + 1;
|
||||
for (cargo_index = 0; cargo_index < lengthof(src_ind->produced_cargo); cargo_index++) {
|
||||
for (cargo_index = 0; cargo_index < std::size(src_ind->produced_cargo); cargo_index++) {
|
||||
if (src_ind->produced_cargo[cargo_index] != INVALID_CARGO) cargo_num--;
|
||||
if (cargo_num == 0) break;
|
||||
}
|
||||
|
@@ -1245,7 +1245,7 @@ class NIHIndustry : public NIHelper {
|
||||
output.print(buffer);
|
||||
}
|
||||
output.print(" Produces:");
|
||||
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
|
||||
for (uint i = 0; i < std::size(ind->produced_cargo); i++) {
|
||||
if (ind->produced_cargo[i] != INVALID_CARGO) {
|
||||
seprintf(buffer, lastof(buffer), " %s:", GetStringPtr(CargoSpec::Get(ind->produced_cargo[i])->name));
|
||||
output.print(buffer);
|
||||
@@ -1261,7 +1261,7 @@ class NIHIndustry : public NIHelper {
|
||||
}
|
||||
}
|
||||
output.print(" Accepts:");
|
||||
for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
|
||||
for (uint i = 0; i < std::size(ind->accepts_cargo); i++) {
|
||||
if (ind->accepts_cargo[i] != INVALID_CARGO) {
|
||||
seprintf(buffer, lastof(buffer), " %s: waiting: %u",
|
||||
GetStringPtr(CargoSpec::Get(ind->accepts_cargo[i])->name), ind->incoming_cargo_waiting[i]);
|
||||
|
@@ -242,12 +242,12 @@ SpriteID TileZoneCheckUnservedIndustriesEvaluation(TileIndex tile, Owner owner)
|
||||
if (st->facilities & (~(FACIL_BUS_STOP | FACIL_TRUCK_STOP)) || st->facilities == (FACIL_BUS_STOP | FACIL_TRUCK_STOP)) {
|
||||
return ZONING_INVALID_SPRITE_ID;
|
||||
} else if (st->facilities & (FACIL_BUS_STOP | FACIL_TRUCK_STOP)) {
|
||||
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
|
||||
for (uint i = 0; i < std::size(ind->produced_cargo); i++) {
|
||||
if (ind->produced_cargo[i] != INVALID_CARGO && st->facilities & (IsCargoInClass(ind->produced_cargo[i], CC_PASSENGERS) ? FACIL_BUS_STOP : FACIL_TRUCK_STOP)) {
|
||||
return ZONING_INVALID_SPRITE_ID;
|
||||
}
|
||||
}
|
||||
for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) {
|
||||
for (uint i = 0; i < std::size(ind->accepts_cargo); i++) {
|
||||
if (ind->accepts_cargo[i] != INVALID_CARGO && st->facilities & (IsCargoInClass(ind->accepts_cargo[i], CC_PASSENGERS) ? FACIL_BUS_STOP : FACIL_TRUCK_STOP)) {
|
||||
return ZONING_INVALID_SPRITE_ID;
|
||||
}
|
||||
|
Reference in New Issue
Block a user