OpenTTD: src/saveload/economy_sl.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

economy_sl.cpp
Go to the documentation of this file.
1 /* $Id: economy_sl.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
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(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 {
32 uint num_cargo = IsSavegameVersionBefore(55) ? 12 : NUM_CARGO;
33 int vt = IsSavegameVersionBefore(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, 0, 64), // max_loan
40 SLE_CONDNULL(8, 65, 143), // max_loan
41 SLE_CONDVAR(Economy, old_max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
42 SLE_CONDVAR(Economy, old_max_loan_unround, SLE_INT64, 65, 125),
43 SLE_CONDVAR(Economy, old_max_loan_unround_fract, SLE_UINT16, 70, 125),
44 SLE_CONDVAR(Economy, inflation_prices, SLE_UINT64, 126, SL_MAX_VERSION),
45 SLE_CONDVAR(Economy, inflation_payment, SLE_UINT64, 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, 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(102)); // old savegames will need to be initialized
65 }
66
67 static const SaveLoad _cargopayment_desc[] = {
68 SLE_REF(CargoPayment, front, REF_VEHICLE),
69 SLE_VAR(CargoPayment, route_profit, SLE_INT64),
70 SLE_VAR(CargoPayment, visual_profit, SLE_INT64),
71 SLE_CONDVAR(CargoPayment, visual_transfer, SLE_INT64, 181, SL_MAX_VERSION),
72 SLE_END()
73 };
74
75 static void Save_CAPY()
76 {
77 CargoPayment *cp;
78 FOR_ALL_CARGO_PAYMENTS(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;
97 FOR_ALL_CARGO_PAYMENTS(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 };