OpenTTD Source 20241224-master-gf74b0cf984
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 <http://www.gnu.org/licenses/>.
6 */
7
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[] = {
19 SLE_VAR(LeagueTableElement, table, SLE_UINT8),
20 SLE_CONDVAR(LeagueTableElement, rating, SLE_FILE_U64 | SLE_VAR_I64, SL_MIN_VERSION, SLV_LINKGRAPH_EDGES),
22 SLE_VAR(LeagueTableElement, company, SLE_UINT8),
25 SLE_VAR(LeagueTableElement, link.type, SLE_UINT8),
26 SLE_VAR(LeagueTableElement, link.target, SLE_UINT32),
27};
28
30 LEAEChunkHandler() : ChunkHandler('LEAE', CH_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) {
48 LeagueTableElement *lte = new (index) LeagueTableElement();
49 SlObject(lte, slt);
50 }
51 }
52};
53
54static const SaveLoad _league_tables_desc[] = {
55 SLE_SSTR(LeagueTable, title, SLE_STR | SLF_ALLOW_CONTROL),
56 SLE_SSTR(LeagueTable, header, SLE_STR | SLF_ALLOW_CONTROL),
57 SLE_SSTR(LeagueTable, footer, SLE_STR | SLF_ALLOW_CONTROL),
58};
59
61 LEATChunkHandler() : ChunkHandler('LEAT', CH_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) {
79 LeagueTable *lt = new (index) LeagueTable();
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);
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:659
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.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition saveload.h:688
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:509
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:512
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:868
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
Definition saveload.h:1046
@ SLV_LINKGRAPH_EDGES
304 PR#10314 Explicitly store link graph edges destination, PR#10471 int64_t instead of uint64_t leag...
Definition saveload.h:344
@ SL_MAX_VERSION
Highest possible saveload version.
Definition saveload.h:399
@ SL_MIN_VERSION
First savegame version.
Definition saveload.h:31
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1002
Handlers and description of chunk.
Definition saveload.h:463
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:31
Struct about custom league tables.
Definition league_base.h:52
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
SaveLoad type struct.
Definition saveload.h:717