Update to 1.11.0-beta1

This commit is contained in:
dP
2021-01-23 17:31:11 +03:00
parent d3c06c25c8
commit 5e4506f493
1045 changed files with 23534 additions and 60345 deletions
+33 -23
View File
@@ -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];
@@ -722,7 +722,7 @@ bool AddInflation(bool check_year)
* inflation doesn't add anything after that either; it even makes playing
* it impossible due to the diverging cost and income rates.
*/
if (check_year && (_cur_year - _settings_game.game_creation.starting_year) >= (ORIGINAL_MAX_YEAR - ORIGINAL_BASE_YEAR)) return true;
if (check_year && (_cur_year < ORIGINAL_BASE_YEAR || _cur_year >= ORIGINAL_MAX_YEAR)) return true;
if (_economy.inflation_prices == MAX_INFLATION || _economy.inflation_payment == MAX_INFLATION) return true;
@@ -746,7 +746,7 @@ bool AddInflation(bool check_year)
void RecomputePrices()
{
/* Setup maximum loan */
_economy.max_loan = (_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / 50000 * 50000;
_economy.max_loan = ((uint64)_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / 50000 * 50000;
/* Setup price bases */
for (Price i = PR_BEGIN; i < PR_END; i++) {
@@ -911,9 +911,17 @@ 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 = (std::min(_cur_year, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR) * 12;
for (int i = 0; i < months; i++) {
AddInflation(false);
}
}
/* Set up prices */
RecomputePrices();
@@ -965,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);
@@ -985,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
@@ -998,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);
}
@@ -1042,10 +1050,12 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
/* Check if industry temporarily refuses acceptance */
if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue;
if (ind->exclusive_supplier != INVALID_OWNER && ind->exclusive_supplier != st->owner) continue;
/* 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;
@@ -1140,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;
@@ -1248,7 +1258,7 @@ void PrepareUnload(Vehicle *front_v)
assert(front_v->cargo_payment == nullptr);
/* One CargoPayment per vehicle and the vehicle limit equals the
* limit in number of CargoPayments. Can't go wrong. */
assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
static_assert(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
assert(CargoPayment::CanAllocateItem());
front_v->cargo_payment = new CargoPayment(front_v);
@@ -1307,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);
}
/**
@@ -1586,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);
}
/**
@@ -1647,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);
@@ -1743,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. */
@@ -1758,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) {
@@ -1832,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);
}