OpenTTD Source 20250205-master-gfd85ab1e2c
labelmaps_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"
14
15#include "saveload_internal.h"
16#include "../rail.h"
17#include "../road.h"
18#include "../newgrf_railtype.h"
19#include "../newgrf_roadtype.h"
20
21#include "../safeguards.h"
22
23extern std::vector<LabelObject<RailTypeLabel>> _railtype_list;
24extern std::vector<LabelObject<RoadTypeLabel>> _roadtype_list;
25
35
37 RAILChunkHandler() : ChunkHandler('RAIL', CH_TABLE) {}
38
39 static inline const SaveLoad description[] = {
40 SLE_VAR(LabelObject<RailTypeLabel>, label, SLE_UINT32),
41 };
42
43 void Save() const override
44 {
45 SlTableHeader(description);
46
48 for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
50
51 SlSetArrayIndex(r);
52 SlObject(&lo, description);
53 }
54 }
55
56 void Load() const override
57 {
58 const std::vector<SaveLoad> slt = SlCompatTableHeader(description, _label_object_sl_compat);
59
60 _railtype_list.reserve(RAILTYPE_END);
61
63
64 while (SlIterateArray() != -1) {
65 SlObject(&lo, slt);
66 _railtype_list.push_back(lo);
67 }
68 }
69};
70
72 ROTTChunkHandler() : ChunkHandler('ROTT', CH_TABLE) {}
73
74 static inline const SaveLoad description[] = {
75 SLE_VAR(LabelObject<RoadTypeLabel>, label, SLE_UINT32),
76 SLE_VAR(LabelObject<RoadTypeLabel>, subtype, SLE_UINT8),
77 };
78
79 void Save() const override
80 {
81 SlTableHeader(description);
82
84 for (RoadType r = ROADTYPE_BEGIN; r != ROADTYPE_END; r++) {
85 const RoadTypeInfo *rti = GetRoadTypeInfo(r);
86 lo.label = rti->label;
87 lo.subtype = GetRoadTramType(r);
88
89 SlSetArrayIndex(r);
90 SlObject(&lo, description);
91 }
92 }
93
94 void Load() const override
95 {
96 const std::vector<SaveLoad> slt = SlCompatTableHeader(description, _label_object_sl_compat);
97
98 _roadtype_list.reserve(ROADTYPE_END);
99
101
102 while (SlIterateArray() != -1) {
103 SlObject(&lo, slt);
104 _roadtype_list.push_back(lo);
105 }
106 }
107};
108
109static const RAILChunkHandler RAIL;
110static const ROTTChunkHandler ROTT;
111
112static const ChunkHandlerRef labelmaps_chunk_handlers[] = {
113 RAIL,
114 ROTT,
115};
116
117extern const ChunkHandlerTable _labelmaps_chunk_handlers(labelmaps_chunk_handlers);
118
RailTypeLabel label
Unique 32 bit rail type identifier.
Definition rail.h:226
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition road.h:137
void AfterLoadLabelMaps()
Perform rail type and road type conversion if necessary.
Loading of labelmaps chunks before table headers were added.
const SaveLoadCompat _label_object_sl_compat[]
Original field order for _label_object_desc.
void ConvertRailTypes()
Test if any saved rail type labels are different to the currently loaded rail types.
void SetCurrentRailTypeLabelList()
Populate railtype label list with current values.
void SetCurrentRoadTypeLabelList()
Populate road type label list with current values.
void ConvertRoadTypes()
Test if any saved road type labels are different to the currently loaded road types.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:297
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:27
@ RAILTYPE_BEGIN
Used for iterations.
Definition rail_type.h:28
@ RAILTYPE_END
Used for iterations.
Definition rail_type.h:33
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
RoadType
The different roadtypes we support.
Definition road_type.h:25
@ ROADTYPE_END
Used for iterations.
Definition road_type.h:29
@ ROADTYPE_BEGIN
Used for iterations.
Definition road_type.h:26
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:662
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.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:510
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:513
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1003
Declaration of functions used in more save/load files.
Handlers and description of chunk.
Definition saveload.h:464
Container for a label for rail or road type conversion.
uint8_t subtype
Subtype of type (road or tram).
T label
Label of rail or road type.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
SaveLoad type struct.
Definition saveload.h:718