summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-07-26 14:58:08 +0000
committerpeter1138 <peter1138@openttd.org>2008-07-26 14:58:08 +0000
commitea7ed286a63fdade4f1b55738a9d0fb110c00c01 (patch)
treed17b928f3de188584a0eaae5d28c2c6ff33bc07e
parent49c971c8eb096f6ce3dde397c37c0d49631e5ab6 (diff)
downloadopenttd-ea7ed286a63fdade4f1b55738a9d0fb110c00c01.tar.xz
(svn r13836) -Fix [FS#2074]: Automatically recalculate inflation if NewGRFs are changed and cargo types are added, so that cargo payment rates are correct.
-rw-r--r--src/economy.cpp36
-rw-r--r--src/economy_func.h1
-rw-r--r--src/openttd.cpp1
3 files changed, 34 insertions, 4 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 9983ecfaf..ee1c155d5 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -621,7 +621,7 @@ static void AddSingleInflation(Money *value, uint16 *frac, int32 amt)
}
}
-static void AddInflation()
+static void AddInflation(bool check_year = true)
{
/* The cargo payment inflation differs from the normal inflation, so the
* relative amount of money you make with a transport decreases slowly over
@@ -638,7 +638,7 @@ static void AddInflation()
* inflation doesn't add anything after that either; it even makes playing
* it impossible due to the diverging cost and income rates.
*/
- if ((_cur_year - _settings_game.game_creation.starting_year) >= (ORIGINAL_MAX_YEAR - ORIGINAL_BASE_YEAR)) return;
+ if (check_year && (_cur_year - _settings_game.game_creation.starting_year) >= (ORIGINAL_MAX_YEAR - ORIGINAL_BASE_YEAR)) return;
/* Approximation for (100 + infl_amount)% ** (1 / 12) - 100%
* scaled by 65536
@@ -818,6 +818,35 @@ void StartupEconomy()
_economy.fluct = GB(Random(), 0, 8) + 168;
}
+void ResetEconomy()
+{
+ /* Test if resetting the economy is needed. */
+ bool needed = false;
+
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
+ const CargoSpec *cs = GetCargo(c);
+ if (!cs->IsValid()) continue;
+ if (_cargo_payment_rates[c] == 0) {
+ needed = true;
+ break;
+ }
+ }
+
+ if (!needed) return;
+
+ /* Remember old unrounded maximum loan value. NewGRF has the ability
+ * to change all the other inflation affected base costs. */
+ Money old_value = _economy.max_loan_unround;
+
+ /* Reset the economy */
+ StartupEconomy();
+ InitializeLandscapeVariables(false);
+
+ /* Reapply inflation, ignoring the year */
+ while (old_value > _economy.max_loan_unround) {
+ AddInflation(false);
+ }
+}
Money GetPriceByIndex(uint8 index)
{
@@ -1718,8 +1747,7 @@ void LoadUnloadStation(Station *st)
void PlayersMonthlyLoop()
{
PlayersGenStatistics();
- if (_settings_game.economy.inflation && _cur_year < MAX_YEAR)
- AddInflation();
+ if (_settings_game.economy.inflation) AddInflation();
PlayersPayInterest();
/* Reset the _current_player flag */
_current_player = OWNER_NONE;
diff --git a/src/economy_func.h b/src/economy_func.h
index 8ce3a5e6f..f458ad1c6 100644
--- a/src/economy_func.h
+++ b/src/economy_func.h
@@ -19,6 +19,7 @@ struct Player;
void ResetPriceBaseMultipliers();
void SetPriceBaseMultiplier(uint price, byte factor);
+void ResetEconomy();
extern const ScoreInfo _score_info[];
extern int _score_part[MAX_PLAYERS][SCORE_END];
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 0fdb22b55..31bfeb33d 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -2454,6 +2454,7 @@ void ReloadNewGRFData()
/* reload grf data */
GfxLoadSprites();
LoadStringWidthTable();
+ ResetEconomy();
/* reload vehicles */
ResetVehiclePosHash();
AfterLoadVehicles(false);