From d83647f9a7aaa2adb5ffa1042613f256134a9e1d Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 22 Jul 2021 21:09:33 +0200 Subject: [PATCH] Fix #9440: negative cargo payments not being handled right Cargo payments were stored as unsigned integer, but cast to int64 during application of inflation. However, then being multiplied with a uint64 making the result uint64. So in the end the payment that should have been negative becomes hugely positive. --- src/cargotype.h | 2 +- src/economy.cpp | 2 +- src/economy_type.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cargotype.h b/src/cargotype.h index a398d60795..5ed9ac90e2 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -61,7 +61,7 @@ struct CargoSpec { uint8 rating_colour; uint8 weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg). uint16 multiplier; ///< Capacity multiplier for vehicles. (8 fractional bits) - uint32 initial_payment; ///< Initial payment rate before inflation is applied. + int32 initial_payment; ///< Initial payment rate before inflation is applied. uint8 transit_days[2]; bool is_freight; ///< Cargo type is considered to be freight (affects train freight multiplier). diff --git a/src/economy.cpp b/src/economy.cpp index c3332c4d12..936fba7896 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -803,7 +803,7 @@ void RecomputePrices() /* Setup cargo payment */ for (CargoSpec *cs : CargoSpec::Iterate()) { - cs->current_payment = ((int64)cs->initial_payment * _economy.inflation_payment) >> 16; + cs->current_payment = (cs->initial_payment * (int64)_economy.inflation_payment) >> 16; } SetWindowClassesDirty(WC_BUILD_VEHICLE); diff --git a/src/economy_type.h b/src/economy_type.h index 85a1bbe4fc..1cb43b8ee9 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -34,7 +34,7 @@ struct Economy { uint32 industry_daily_change_counter; ///< Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily uint32 industry_daily_increment; ///< The value which will increment industry_daily_change_counter. Computed value. NOSAVE uint64 inflation_prices; ///< Cumulated inflation of prices since game start; 16 bit fractional part - uint64 inflation_payment; ///< Cumulated inflation of cargo paypent since game start; 16 bit fractional part + uint64 inflation_payment; ///< Cumulated inflation of cargo payment since game start; 16 bit fractional part /* Old stuff for savegame conversion only */ Money old_max_loan_unround; ///< Old: Unrounded max loan