Codechange: Remove min/max functions in favour of STL variants (#8502)

This commit is contained in:
Charles Pigott
2021-01-08 10:16:18 +00:00
committed by GitHub
parent c1fddb9a6a
commit 9b800a96ed
181 changed files with 900 additions and 954 deletions

View File

@@ -531,7 +531,7 @@ static bool TransportIndustryGoods(TileIndex tile)
bool moved_cargo = false;
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
uint cw = min(i->produced_cargo_waiting[j], 255);
uint cw = std::min<uint>(i->produced_cargo_waiting[j], 255u);
if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) {
i->produced_cargo_waiting[j] -= cw;
@@ -1032,7 +1032,7 @@ static void PlantFarmField(TileIndex tile, IndustryID industry)
uint size_x = GB(r, 0, 8);
uint size_y = GB(r, 8, 8);
TileArea ta(tile - TileDiffXY(min(TileX(tile), size_x / 2), min(TileY(tile), size_y / 2)), size_x, size_y);
TileArea ta(tile - TileDiffXY(std::min(TileX(tile), size_x / 2), std::min(TileY(tile), size_y / 2)), size_x, size_y);
ta.ClampToMap();
if (ta.w == 0 || ta.h == 0) return;
@@ -1121,7 +1121,7 @@ static void ChopLumberMillTrees(Industry *i)
TileIndex tile = i->location.tile;
if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, nullptr)) { // 40x40 tiles to search.
i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); // Found a tree, add according value to waiting cargo.
i->produced_cargo_waiting[0] = std::min(0xffff, i->produced_cargo_waiting[0] + 45); // Found a tree, add according value to waiting cargo.
}
}
@@ -1153,7 +1153,7 @@ static void ProduceIndustryGoods(Industry *i)
IndustryBehaviour indbehav = indsp->behaviour;
for (size_t j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
i->produced_cargo_waiting[j] = min(0xffff, i->produced_cargo_waiting[j] + i->production_rate[j]);
i->produced_cargo_waiting[j] = std::min(0xffff, i->produced_cargo_waiting[j] + i->production_rate[j]);
}
if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
@@ -1743,7 +1743,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++) {
i->production_rate[ci] = min((RandomRange(256) + 128) * i->production_rate[ci] >> 8, 255);
i->production_rate[ci] = std::min((RandomRange(256) + 128) * i->production_rate[ci] >> 8, 255u);
}
}
@@ -2208,7 +2208,7 @@ static uint GetNumberOfIndustries()
assert(lengthof(numof_industry_table) == ID_END);
uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.industry_density : (uint)ID_VERY_LOW;
return min(IndustryPool::MAX_SIZE, ScaleByMapSize(numof_industry_table[difficulty]));
return std::min<uint>(IndustryPool::MAX_SIZE, ScaleByMapSize(numof_industry_table[difficulty]));
}
/**
@@ -2284,7 +2284,7 @@ void IndustryBuildData::MonthlyLoop()
/* To prevent running out of unused industries for the player to connect,
* add a fraction of new industries each month, but only if the manager can keep up. */
uint max_behind = 1 + min(99u, ScaleByMapSize(3)); // At most 2 industries for small maps, and 100 at the biggest map (about 6 months industry build attempts).
uint max_behind = 1 + std::min(99u, ScaleByMapSize(3)); // At most 2 industries for small maps, and 100 at the biggest map (about 6 months industry build attempts).
if (GetCurrentTotalNumberOfIndustries() + max_behind >= (this->wanted_inds >> 16)) {
this->wanted_inds += ScaleByMapSize(NEWINDS_PER_MONTH);
}
@@ -2352,7 +2352,7 @@ static void UpdateIndustryStatistics(Industry *i)
byte pct = 0;
if (i->this_month_production[j] != 0) {
i->last_prod_year = _cur_year;
pct = min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255);
pct = std::min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255);
}
i->last_month_pct_transported[j] = pct;
@@ -2376,7 +2376,7 @@ void Industry::RecomputeProductionMultipliers()
/* Rates are rounded up, so e.g. oilrig always produces some passengers */
for (size_t i = 0; i < lengthof(this->production_rate); i++) {
this->production_rate[i] = min(CeilDiv(indspec->production_rate[i] * this->prod_level, PRODLEVEL_DEFAULT), 0xFF);
this->production_rate[i] = std::min(CeilDiv(indspec->production_rate[i] * this->prod_level, PRODLEVEL_DEFAULT), 0xFFu);
}
}
@@ -2509,10 +2509,10 @@ void IndustryBuildData::TryBuildNewIndustry()
const Industry *ind = PlaceIndustry(it, IACT_RANDOMCREATION, false);
if (ind == nullptr) {
this->builddata[it].wait_count = this->builddata[it].max_wait + 1; // Compensate for decrementing below.
this->builddata[it].max_wait = min(1000, this->builddata[it].max_wait + 2);
this->builddata[it].max_wait = std::min(1000, this->builddata[it].max_wait + 2);
} else {
AdvertiseIndustryOpening(ind);
this->builddata[it].max_wait = max(this->builddata[it].max_wait / 2, 1); // Reduce waiting time of the industry type.
this->builddata[it].max_wait = std::max(this->builddata[it].max_wait / 2, 1); // Reduce waiting time of the industry type.
}
}
@@ -2749,7 +2749,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
/* 4.5% chance for 3-23% (or 1 unit for very low productions) production change,
* determined by mult value. If mult = 1 prod. increases, else (-1) it decreases. */
if (Chance16I(1, 22, r >> 16)) {
new_prod += mult * (max(((RandomRange(50) + 10) * old_prod) >> 8, 1U));
new_prod += mult * (std::max(((RandomRange(50) + 10) * old_prod) >> 8, 1U));
}
/* Prevent production to overflow or Oil Rig passengers to be over-"produced" */
@@ -2794,7 +2794,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
/* Increase if needed */
while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM);
i->prod_level = std::min<int>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
recalculate_multipliers = true;
if (str == STR_NULL) str = indspec->production_up_text;
}
@@ -2805,7 +2805,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
closeit = true;
break;
} else {
i->prod_level = max(i->prod_level / 2, (int)PRODLEVEL_MINIMUM); // typecast to int required to please MSVC
i->prod_level = std::max<int>(i->prod_level / 2, PRODLEVEL_MINIMUM);
recalculate_multipliers = true;
if (str == STR_NULL) str = indspec->production_down_text;
}
@@ -2897,7 +2897,7 @@ void IndustryDailyLoop()
uint perc = 3; // Between 3% and 9% chance of creating a new industry.
if ((_industry_builder.wanted_inds >> 16) > GetCurrentTotalNumberOfIndustries()) {
perc = min(9u, perc + (_industry_builder.wanted_inds >> 16) - GetCurrentTotalNumberOfIndustries());
perc = std::min(9u, perc + (_industry_builder.wanted_inds >> 16) - GetCurrentTotalNumberOfIndustries());
}
for (uint16 j = 0; j < change_loop; j++) {
if (Chance16(perc, 100)) {