OpenTTD Source 20260711-master-g3fb3006dff
league_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"
13
14#include "../league_base.h"
15
16#include "../safeguards.h"
17
18static const SaveLoad _league_table_elements_desc[] = {
27};
28
29struct LEAEChunkHandler : ChunkHandler {
30 LEAEChunkHandler() : ChunkHandler('LEAE', ChunkType::Table) {}
31
32 void Save() const override
33 {
34 SlTableHeader(_league_table_elements_desc);
35
37 SlSetArrayIndex(lte->index);
38 SlObject(lte, _league_table_elements_desc);
39 }
40 }
41
42 void Load() const override
43 {
44 const std::vector<SaveLoad> slt = SlTableHeader(_league_table_elements_desc);
45
46 int index;
47 while ((index = SlIterateArray()) != -1) {
49 SlObject(lte, slt);
50 }
51 }
52};
53
54static const SaveLoad _league_tables_desc[] = {
58};
59
60struct LEATChunkHandler : ChunkHandler {
61 LEATChunkHandler() : ChunkHandler('LEAT', ChunkType::Table) {}
62
63 void Save() const override
64 {
65 SlTableHeader(_league_tables_desc);
66
67 for (LeagueTable *lt : LeagueTable::Iterate()) {
68 SlSetArrayIndex(lt->index);
69 SlObject(lt, _league_tables_desc);
70 }
71 }
72
73 void Load() const override
74 {
75 const std::vector<SaveLoad> slt = SlTableHeader(_league_tables_desc);
76
77 int index;
78 while ((index = SlIterateArray()) != -1) {
80 SlObject(lt, slt);
81 }
82 }
83};
84
85static const LEAEChunkHandler LEAE;
86static const LEATChunkHandler LEAT;
87static const ChunkHandlerRef league_chunk_handlers[] = {
88 LEAE,
89 LEAT,
90};
91
92extern const ChunkHandlerTable _league_chunk_handlers(league_chunk_handlers);
LeagueTable base class.
PoolID< uint16_t, struct LeagueTableElementIDTag, 64000, 0xFFFF > LeagueTableElementID
ID of a league table.
Definition league_type.h:38
PoolID< uint8_t, struct LeagueTableIDTag, 255, 0xFF > LeagueTableID
ID of a league table.
Definition league_type.h:35
A number of safeguards to prevent using unsafe methods.
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.
@ I64
A 64 bit signed int.
Definition saveload.h:685
@ U64
A 64 bit unsigned int.
Definition saveload.h:668
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
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
Definition saveload.h:1061
@ LinkgraphEdges
Saveload version: 304, GitHub pull request: 10314 Explicitly store link graph edges destination,...
Definition saveload.h:344
@ MinVersion
First savegame version.
Definition saveload.h:31
@ 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
Definition of base types and functions in a cross-platform compatible way.
@ AllowControlCode
Allow the special control codes.
Definition string_type.h:47
void Load() const override
Load the chunk.
Definition league_sl.cpp:42
void Save() const override
Save the chunk.
Definition league_sl.cpp:32
void Load() const override
Load the chunk.
Definition league_sl.cpp:73
void Save() const override
Save the chunk.
Definition league_sl.cpp:63
Struct about league table elements.
Definition league_base.h:32
Struct about custom league tables.
Definition league_base.h:52
static Pool::IterateWrapper< LeagueTableElement > Iterate(size_t from=0)
static T * CreateAtIndex(LeagueTableElementID index, Targs &&... args)
SaveLoad type struct.
Definition saveload.h:787
static constexpr VarType U8
Store a 8 bits unsigned int.
Definition saveload.h:752
static constexpr VarType STR
Store string.
Definition saveload.h:760
static constexpr VarType I64
Store a 64 bits signed int.
Definition saveload.h:757
static constexpr VarType U32
Store a 32 bits unsigned int.
Definition saveload.h:756