Update: Translations from eints
[openttd-github.git] / src / saveload / economy_sl.cpp
blobfcccebbcf2f5cef88aa013743f3bf726c8066403
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file economy_sl.cpp Code handling saving and loading of economy data */
10 #include "../stdafx.h"
12 #include "saveload.h"
13 #include "compat/economy_sl_compat.h"
15 #include "../economy_func.h"
16 #include "../economy_base.h"
18 #include "../safeguards.h"
20 /** Prices in pre 126 savegames */
21 struct PRICChunkHandler : ChunkHandler {
22 PRICChunkHandler() : ChunkHandler('PRIC', CH_READONLY) {}
24 void Load() const override
26 /* Old games store 49 base prices, very old games store them as int32_t */
27 int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
28 SlCopy(nullptr, 49, vt | SLE_VAR_NULL);
29 SlCopy(nullptr, 49, SLE_FILE_U16 | SLE_VAR_NULL);
33 /** Cargo payment rates in pre 126 savegames */
34 struct CAPRChunkHandler : ChunkHandler {
35 CAPRChunkHandler() : ChunkHandler('CAPR', CH_READONLY) {}
37 void Load() const override
39 uint num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
40 int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
41 SlCopy(nullptr, num_cargo, vt | SLE_VAR_NULL);
42 SlCopy(nullptr, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
46 static const SaveLoad _economy_desc[] = {
47 SLE_CONDVAR(Economy, old_max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
48 SLE_CONDVAR(Economy, old_max_loan_unround, SLE_INT64, SLV_65, SLV_126),
49 SLE_CONDVAR(Economy, old_max_loan_unround_fract, SLE_UINT16, SLV_70, SLV_126),
50 SLE_CONDVAR(Economy, inflation_prices, SLE_UINT64, SLV_126, SL_MAX_VERSION),
51 SLE_CONDVAR(Economy, inflation_payment, SLE_UINT64, SLV_126, SL_MAX_VERSION),
52 SLE_VAR(Economy, fluct, SLE_INT16),
53 SLE_VAR(Economy, interest_rate, SLE_UINT8),
54 SLE_VAR(Economy, infl_amount, SLE_UINT8),
55 SLE_VAR(Economy, infl_amount_pr, SLE_UINT8),
56 SLE_CONDVAR(Economy, industry_daily_change_counter, SLE_UINT32, SLV_102, SL_MAX_VERSION),
59 /** Economy variables */
60 struct ECMYChunkHandler : ChunkHandler {
61 ECMYChunkHandler() : ChunkHandler('ECMY', CH_TABLE) {}
63 void Save() const override
65 SlTableHeader(_economy_desc);
67 SlSetArrayIndex(0);
68 SlObject(&_economy, _economy_desc);
72 void Load() const override
74 const std::vector<SaveLoad> slt = SlCompatTableHeader(_economy_desc, _economy_sl_compat);
76 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
77 SlObject(&_economy, slt);
78 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many ECMY entries");
80 StartupIndustryDailyChanges(IsSavegameVersionBefore(SLV_102)); // old savegames will need to be initialized
84 static const SaveLoad _cargopayment_desc[] = {
85 SLE_REF(CargoPayment, front, REF_VEHICLE),
86 SLE_VAR(CargoPayment, route_profit, SLE_INT64),
87 SLE_VAR(CargoPayment, visual_profit, SLE_INT64),
88 SLE_CONDVAR(CargoPayment, visual_transfer, SLE_INT64, SLV_181, SL_MAX_VERSION),
91 struct CAPYChunkHandler : ChunkHandler {
92 CAPYChunkHandler() : ChunkHandler('CAPY', CH_TABLE) {}
94 void Save() const override
96 SlTableHeader(_cargopayment_desc);
98 for (CargoPayment *cp : CargoPayment::Iterate()) {
99 SlSetArrayIndex(cp->index);
100 SlObject(cp, _cargopayment_desc);
104 void Load() const override
106 const std::vector<SaveLoad> slt = SlCompatTableHeader(_cargopayment_desc, _cargopayment_sl_compat);
108 int index;
110 while ((index = SlIterateArray()) != -1) {
111 CargoPayment *cp = new (index) CargoPayment();
112 SlObject(cp, slt);
116 void FixPointers() const override
118 for (CargoPayment *cp : CargoPayment::Iterate()) {
119 SlObject(cp, _cargopayment_desc);
124 static const CAPYChunkHandler CAPY;
125 static const PRICChunkHandler PRIC;
126 static const CAPRChunkHandler CAPR;
127 static const ECMYChunkHandler ECMY;
128 static const ChunkHandlerRef economy_chunk_handlers[] = {
129 CAPY,
130 PRIC,
131 CAPR,
132 ECMY,
135 extern const ChunkHandlerTable _economy_chunk_handlers(economy_chunk_handlers);