OpenTTD Source 20260711-master-g3fb3006dff
subsidy_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
9
10#include "../stdafx.h"
11
12#include "saveload.h"
14
15#include "../subsidy_base.h"
16
17#include "../safeguards.h"
18
19static const SaveLoad _subsidies_desc[] = {
20 SLE_VAR(Subsidy, cargo_type, VarTypes::U8),
30};
31
32struct SUBSChunkHandler : ChunkHandler {
33 SUBSChunkHandler() : ChunkHandler('SUBS', ChunkType::Table) {}
34
35 void Save() const override
36 {
37 SlTableHeader(_subsidies_desc);
38
39 for (Subsidy *s : Subsidy::Iterate()) {
40 SlSetArrayIndex(s->index);
41 SlObject(s, _subsidies_desc);
42 }
43 }
44
45 void Load() const override
46 {
47 const std::vector<SaveLoad> slt = SlCompatTableHeader(_subsidies_desc, _subsidies_sl_compat);
48
49 int index;
50 while ((index = SlIterateArray()) != -1) {
52 SlObject(s, slt);
53 }
54 }
55};
56
57static const SUBSChunkHandler SUBS;
58static const ChunkHandlerRef subsidy_chunk_handlers[] = {
59 SUBS,
60};
61
62extern const ChunkHandlerTable _subsidy_chunk_handlers(subsidy_chunk_handlers);
A number of safeguards to prevent using unsafe methods.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:734
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Functions/types related to saving and loading games.
@ U16
A 16 bit unsigned int.
Definition saveload.h:682
@ U8
A 8 bit unsigned int.
Definition saveload.h:662
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:530
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:533
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:904
@ BigMap
Saveload version: 5.0, SVN revision: 1429 Making maps a different size than 256x256.
Definition saveload.h:44
@ RemoveSubsidyStationBinding
Saveload version: 125, SVN revision: 17113 Awarded subsidies are not bound to stations,...
Definition saveload.h:194
@ MinVersion
First savegame version.
Definition saveload.h:31
@ CustomSubsidyDuration
Saveload version: 292, GitHub pull request: 9081 Configurable subsidy duration.
Definition saveload.h:330
@ MaxVersion
Highest possible saveload version.
Definition saveload.h:421
@ Table
An Array with a header describing the elements.
Definition saveload.h:475
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1017
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:915
Definition of base types and functions in a cross-platform compatible way.
static Pool::IterateWrapper< Subsidy > Iterate(size_t from=0)
static T * CreateAtIndex(SubsidyID index, Targs &&... args)
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
SaveLoad type struct.
Definition saveload.h:787
Struct about subsidies, offered and awarded.
static constexpr VarType U16
Store a 16 bits unsigned int.
Definition saveload.h:754
static constexpr VarType U8
Store a 8 bits unsigned int.
Definition saveload.h:752
Subsidy base class.
Loading of subsidy chunks before table headers were added.
const SaveLoadCompat _subsidies_sl_compat[]
Original field order for _subsidies_desc.
PoolID< uint16_t, struct SubsidyIDTag, 256, 0xFFFF > SubsidyID
ID of a subsidy.