summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-09-06 18:53:57 +0000
committerfrosch <frosch@openttd.org>2009-09-06 18:53:57 +0000
commit438a429549486f08919748cee0f5346ccacf760b (patch)
tree3858342b95e237dcb97d35476646e0d0f9d23aeb /src/saveload
parent2ce1a608a8ff5eb4cd6582adac990b2004ce1103 (diff)
downloadopenttd-438a429549486f08919748cee0f5346ccacf760b.tar.xz
(svn r17433) -Codechange: Store cumulated inflation in savegame and compute all prices from that instead of storing all prices separately.
Note: Savegame conversion computes the inflation from max loan. Prices from modified savegames will get lost. TTO savegames will also behave slightly different. -Change: NewGRF price modifiers now take effect everytime when loading NewGRFs instead of once on gamestart.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp25
-rw-r--r--src/saveload/economy_sl.cpp36
-rw-r--r--src/saveload/oldloader_sl.cpp92
-rw-r--r--src/saveload/saveload.cpp2
4 files changed, 56 insertions, 99 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index d76638183..ce03b01af 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -234,6 +234,8 @@ static void InitializeWindowsAndCaches()
}
}
+ RecomputePrices();
+
SetCachedEngineCounts();
Station::RecomputeIndustriesNearForAll();
@@ -530,9 +532,6 @@ bool AfterLoadGame()
/* Connect front and rear engines of multiheaded trains */
ConnectMultiheadedTrains();
- /* reinit the landscape variables (landscape might have changed) */
- InitializeLandscapeVariables(true);
-
/* Update all vehicles */
AfterLoadVehicles(true);
@@ -1929,6 +1928,24 @@ bool AfterLoadGame()
}
}
+ if (CheckSavegameVersion(126)) {
+ /* Recompute inflation based on old unround loan limit
+ * Note: Max loan is 500000. With an inflation of 4% across 170 years
+ * that results in a max loan of about 0.7 * 2^31.
+ * So taking the 16 bit fractional part into account there are plenty of bits left
+ * for unmodified savegames ...
+ */
+ uint64 aimed_inflation = (_economy.old_max_loan_unround << 16 | _economy.old_max_loan_unround_fract) / _settings_game.difficulty.max_loan;
+
+ /* ... well, just clamp it then. */
+ if (aimed_inflation > MAX_INFLATION) aimed_inflation = MAX_INFLATION;
+
+ /* Simulate the inflation, so we also get the payment inflation */
+ while (_economy.inflation_prices < aimed_inflation) {
+ AddInflation(false);
+ }
+ }
+
AfterLoadLabelMaps();
GamelogPrintDebug(1);
@@ -1950,7 +1967,7 @@ void ReloadNewGRFData()
/* reload grf data */
GfxLoadSprites();
LoadStringWidthTable();
- ResetEconomy();
+ RecomputePrices();
/* reload vehicles */
ResetVehiclePosHash();
AfterLoadVehicles(false);
diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp
index 1e083a295..fccbb4bf3 100644
--- a/src/saveload/economy_sl.cpp
+++ b/src/saveload/economy_sl.cpp
@@ -15,29 +15,31 @@
#include "saveload.h"
-/** Prices */
-static void SaveLoad_PRIC()
+/** Prices in pre 126 savegames */
+static void Load_PRIC()
{
- int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64;
- SlArray(&_price, NUM_PRICES, vt);
- SlArray(&_price_frac, NUM_PRICES, SLE_UINT16);
+ int vt = CheckSavegameVersion(65) ? SLE_FILE_I32 : SLE_FILE_I64;
+ SlArray(NULL, NUM_PRICES, vt | SLE_VAR_NULL);
+ SlArray(NULL, NUM_PRICES, SLE_FILE_U16 | SLE_VAR_NULL);
}
-/** Cargo payment rates */
-static void SaveLoad_CAPR()
+/** Cargo payment rates in pre 126 savegames */
+static void Load_CAPR()
{
uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
- int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64;
- SlArray(&_cargo_payment_rates, num_cargo, vt);
- SlArray(&_cargo_payment_rates_frac, num_cargo, SLE_UINT16);
+ int vt = CheckSavegameVersion(65) ? SLE_FILE_I32 : SLE_FILE_I64;
+ SlArray(NULL, num_cargo, vt | SLE_VAR_NULL);
+ SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
}
static const SaveLoad _economy_desc[] = {
- SLE_CONDVAR(Economy, max_loan, SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
- SLE_CONDVAR(Economy, max_loan, SLE_INT64, 65, SL_MAX_VERSION),
- SLE_CONDVAR(Economy, max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
- SLE_CONDVAR(Economy, max_loan_unround, SLE_INT64, 65, SL_MAX_VERSION),
- SLE_CONDVAR(Economy, max_loan_unround_fract, SLE_UINT16, 70, SL_MAX_VERSION),
+ SLE_CONDNULL(4, 0, 64), // max_loan
+ SLE_CONDNULL(8, 65, SL_MAX_VERSION), // max_loan
+ SLE_CONDVAR(Economy, old_max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
+ SLE_CONDVAR(Economy, old_max_loan_unround, SLE_INT64, 65, 125),
+ SLE_CONDVAR(Economy, old_max_loan_unround_fract, SLE_UINT16, 70, 125),
+ SLE_CONDVAR(Economy, inflation_prices, SLE_UINT64, 126, SL_MAX_VERSION),
+ SLE_CONDVAR(Economy, inflation_payment, SLE_UINT64, 126, SL_MAX_VERSION),
SLE_VAR(Economy, fluct, SLE_INT16),
SLE_VAR(Economy, interest_rate, SLE_UINT8),
SLE_VAR(Economy, infl_amount, SLE_UINT8),
@@ -97,7 +99,7 @@ static void Ptrs_CAPY()
extern const ChunkHandler _economy_chunk_handlers[] = {
{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, CH_ARRAY},
- { 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, NULL, CH_RIFF | CH_AUTO_LENGTH},
- { 'CAPR', SaveLoad_CAPR, SaveLoad_CAPR, NULL, CH_RIFF | CH_AUTO_LENGTH},
+ { 'PRIC', NULL, Load_PRIC, NULL, CH_RIFF | CH_AUTO_LENGTH},
+ { 'CAPR', NULL, Load_CAPR, NULL, CH_RIFF | CH_AUTO_LENGTH},
{ 'ECMY', Save_ECMY, Load_ECMY, NULL, CH_RIFF | CH_LAST},
};
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index 245c126cb..5a50ac79a 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -669,76 +669,6 @@ static bool LoadOldDepot(LoadgameState *ls, int num)
return true;
}
-static int32 _old_price;
-static uint16 _old_price_frac;
-static const OldChunks price_chunk[] = {
- OCL_VAR ( OC_INT32, 1, &_old_price ),
- OCL_VAR ( OC_UINT16, 1, &_old_price_frac ),
- OCL_END()
-};
-
-static bool LoadOldPrice(LoadgameState *ls, int num)
-{
- if (_savegame_type == SGT_TTO && num == 25) {
- /* clear_fields == build_road_depot (TTO didn't have this price) */
- ((Money*)&_price)[25] = ((Money*)&_price)[6];
- _price_frac[25] = _price_frac[6];
- return true;
- }
-
- if (!LoadChunk(ls, NULL, price_chunk)) return false;
-
- if (_savegame_type == SGT_TTO) {
- /* base prices are different in these two cases */
- if (num == 15) _old_price = ClampToI32(((Money)_old_price) * 20 / 3); // build_railvehicle
- if (num == 17) _old_price = ClampToI32(((Money)_old_price) * 10); // aircraft_base
- }
-
-
- /* We use a struct to store the prices, but they are ints in a row..
- * so just access the struct as an array of int32s */
- ((Money*)&_price)[num] = _old_price;
- _price_frac[num] = _old_price_frac;
-
- return true;
-}
-
-static const OldChunks cargo_payment_rate_chunk[] = {
- OCL_VAR ( OC_INT32, 1, &_old_price ),
- OCL_VAR ( OC_UINT16, 1, &_old_price_frac ),
-
- OCL_NULL( 2 ), ///< Junk
- OCL_END()
-};
-
-static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num)
-{
- if (_savegame_type == SGT_TTO && num == 11) { // TTD has 1 more cargo type
- _cargo_payment_rates[num] = _cargo_payment_rates[9];
- _cargo_payment_rates_frac[num] = _cargo_payment_rates_frac[9];
- return true;
- }
-
- if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk)) return false;
-
- if (_savegame_type == SGT_TTO) {
- /* SVXConverter about cargo payment rates correction:
- * "increase them to compensate for the faster time advance in TTD compared to TTO
- * which otherwise would cause much less income while the annual running costs of
- * the vehicles stay the same" */
-
- Money m = ((((Money)_old_price) << 16) + (uint)_old_price_frac) * 124 / 74;
-
- _old_price = m >> 16;
- _old_price_frac = GB((int64)m, 0, 16);
- }
-
- _cargo_payment_rates[num] = -_old_price;
- _cargo_payment_rates_frac[num] = _old_price_frac;
-
- return true;
-}
-
static StationID _current_station_id;
static uint16 _waiting_acceptance;
static uint8 _cargo_source;
@@ -1670,11 +1600,13 @@ static const OldChunks main_chunk[] = {
OCL_ASSERT( OC_TTO, 0x3A2E ),
- OCL_CHUNK( 49, LoadOldPrice ),
+ OCL_CNULL( OC_TTO, 48 * 6 ), ///< prices
+ OCL_CNULL( OC_TTD, 49 * 6 ), ///< prices
OCL_ASSERT( OC_TTO, 0x3B4E ),
- OCL_CHUNK( 12, LoadOldCargoPaymentRate ),
+ OCL_CNULL( OC_TTO, 11 * 8 ), ///< cargo payment rates
+ OCL_CNULL( OC_TTD, 12 * 8 ), ///< cargo payment rates
OCL_ASSERT( OC_TTD, 0x4CBA ),
OCL_ASSERT( OC_TTO, 0x3BA6 ),
@@ -1735,19 +1667,19 @@ static const OldChunks main_chunk[] = {
OCL_VAR ( OC_FILE_I16 | OC_VAR_I32, 1, &_saved_scrollpos_y ),
OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_saved_scrollpos_zoom ),
- OCL_VAR ( OC_FILE_U32 | OC_VAR_I64, 1, &_economy.max_loan ),
- OCL_VAR ( OC_FILE_U32 | OC_VAR_I64, 1, &_economy.max_loan_unround ),
+ OCL_NULL( 4 ), ///< max_loan
+ OCL_VAR ( OC_FILE_U32 | OC_VAR_I64, 1, &_economy.old_max_loan_unround ),
OCL_VAR ( OC_INT16, 1, &_economy.fluct ),
OCL_VAR ( OC_UINT16, 1, &_disaster_delay ),
OCL_ASSERT( OC_TTO, 0x496E4 ),
- OCL_CNULL( OC_TTD, 144 ), ///< cargo-stuff, calculated in InitializeLandscapeVariables
+ OCL_CNULL( OC_TTD, 144 ), ///< cargo-stuff
OCL_CCHUNK( OC_TTD, 256, LoadOldEngineName ),
- OCL_CNULL( OC_TTD, 144 ), ///< AI cargo-stuff, calculated in InitializeLandscapeVariables
+ OCL_CNULL( OC_TTD, 144 ), ///< AI cargo-stuff
OCL_NULL( 2 ), ///< Company indexes of companies, no longer in use
OCL_NULL( 1 ), ///< Station tick counter, no longer in use
@@ -1778,7 +1710,7 @@ static const OldChunks main_chunk[] = {
OCL_VAR ( OC_TTD | OC_UINT8, 1, &_settings_game.game_creation.snow_line ),
OCL_CNULL( OC_TTD, 32 ), ///< new_industry_randtable, no longer used (because of new design)
- OCL_CNULL( OC_TTD, 36 ), ///< cargo-stuff, calculated in InitializeLandscapeVariables
+ OCL_CNULL( OC_TTD, 36 ), ///< cargo-stuff
OCL_ASSERT( OC_TTD, 0x77179 ),
OCL_ASSERT( OC_TTO, 0x4971D ),
@@ -1865,6 +1797,12 @@ bool LoadTTOMain(LoadgameState *ls)
/* We have a new difficulty setting */
_settings_game.difficulty.town_council_tolerance = Clamp(_settings_game.difficulty.diff_level, 0, 2);
+ /* SVXConverter about cargo payment rates correction:
+ * "increase them to compensate for the faster time advance in TTD compared to TTO
+ * which otherwise would cause much less income while the annual running costs of
+ * the vehicles stay the same" */
+ _economy.inflation_payment = min(_economy.inflation_payment * 124 / 74, MAX_INFLATION);
+
DEBUG(oldloader, 3, "Finished converting game data");
DEBUG(oldloader, 1, "TTO savegame successfully converted");
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 65a1d2e8e..0fd7a2561 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -48,7 +48,7 @@
#include "saveload_internal.h"
-extern const uint16 SAVEGAME_VERSION = 125;
+extern const uint16 SAVEGAME_VERSION = 126;
SavegameType _savegame_type; ///< type of savegame we are loading