OpenTTD Source: src/saveload/industry_sl.cpp Source File

OpenTTD Source 15.3

industry_sl.cpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "../stdafx.h"
11
12#include "saveload.h"
13#include "compat/industry_sl_compat.h"
14
15#include "../industry.h"
16#include "newgrf_sl.h"
17
18#include "../safeguards.h"
19
20static OldPersistentStorage _old_ind_persistent_storage;
21
22 class SlIndustryAcceptedHistory : public DefaultSaveLoadHandler<SlIndustryAcceptedHistory, Industry::AcceptedCargo> {
23public:
24 static inline const SaveLoad description[] = {
25 SLE_VAR(Industry::AcceptedHistory, accepted, SLE_UINT16),
26 SLE_VAR(Industry::AcceptedHistory, waiting, SLE_UINT16),
27 };
28 static inline const SaveLoadCompatTable compat_description = _industry_produced_history_sl_compat;
29
30 void Save(Industry::AcceptedCargo *a) const override
31 {
32 if (!IsValidCargoType(a->cargo) || a->history == nullptr) {
33 /* Don't save any history if cargo slot isn't used. */
34 SlSetStructListLength(0);
35 return;
36 }
37
38 SlSetStructListLength(a->history->size());
39
40 for (auto &h : *a->history) {
41 SlObject(&h, this->GetDescription());
42 }
43 }
44
45 void Load(Industry::AcceptedCargo *a) const override
46 {
47 size_t len = SlGetStructListLength(UINT32_MAX);
48 if (len == 0) return;
49
50 auto &history = a->GetOrCreateHistory();
51 for (auto &h : history) {
52 if (--len > history.size()) break; // unsigned so wraps after hitting zero.
53 SlObject(&h, this->GetLoadDescription());
54 }
55 }
56};
57
58 class SlIndustryAccepted : public VectorSaveLoadHandler<SlIndustryAccepted, Industry, Industry::AcceptedCargo, INDUSTRY_NUM_INPUTS> {
59public:
60 static inline const SaveLoad description[] = {
61 SLE_VAR(Industry::AcceptedCargo, cargo, SLE_UINT8),
62 SLE_VAR(Industry::AcceptedCargo, waiting, SLE_UINT16),
63 SLE_VAR(Industry::AcceptedCargo, last_accepted, SLE_INT32),
64 SLE_CONDVAR(Industry::AcceptedCargo, accumulated_waiting, SLE_UINT32, SLV_INDUSTRY_ACCEPTED_HISTORY, SL_MAX_VERSION),
65 SLEG_CONDSTRUCTLIST("history", SlIndustryAcceptedHistory, SLV_INDUSTRY_ACCEPTED_HISTORY, SL_MAX_VERSION),
66 };
67 static inline const SaveLoadCompatTable compat_description = _industry_accepts_sl_compat;
68
69 std::vector<Industry::AcceptedCargo> &GetVector(Industry *i) const override { return i->accepted; }
70
71 /* Old array structure used by INDYChunkHandler for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
72 static inline std::array<CargoType, INDUSTRY_NUM_INPUTS> old_cargo;
73 static inline std::array<uint16_t, INDUSTRY_NUM_INPUTS> old_waiting;
74 static inline std::array<TimerGameEconomy::Date, INDUSTRY_NUM_INPUTS> old_last_accepted;
75
76 static void ResetOldStructure()
77 {
78 SlIndustryAccepted::old_cargo.fill(INVALID_CARGO);
79 SlIndustryAccepted::old_waiting.fill(0);
80 SlIndustryAccepted::old_last_accepted.fill(TimerGameEconomy::Date{});
81 }
82};
83
84 class SlIndustryProducedHistory : public DefaultSaveLoadHandler<SlIndustryProducedHistory, Industry::ProducedCargo> {
85public:
86 static inline const SaveLoad description[] = {
87 SLE_VAR(Industry::ProducedHistory, production, SLE_UINT16),
88 SLE_VAR(Industry::ProducedHistory, transported, SLE_UINT16),
89 };
90 static inline const SaveLoadCompatTable compat_description = _industry_produced_history_sl_compat;
91
92 void Save(Industry::ProducedCargo *p) const override
93 {
94 if (!IsValidCargoType(p->cargo)) {
95 /* Don't save any history if cargo slot isn't used. */
96 SlSetStructListLength(0);
97 return;
98 }
99
100 SlSetStructListLength(p->history.size());
101
102 for (auto &h : p->history) {
103 SlObject(&h, this->GetDescription());
104 }
105 }
106
107 void Load(Industry::ProducedCargo *p) const override
108 {
109 size_t len = SlGetStructListLength(p->history.size());
110
111 for (auto &h : p->history) {
112 if (--len > p->history.size()) break; // unsigned so wraps after hitting zero.
113 SlObject(&h, this->GetLoadDescription());
114 }
115 }
116};
117
118 class SlIndustryProduced : public VectorSaveLoadHandler<SlIndustryProduced, Industry, Industry::ProducedCargo, INDUSTRY_NUM_OUTPUTS> {
119public:
120 static inline const SaveLoad description[] = {
121 SLE_VAR(Industry::ProducedCargo, cargo, SLE_UINT8),
122 SLE_VAR(Industry::ProducedCargo, waiting, SLE_UINT16),
123 SLE_VAR(Industry::ProducedCargo, rate, SLE_UINT8),
124 SLEG_STRUCTLIST("history", SlIndustryProducedHistory),
125 };
126 static inline const SaveLoadCompatTable compat_description = _industry_produced_sl_compat;
127
128 std::vector<Industry::ProducedCargo> &GetVector(Industry *i) const override { return i->produced; }
129
130 /* Old array structure used by INDYChunkHandler for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
131 static inline std::array<CargoType, INDUSTRY_NUM_OUTPUTS> old_cargo;
132 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_waiting;
133 static inline std::array<uint8_t, INDUSTRY_NUM_OUTPUTS> old_rate;
134 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_this_month_production;
135 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_this_month_transported;
136 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_last_month_production;
137 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_last_month_transported;
138
139 static void ResetOldStructure()
140 {
141 SlIndustryProduced::old_cargo.fill(INVALID_CARGO);
142 SlIndustryProduced::old_waiting.fill(0);
143 SlIndustryProduced::old_rate.fill(0);
144 SlIndustryProduced::old_this_month_production.fill(0);
145 SlIndustryProduced::old_this_month_transported.fill(0);
146 SlIndustryProduced::old_last_month_production.fill(0);
147 SlIndustryProduced::old_this_month_production.fill(0);
148 }
149};
150
151static const SaveLoad _industry_desc[] = {
152 SLE_CONDVAR(Industry, location.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
153 SLE_CONDVAR(Industry, location.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
154 SLE_VAR(Industry, location.w, SLE_FILE_U8 | SLE_VAR_U16),
155 SLE_VAR(Industry, location.h, SLE_FILE_U8 | SLE_VAR_U16),
156 SLE_REF(Industry, town, REF_TOWN),
157 SLE_CONDREF(Industry, neutral_station, REF_STATION, SLV_SERVE_NEUTRAL_INDUSTRIES, SL_MAX_VERSION),
158 SLEG_CONDARR("produced_cargo", SlIndustryProduced::old_cargo, SLE_UINT8, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
159 SLEG_CONDARR("produced_cargo", SlIndustryProduced::old_cargo, SLE_UINT8, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
160 SLEG_CONDARR("incoming_cargo_waiting", SlIndustryAccepted::old_waiting, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_INPUTS, SLV_70, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
161 SLEG_CONDARR("incoming_cargo_waiting", SlIndustryAccepted::old_waiting, SLE_UINT16, INDUSTRY_NUM_INPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
162 SLEG_CONDARR("produced_cargo_waiting", SlIndustryProduced::old_waiting, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
163 SLEG_CONDARR("produced_cargo_waiting", SlIndustryProduced::old_waiting, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
164 SLEG_CONDARR("production_rate", SlIndustryProduced::old_rate, SLE_UINT8, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
165 SLEG_CONDARR("production_rate", SlIndustryProduced::old_rate, SLE_UINT8, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
166 SLEG_CONDARR("accepts_cargo", SlIndustryAccepted::old_cargo, SLE_UINT8, INDUSTRY_ORIGINAL_NUM_INPUTS, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
167 SLEG_CONDARR("accepts_cargo", SlIndustryAccepted::old_cargo, SLE_UINT8, INDUSTRY_NUM_INPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
168 SLE_VAR(Industry, prod_level, SLE_UINT8),
169 SLEG_CONDARR("this_month_production", SlIndustryProduced::old_this_month_production, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
170 SLEG_CONDARR("this_month_production", SlIndustryProduced::old_this_month_production, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
171 SLEG_CONDARR("this_month_transported", SlIndustryProduced::old_this_month_transported, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
172 SLEG_CONDARR("this_month_transported", SlIndustryProduced::old_this_month_transported, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
173 SLEG_CONDARR("last_month_production", SlIndustryProduced::old_last_month_production, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
174 SLEG_CONDARR("last_month_production", SlIndustryProduced::old_last_month_production, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
175 SLEG_CONDARR("last_month_transported", SlIndustryProduced::old_last_month_transported, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
176 SLEG_CONDARR("last_month_transported", SlIndustryProduced::old_last_month_transported, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
177
178 SLE_VAR(Industry, counter, SLE_UINT16),
179
180 SLE_VAR(Industry, type, SLE_UINT8),
181 SLE_VAR(Industry, owner, SLE_UINT8),
182 SLE_VAR(Industry, random_colour, SLE_UINT8),
183 SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
184 SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
185 SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8),
186 SLE_CONDVAR(Industry, ctlflags, SLE_UINT8, SLV_GS_INDUSTRY_CONTROL, SL_MAX_VERSION),
187
188 SLE_CONDVAR(Industry, founder, SLE_UINT8, SLV_70, SL_MAX_VERSION),
189 SLE_CONDVAR(Industry, construction_date, SLE_INT32, SLV_70, SL_MAX_VERSION),
190 SLE_CONDVAR(Industry, construction_type, SLE_UINT8, SLV_70, SL_MAX_VERSION),
191 SLEG_CONDVAR("last_cargo_accepted_at[0]", SlIndustryAccepted::old_last_accepted[0], SLE_INT32, SLV_70, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
192 SLEG_CONDARR("last_cargo_accepted_at", SlIndustryAccepted::old_last_accepted, SLE_INT32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
193 SLE_CONDVAR(Industry, selected_layout, SLE_UINT8, SLV_73, SL_MAX_VERSION),
194 SLE_CONDVAR(Industry, exclusive_supplier, SLE_UINT8, SLV_GS_INDUSTRY_CONTROL, SL_MAX_VERSION),
195 SLE_CONDVAR(Industry, exclusive_consumer, SLE_UINT8, SLV_GS_INDUSTRY_CONTROL, SL_MAX_VERSION),
196
197 SLEG_CONDARR("storage", _old_ind_persistent_storage.storage, SLE_UINT32, 16, SLV_76, SLV_161),
198 SLE_CONDREF(Industry, psa, REF_STORAGE, SLV_161, SL_MAX_VERSION),
199
200 SLE_CONDVAR(Industry, random, SLE_UINT16, SLV_82, SL_MAX_VERSION),
201 SLE_CONDSSTR(Industry, text, SLE_STR | SLF_ALLOW_CONTROL, SLV_INDUSTRY_TEXT, SL_MAX_VERSION),
202
203 SLE_CONDVAR(Industry, valid_history, SLE_UINT64, SLV_INDUSTRY_NUM_VALID_HISTORY, SL_MAX_VERSION),
204
205 SLEG_CONDSTRUCTLIST("accepted", SlIndustryAccepted, SLV_INDUSTRY_CARGO_REORGANISE, SL_MAX_VERSION),
206 SLEG_CONDSTRUCTLIST("produced", SlIndustryProduced, SLV_INDUSTRY_CARGO_REORGANISE, SL_MAX_VERSION),
207};
208
209 struct INDYChunkHandler : ChunkHandler {
210 INDYChunkHandler() : ChunkHandler('INDY', CH_TABLE) {}
211
212 void Save() const override
213 {
214 SlTableHeader(_industry_desc);
215
216 /* Write the industries */
217 for (Industry *ind : Industry::Iterate()) {
218 SlSetArrayIndex(ind->index);
219 SlObject(ind, _industry_desc);
220 }
221 }
222
223 void LoadMoveAcceptsProduced(Industry *i, uint inputs, uint outputs) const
224 {
225 i->accepted.reserve(inputs);
226 for (uint j = 0; j != inputs; ++j) {
227 auto &a = i->accepted.emplace_back();
228 a.cargo = SlIndustryAccepted::old_cargo[j];
229 a.waiting = SlIndustryAccepted::old_waiting[j];
230 a.last_accepted = SlIndustryAccepted::old_last_accepted[j];
231 }
232
233 i->produced.reserve(outputs);
234 for (uint j = 0; j != outputs; ++j) {
235 auto &p = i->produced.emplace_back();
236 p.cargo = SlIndustryProduced::old_cargo[j];
237 p.waiting = SlIndustryProduced::old_waiting[j];
238 p.rate = SlIndustryProduced::old_rate[j];
239 p.history[THIS_MONTH].production = SlIndustryProduced::old_this_month_production[j];
240 p.history[THIS_MONTH].transported = SlIndustryProduced::old_this_month_transported[j];
241 p.history[LAST_MONTH].production = SlIndustryProduced::old_last_month_production[j];
242 p.history[LAST_MONTH].transported = SlIndustryProduced::old_last_month_transported[j];
243 }
244 }
245
246 void Load() const override
247 {
248 const std::vector<SaveLoad> slt = SlCompatTableHeader(_industry_desc, _industry_sl_compat);
249
250 int index;
251
252 SlIndustryAccepted::ResetOldStructure();
253 SlIndustryProduced::ResetOldStructure();
254
255 while ((index = SlIterateArray()) != -1) {
256 Industry *i = new (IndustryID(index)) Industry();
257 SlObject(i, slt);
258
259 /* Before savegame version 161, persistent storages were not stored in a pool. */
260 if (IsSavegameVersionBefore(SLV_161) && !IsSavegameVersionBefore(SLV_76)) {
261 /* Store the old persistent storage. The GRFID will be added later. */
262 assert(PersistentStorage::CanAllocateItem());
263 i->psa = new PersistentStorage(0, GSF_INVALID, TileIndex{});
264 std::copy(std::begin(_old_ind_persistent_storage.storage), std::end(_old_ind_persistent_storage.storage), std::begin(i->psa->storage));
265 }
266 if (IsSavegameVersionBefore(SLV_EXTEND_INDUSTRY_CARGO_SLOTS)) {
267 LoadMoveAcceptsProduced(i, INDUSTRY_ORIGINAL_NUM_INPUTS, INDUSTRY_ORIGINAL_NUM_OUTPUTS);
268 } else if (IsSavegameVersionBefore(SLV_INDUSTRY_CARGO_REORGANISE)) {
269 LoadMoveAcceptsProduced(i, INDUSTRY_NUM_INPUTS, INDUSTRY_NUM_OUTPUTS);
270 }
271
272 if (IsSavegameVersionBefore(SLV_INDUSTRY_NUM_VALID_HISTORY)) {
273 /* The last month has always been recorded. */
274 size_t oldest_valid = LAST_MONTH;
275 if (!IsSavegameVersionBefore(SLV_PRODUCTION_HISTORY)) {
276 /* History was extended but we did not keep track of valid history, so assume it from the oldest non-zero value. */
277 for (const auto &p : i->produced) {
278 if (!IsValidCargoType(p.cargo)) continue;
279 for (size_t n = LAST_MONTH; n < std::size(p.history); ++n) {
280 if (p.history[n].production == 0 && p.history[n].transported == 0) continue;
281 oldest_valid = std::max(oldest_valid, n);
282 }
283 }
284 }
285 /* Set mask bits up to and including the oldest valid record. */
286 i->valid_history = (std::numeric_limits<uint64_t>::max() >> (std::numeric_limits<uint64_t>::digits - (oldest_valid + 1 - LAST_MONTH))) << LAST_MONTH;
287 }
288
289 Industry::industries[i->type].insert(i->index);
290 }
291 }
292
293 void FixPointers() const override
294 {
295 for (Industry *i : Industry::Iterate()) {
296 SlObject(i, _industry_desc);
297 }
298 }
299};
300
301 struct IIDSChunkHandler : NewGRFMappingChunkHandler {
302 IIDSChunkHandler() : NewGRFMappingChunkHandler('IIDS', _industry_mngr) {}
303};
304
305 struct TIDSChunkHandler : NewGRFMappingChunkHandler {
306 TIDSChunkHandler() : NewGRFMappingChunkHandler('TIDS', _industile_mngr) {}
307};
308
310 static const SaveLoad _industry_builder_desc[] = {
311 SLEG_VAR("wanted_inds", _industry_builder.wanted_inds, SLE_UINT32),
312};
313
315 struct IBLDChunkHandler : ChunkHandler {
316 IBLDChunkHandler() : ChunkHandler('IBLD', CH_TABLE) {}
317
318 void Save() const override
319 {
320 SlTableHeader(_industry_builder_desc);
321
322 SlSetArrayIndex(0);
323 SlGlobList(_industry_builder_desc);
324 }
325
326 void Load() const override
327 {
328 const std::vector<SaveLoad> slt = SlCompatTableHeader(_industry_builder_desc, _industry_builder_sl_compat);
329
330 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
331 SlGlobList(slt);
332 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many IBLD entries");
333 }
334};
335
337 static const SaveLoad _industrytype_builder_desc[] = {
338 SLE_VAR(IndustryTypeBuildData, probability, SLE_UINT32),
339 SLE_VAR(IndustryTypeBuildData, min_number, SLE_UINT8),
340 SLE_VAR(IndustryTypeBuildData, target_count, SLE_UINT16),
341 SLE_VAR(IndustryTypeBuildData, max_wait, SLE_UINT16),
342 SLE_VAR(IndustryTypeBuildData, wait_count, SLE_UINT16),
343};
344
346 struct ITBLChunkHandler : ChunkHandler {
347 ITBLChunkHandler() : ChunkHandler('ITBL', CH_TABLE) {}
348
349 void Save() const override
350 {
351 SlTableHeader(_industrytype_builder_desc);
352
353 for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
354 SlSetArrayIndex(i);
355 SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
356 }
357 }
358
359 void Load() const override
360 {
361 const std::vector<SaveLoad> slt = SlCompatTableHeader(_industrytype_builder_desc, _industrytype_builder_sl_compat);
362
363 for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
364 _industry_builder.builddata[it].Reset();
365 }
366 int index;
367 while ((index = SlIterateArray()) != -1) {
368 if ((uint)index >= NUM_INDUSTRYTYPES) SlErrorCorrupt("Too many industry builder datas");
369 SlObject(_industry_builder.builddata + index, slt);
370 }
371 }
372};
373
374static const INDYChunkHandler INDY;
375static const IIDSChunkHandler IIDS;
376static const TIDSChunkHandler TIDS;
377static const IBLDChunkHandler IBLD;
378static const ITBLChunkHandler ITBL;
379static const ChunkHandlerRef industry_chunk_handlers[] = {
380 INDY,
381 IIDS,
382 TIDS,
383 IBLD,
384 ITBL,
385};
386
387extern const ChunkHandlerTable _industry_chunk_handlers(industry_chunk_handlers);
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition saveload.h:596
DefaultSaveLoadHandler< SlIndustryAcceptedHistory, Industry::AcceptedCargo >::GetDescription
SaveLoadTable GetDescription() const override
Definition saveload.h:598
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition saveload.cpp:3444
SlIndustryAcceptedHistory
Definition industry_sl.cpp:22
SlIndustryAccepted
Definition industry_sl.cpp:58
SlIndustryAccepted::GetVector
std::vector< Industry::AcceptedCargo > & GetVector(Industry *i) const override
Get instance of vector to load/save.
Definition industry_sl.cpp:69
SlIndustryProducedHistory
Definition industry_sl.cpp:84
SlIndustryProduced
Definition industry_sl.cpp:118
SlIndustryProduced::GetVector
std::vector< Industry::ProducedCargo > & GetVector(Industry *i) const override
Get instance of vector to load/save.
Definition industry_sl.cpp:128
VectorSaveLoadHandler
Default handler for saving/loading a vector to/from disk.
Definition saveload.h:1382
_industry_builder
IndustryBuildData _industry_builder
In-game manager of industries.
Definition industry_cmd.cpp:73
_industrytype_builder_desc
static const SaveLoad _industrytype_builder_desc[]
Description of the data to save and load in IndustryTypeBuildData.
Definition industry_sl.cpp:337
_industry_builder_desc
static const SaveLoad _industry_builder_desc[]
Description of the data to save and load in IndustryBuildData.
Definition industry_sl.cpp:310
industry_sl_compat.h
Loading of industry chunks before table headers were added.
_industry_sl_compat
const SaveLoadCompat _industry_sl_compat[]
Original field order for _industry_desc.
Definition industry_sl_compat.h:33
_industry_builder_sl_compat
const SaveLoadCompat _industry_builder_sl_compat[]
Original field order for _industry_builder_desc.
Definition industry_sl_compat.h:77
_industrytype_builder_sl_compat
const SaveLoadCompat _industrytype_builder_sl_compat[]
Original field order for _industrytype_builder_desc.
Definition industry_sl_compat.h:82
INDUSTRY_ORIGINAL_NUM_INPUTS
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
Definition industry_type.h:59
INDUSTRY_NUM_OUTPUTS
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
Definition industry_type.h:58
INDUSTRY_NUM_INPUTS
static const int INDUSTRY_NUM_INPUTS
Number of cargo types an industry can accept.
Definition industry_type.h:57
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like IT_...
Definition industry_type.h:45
INDUSTRY_ORIGINAL_NUM_OUTPUTS
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
Definition industry_type.h:60
GSF_INVALID
@ GSF_INVALID
An invalid spec feature.
Definition newgrf.h:99
newgrf_sl.h
Code handling saving and loading of NewGRF mappings.
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition saveload.cpp:2037
SlGetStructListLength
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
Definition saveload.cpp:1833
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:677
SlErrorCorrupt
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition saveload.cpp:369
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition saveload.cpp:1846
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition saveload.cpp:1899
SlGlobList
void SlGlobList(const SaveLoadTable &slt)
Save or Load (a list of) global variables.
Definition saveload.cpp:2091
SlSetStructListLength
void SlSetStructListLength(size_t length)
Set the length of this list.
Definition saveload.cpp:1817
saveload.h
Functions/types related to saving and loading games.
SLEG_CONDARR
#define SLEG_CONDARR(name, variable, type, length, from, to)
Storage of a global fixed-size array of SL_VAR elements in some savegame versions.
Definition saveload.h:1145
SLEG_STRUCTLIST
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
Definition saveload.h:1256
SLEG_CONDVAR
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition saveload.h:1124
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition saveload.h:702
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:524
REF_TOWN
@ REF_TOWN
Load/save a reference to a town.
Definition saveload.h:618
REF_STATION
@ REF_STATION
Load/save a reference to a station.
Definition saveload.h:617
REF_STORAGE
@ REF_STORAGE
Load/save a reference to a persistent storage.
Definition saveload.h:624
ChunkHandlerTable
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:527
SLEG_VAR
#define SLEG_VAR(name, variable, type)
Storage of a global variable in every savegame version.
Definition saveload.h:1201
SLE_REF
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition saveload.h:1034
SaveLoadCompatTable
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition saveload.h:533
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition saveload.h:948
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:883
IsSavegameVersionBefore
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1278
SLV_INDUSTRY_TEXT
@ SLV_INDUSTRY_TEXT
289 PR#8576 v1.11.0-RC1 Additional GS text for industries.
Definition saveload.h:326
SLV_SERVE_NEUTRAL_INDUSTRIES
@ SLV_SERVE_NEUTRAL_INDUSTRIES
210 PR#7234 Company stations can serve industries with attached neutral stations.
Definition saveload.h:296
SLV_73
@ SLV_73
73 10903
Definition saveload.h:130
SLV_EXTEND_INDUSTRY_CARGO_SLOTS
@ SLV_EXTEND_INDUSTRY_CARGO_SLOTS
202 PR#6867 Increase industry cargo slots to 16 in, 16 out
Definition saveload.h:286
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition saveload.h:46
SLV_INDUSTRY_NUM_VALID_HISTORY
@ SLV_INDUSTRY_NUM_VALID_HISTORY
356 PR#14416 Store number of valid history records for industries.
Definition saveload.h:407
SLV_RIFF_TO_ARRAY
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
Definition saveload.h:332
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition saveload.h:416
SLV_GS_INDUSTRY_CONTROL
@ SLV_GS_INDUSTRY_CONTROL
287 PR#7912 and PR#8115 GS industry control.
Definition saveload.h:324
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition saveload.h:31
SLV_PRODUCTION_HISTORY
@ SLV_PRODUCTION_HISTORY
343 PR#10541 Industry production history.
Definition saveload.h:391
SLV_76
@ SLV_76
76 11139
Definition saveload.h:134
SLV_78
@ SLV_78
78 11176
Definition saveload.h:136
SLV_161
@ SLV_161
161 22567
Definition saveload.h:236
SLV_INDUSTRY_CARGO_REORGANISE
@ SLV_INDUSTRY_CARGO_REORGANISE
315 PR#10853 Industry accepts/produced data reorganised.
Definition saveload.h:358
SLV_INDUSTRY_ACCEPTED_HISTORY
@ SLV_INDUSTRY_ACCEPTED_HISTORY
357 PR#14321 Add per-industry history of cargo delivered and waiting.
Definition saveload.h:408
SLV_82
@ SLV_82
82 11410
Definition saveload.h:141
SLV_70
@ SLV_70
70 10541
Definition saveload.h:127
SLV_31
@ SLV_31
31 5999
Definition saveload.h:80
SLE_CONDREF
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition saveload.h:904
SLEG_CONDSTRUCTLIST
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
Definition saveload.h:1193
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1017
ChunkHandler
Handlers and description of chunk.
Definition saveload.h:478
IBLDChunkHandler
Industry builder.
Definition industry_sl.cpp:315
IBLDChunkHandler::Load
void Load() const override
Load the chunk.
Definition industry_sl.cpp:326
IBLDChunkHandler::Save
void Save() const override
Save the chunk.
Definition industry_sl.cpp:318
IIDSChunkHandler
Definition industry_sl.cpp:301
INDYChunkHandler
Definition industry_sl.cpp:209
INDYChunkHandler::Save
void Save() const override
Save the chunk.
Definition industry_sl.cpp:212
INDYChunkHandler::Load
void Load() const override
Load the chunk.
Definition industry_sl.cpp:246
INDYChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition industry_sl.cpp:293
ITBLChunkHandler
Industry-type build data.
Definition industry_sl.cpp:346
ITBLChunkHandler::Load
void Load() const override
Load the chunk.
Definition industry_sl.cpp:359
ITBLChunkHandler::Save
void Save() const override
Save the chunk.
Definition industry_sl.cpp:349
IndustryBuildData::wanted_inds
uint32_t wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
Definition industry.h:308
IndustryBuildData::builddata
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]
Industry build data for every industry type.
Definition industry.h:307
IndustryTypeBuildData
Data for managing the number of industries of a single industry type.
Definition industry.h:291
IndustryTypeBuildData::Reset
void Reset()
Reset the entry.
Definition industry_cmd.cpp:2426
Industry::AcceptedCargo
Definition industry.h:85
Industry::AcceptedCargo::cargo
CargoType cargo
Cargo type.
Definition industry.h:86
Industry::AcceptedCargo::GetOrCreateHistory
HistoryData< AcceptedHistory > & GetOrCreateHistory()
Get history data, creating it if necessary.
Definition industry.h:96
Industry::AcceptedCargo::history
std::unique_ptr< HistoryData< AcceptedHistory > > history
History of accepted and waiting cargo.
Definition industry.h:90
Industry::AcceptedHistory
Definition industry.h:80
Industry::ProducedCargo
Definition industry.h:73
Industry::ProducedCargo::cargo
CargoType cargo
Cargo type.
Definition industry.h:74
Industry::ProducedCargo::history
HistoryData< ProducedHistory > history
History of cargo produced and transported for this month and 24 previous months.
Definition industry.h:77
Industry::ProducedHistory
Definition industry.h:63
Industry
Defines the internal data of a functional industry.
Definition industry.h:62
Industry::type
IndustryType type
type of industry.
Definition industry.h:115
Industry::psa
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition industry.h:136
Industry::valid_history
ValidHistoryMask valid_history
Mask of valid history records.
Definition industry.h:109
Industry::produced
ProducedCargoes produced
produced cargo slots
Definition industry.h:110
Industry::accepted
AcceptedCargoes accepted
accepted cargo slots
Definition industry.h:111
Industry::industries
static std::array< FlatSet< IndustryID >, NUM_INDUSTRYTYPES > industries
List of industries of each type.
Definition industry.h:276
NewGRFMappingChunkHandler
Definition newgrf_sl.h:16
PersistentStorageArray
Class for persistent storage of data.
Definition newgrf_storage.h:67
PersistentStorageArray::storage
StorageType storage
Memory for the storage array.
Definition newgrf_storage.h:70
PersistentStorage
Class for pooled persistent storage of data.
Definition newgrf_storage.h:199
PoolID
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43
Pool::PoolItem<&_industry_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_persistent_storage_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition pool_type.hpp:357
SaveLoad
SaveLoad type struct.
Definition saveload.h:732
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
TIDSChunkHandler
Definition industry_sl.cpp:305