OpenTTD
economy_sl.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "../stdafx.h"
13 #include "../economy_func.h"
14 #include "../economy_base.h"
15 
16 #include "saveload.h"
17 
18 #include "../safeguards.h"
19 
21 static void Load_PRIC()
22 {
23  /* Old games store 49 base prices, very old games store them as int32 */
24  int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
25  SlArray(NULL, 49, vt | SLE_VAR_NULL);
26  SlArray(NULL, 49, SLE_FILE_U16 | SLE_VAR_NULL);
27 }
28 
30 static void Load_CAPR()
31 {
33  int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
34  SlArray(NULL, num_cargo, vt | SLE_VAR_NULL);
35  SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
36 }
37 
38 static const SaveLoad _economy_desc[] = {
39  SLE_CONDNULL(4, SL_MIN_VERSION, SLV_65), // max_loan
40  SLE_CONDNULL(8, SLV_65, SLV_144), // max_loan
41  SLE_CONDVAR(Economy, old_max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
42  SLE_CONDVAR(Economy, old_max_loan_unround, SLE_INT64, SLV_65, SLV_126),
43  SLE_CONDVAR(Economy, old_max_loan_unround_fract, SLE_UINT16, SLV_70, SLV_126),
44  SLE_CONDVAR(Economy, inflation_prices, SLE_UINT64, SLV_126, SL_MAX_VERSION),
45  SLE_CONDVAR(Economy, inflation_payment, SLE_UINT64, SLV_126, SL_MAX_VERSION),
46  SLE_VAR(Economy, fluct, SLE_INT16),
47  SLE_VAR(Economy, interest_rate, SLE_UINT8),
48  SLE_VAR(Economy, infl_amount, SLE_UINT8),
49  SLE_VAR(Economy, infl_amount_pr, SLE_UINT8),
50  SLE_CONDVAR(Economy, industry_daily_change_counter, SLE_UINT32, SLV_102, SL_MAX_VERSION),
51  SLE_END()
52 };
53 
55 static void Save_ECMY()
56 {
57  SlObject(&_economy, _economy_desc);
58 }
59 
61 static void Load_ECMY()
62 {
63  SlObject(&_economy, _economy_desc);
64  StartupIndustryDailyChanges(IsSavegameVersionBefore(SLV_102)); // old savegames will need to be initialized
65 }
66 
67 static const SaveLoad _cargopayment_desc[] = {
69  SLE_VAR(CargoPayment, route_profit, SLE_INT64),
70  SLE_VAR(CargoPayment, visual_profit, SLE_INT64),
71  SLE_CONDVAR(CargoPayment, visual_transfer, SLE_INT64, SLV_181, SL_MAX_VERSION),
72  SLE_END()
73 };
74 
75 static void Save_CAPY()
76 {
77  CargoPayment *cp;
79  SlSetArrayIndex(cp->index);
80  SlObject(cp, _cargopayment_desc);
81  }
82 }
83 
84 static void Load_CAPY()
85 {
86  int index;
87 
88  while ((index = SlIterateArray()) != -1) {
89  CargoPayment *cp = new (index) CargoPayment();
90  SlObject(cp, _cargopayment_desc);
91  }
92 }
93 
94 static void Ptrs_CAPY()
95 {
96  CargoPayment *cp;
98  SlObject(cp, _cargopayment_desc);
99  }
100 }
101 
102 
103 extern const ChunkHandler _economy_chunk_handlers[] = {
104  { 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, NULL, CH_ARRAY},
105  { 'PRIC', NULL, Load_PRIC, NULL, NULL, CH_RIFF | CH_AUTO_LENGTH},
106  { 'CAPR', NULL, Load_CAPR, NULL, NULL, CH_RIFF | CH_AUTO_LENGTH},
107  { 'ECMY', Save_ECMY, Load_ECMY, NULL, NULL, CH_RIFF | CH_LAST},
108 };
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:632
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:753
70 10541
Definition: saveload.h:128
static void Load_ECMY()
Economy variables.
Definition: economy_sl.cpp:61
102 14332
Definition: saveload.h:166
static void Load_CAPR()
Cargo payment rates in pre 126 savegames.
Definition: economy_sl.cpp:30
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:592
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
static void Save_ECMY()
Economy variables.
Definition: economy_sl.cpp:55
#define FOR_ALL_CARGO_PAYMENTS(var)
Iterate over all cargo payments.
Definition: economy_base.h:63
void SlArray(void *array, size_t length, VarType conv)
Save/Load an array.
Definition: saveload.cpp:992
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:524
Highest possible saveload version.
Definition: saveload.h:295
First savegame version.
Definition: saveload.h:32
55 9638
Definition: saveload.h:110
Helper class to perform the cargo payment.
Definition: economy_base.h:26
Data of the economy.
Definition: economy_type.h:21
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:634
Load/save a reference to a vehicle.
Definition: saveload.h:362
Handlers and description of chunk.
Definition: saveload.h:346
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:641
144 20334
Definition: saveload.h:216
181 25012
Definition: saveload.h:261
useful to write zeros in savegame.
Definition: saveload.h:417
static void Load_PRIC()
Prices in pre 126 savegames.
Definition: economy_sl.cpp:21
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1543
65 10210
Definition: saveload.h:122
void StartupIndustryDailyChanges(bool init_counter)
Initialize the variables that will maintain the daily industry change system.
Definition: economy.cpp:917
SaveLoad type struct.
Definition: saveload.h:486
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:584
199 PR#6802 Extend cargotypes to 64
Definition: saveload.h:283
126 17433
Definition: saveload.h:195
Last chunk in this array.
Definition: saveload.h:381