summaryrefslogtreecommitdiff
path: root/src/economy.cpp
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2021-01-08 10:16:18 +0000
committerGitHub <noreply@github.com>2021-01-08 11:16:18 +0100
commit9b800a96ed32720ff60b74e498a0e0a6351004f9 (patch)
tree3f287d339e15c4902ee415556475fd9b2918d33c /src/economy.cpp
parentc1fddb9a6ae5c3af6865461a7295788a341011a2 (diff)
downloadopenttd-9b800a96ed32720ff60b74e498a0e0a6351004f9.tar.xz
Codechange: Remove min/max functions in favour of STL variants (#8502)
Diffstat (limited to 'src/economy.cpp')
-rw-r--r--src/economy.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index c73012096..d5c7797d5 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -135,7 +135,7 @@ Money CalculateCompanyValue(const Company *c, bool including_loan)
if (including_loan) value -= c->current_loan;
value += c->money;
- return max(value, (Money)1);
+ return std::max<Money>(value, 1);
}
/**
@@ -194,15 +194,15 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
/* Generate statistics depending on recent income statistics */
{
- int numec = min(c->num_valid_stat_ent, 12);
+ int numec = std::min<uint>(c->num_valid_stat_ent, 12u);
if (numec != 0) {
const CompanyEconomyEntry *cee = c->old_economy;
Money min_income = cee->income + cee->expenses;
Money max_income = cee->income + cee->expenses;
do {
- min_income = min(min_income, cee->income + cee->expenses);
- max_income = max(max_income, cee->income + cee->expenses);
+ min_income = std::min(min_income, cee->income + cee->expenses);
+ max_income = std::max(max_income, cee->income + cee->expenses);
} while (++cee, --numec);
if (min_income > 0) {
@@ -215,7 +215,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
/* Generate score depending on amount of transported cargo */
{
- int numec = min(c->num_valid_stat_ent, 4);
+ int numec = std::min<uint>(c->num_valid_stat_ent, 4u);
if (numec != 0) {
const CompanyEconomyEntry *cee = c->old_economy;
OverflowSafeInt64 total_delivered = 0;
@@ -361,7 +361,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
if (HasBit(t->have_ratings, old_owner)) {
if (HasBit(t->have_ratings, new_owner)) {
/* use max of the two ratings. */
- t->ratings[new_owner] = max(t->ratings[new_owner], t->ratings[old_owner]);
+ t->ratings[new_owner] = std::max(t->ratings[new_owner], t->ratings[old_owner]);
} else {
SetBit(t->have_ratings, new_owner);
t->ratings[new_owner] = t->ratings[old_owner];
@@ -911,12 +911,12 @@ void StartupEconomy()
{
_economy.interest_rate = _settings_game.difficulty.initial_interest;
_economy.infl_amount = _settings_game.difficulty.initial_interest;
- _economy.infl_amount_pr = max(0, _settings_game.difficulty.initial_interest - 1);
+ _economy.infl_amount_pr = std::max(0, _settings_game.difficulty.initial_interest - 1);
_economy.fluct = GB(Random(), 0, 8) + 168;
if (_settings_game.economy.inflation) {
/* Apply inflation that happened before our game start year. */
- int months = (min(_cur_year, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR) * 12;
+ int months = (std::min(_cur_year, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR) * 12;
for (int i = 0; i < months; i++) {
AddInflation(false);
}
@@ -973,7 +973,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
/* Use callback to calculate cargo profit, if available */
if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
- uint32 var18 = min(dist, 0xFFFF) | (min(num_pieces, 0xFF) << 16) | (transit_days << 24);
+ uint32 var18 = std::min(dist, 0xFFFFu) | (std::min(num_pieces, 0xFFu) << 16) | (transit_days << 24);
uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs);
if (callback != CALLBACK_FAILED) {
int result = GB(callback, 0, 14);
@@ -993,8 +993,8 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
const int days1 = cs->transit_days[0];
const int days2 = cs->transit_days[1];
- const int days_over_days1 = max( transit_days - days1, 0);
- const int days_over_days2 = max(days_over_days1 - days2, 0);
+ const int days_over_days1 = std::max( transit_days - days1, 0);
+ const int days_over_days2 = std::max(days_over_days1 - days2, 0);
/*
* The time factor is calculated based on the time it took
@@ -1006,7 +1006,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
* - linear decreasing with time with a slope of -2 for slow transports
*
*/
- const int time_factor = max(MAX_TIME_FACTOR - days_over_days1 - days_over_days2, MIN_TIME_FACTOR);
+ const int time_factor = std::max(MAX_TIME_FACTOR - days_over_days1 - days_over_days2, MIN_TIME_FACTOR);
return BigMulS(dist * time_factor * num_pieces, cs->current_payment, 21);
}
@@ -1055,7 +1055,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
/* Insert the industry into _cargo_delivery_destinations, if not yet contained */
include(_cargo_delivery_destinations, ind);
- uint amount = min(num_pieces, 0xFFFFU - ind->incoming_cargo_waiting[cargo_index]);
+ uint amount = std::min(num_pieces, 0xFFFFu - ind->incoming_cargo_waiting[cargo_index]);
ind->incoming_cargo_waiting[cargo_index] += amount;
ind->last_cargo_accepted_at[cargo_index] = _date;
num_pieces -= amount;
@@ -1150,7 +1150,7 @@ static void TriggerIndustryProduction(Industry *i)
if (cargo_waiting == 0) continue;
for (uint ci_out = 0; ci_out < lengthof(i->produced_cargo_waiting); ci_out++) {
- i->produced_cargo_waiting[ci_out] = min(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256), 0xFFFF);
+ i->produced_cargo_waiting[ci_out] = std::min(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256), 0xFFFFu);
}
i->incoming_cargo_waiting[ci_in] = 0;
@@ -1317,7 +1317,7 @@ static uint GetLoadAmount(Vehicle *v)
if (HasBit(e->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER) && !air_mail) load_amount = CeilDiv(load_amount * CargoSpec::Get(v->cargo_type)->multiplier, 0x100);
/* Zero load amount breaks a lot of things. */
- return max(1u, load_amount);
+ return std::max(1u, load_amount);
}
/**
@@ -1596,7 +1596,7 @@ static void UpdateLoadUnloadTicks(Vehicle *front, const Station *st, int ticks)
}
}
/* Always wait at least 1, otherwise we'll wait 'infinitively' long. */
- front->load_unload_ticks = max(1, ticks);
+ front->load_unload_ticks = std::max(1, ticks);
}
/**
@@ -1657,7 +1657,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && (front->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
uint cargo_count = v->cargo.UnloadCount();
- uint amount_unloaded = _settings_game.order.gradual_loading ? min(cargo_count, GetLoadAmount(v)) : cargo_count;
+ uint amount_unloaded = _settings_game.order.gradual_loading ? std::min(cargo_count, GetLoadAmount(v)) : cargo_count;
bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here?
assert(payment != nullptr);
@@ -1753,8 +1753,8 @@ static void LoadUnloadVehicle(Vehicle *front)
}
/* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
- ge->last_speed = min(t, 255);
- ge->last_age = min(_cur_year - front->build_year, 255);
+ ge->last_speed = std::min(t, 255);
+ ge->last_age = std::min(_cur_year - front->build_year, 255);
assert(v->cargo_cap >= v->cargo.StoredCount());
/* Capacity available for loading more cargo. */
@@ -1768,7 +1768,7 @@ static void LoadUnloadVehicle(Vehicle *front)
* has capacity for it, load it on the vehicle. */
if ((v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0 || ge->cargo.AvailableCount() > 0) && MayLoadUnderExclusiveRights(st, v)) {
if (v->cargo.StoredCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
- if (_settings_game.order.gradual_loading) cap_left = min(cap_left, GetLoadAmount(v));
+ if (_settings_game.order.gradual_loading) cap_left = std::min(cap_left, GetLoadAmount(v));
uint loaded = ge->cargo.Load(cap_left, &v->cargo, st->xy, next_station);
if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) {
@@ -1842,7 +1842,7 @@ static void LoadUnloadVehicle(Vehicle *front)
/* We loaded less cargo than possible for all cargo types and it's not full
* load and we're not supposed to wait any longer: stop loading. */
if (!anything_unloaded && full_load_amount == 0 && reservation_left == 0 && !(front->current_order.GetLoadType() & OLFB_FULL_LOAD) &&
- front->current_order_time >= (uint)max(front->current_order.GetTimetabledWait() - front->lateness_counter, 0)) {
+ front->current_order_time >= (uint)std::max(front->current_order.GetTimetabledWait() - front->lateness_counter, 0)) {
SetBit(front->vehicle_flags, VF_STOP_LOADING);
}