OpenTTD Source 20241224-master-gf74b0cf984
signs_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 "../signs_base.h"
16#include "../fios.h"
17
18#include "../safeguards.h"
19
21static const SaveLoad _sign_desc[] = {
22 SLE_CONDVAR(Sign, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
24 SLE_CONDVAR(Sign, x, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_5),
25 SLE_CONDVAR(Sign, y, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_5),
26 SLE_CONDVAR(Sign, x, SLE_INT32, SLV_5, SL_MAX_VERSION),
27 SLE_CONDVAR(Sign, y, SLE_INT32, SLV_5, SL_MAX_VERSION),
28 SLE_CONDVAR(Sign, owner, SLE_UINT8, SLV_6, SL_MAX_VERSION),
29 SLE_CONDVAR(Sign, z, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
30 SLE_CONDVAR(Sign, z, SLE_INT32, SLV_164, SL_MAX_VERSION),
31};
32
34 SIGNChunkHandler() : ChunkHandler('SIGN', CH_TABLE) {}
35
36 void Save() const override
37 {
39
40 for (Sign *si : Sign::Iterate()) {
41 SlSetArrayIndex(si->index);
43 }
44 }
45
46 void Load() const override
47 {
48 const std::vector<SaveLoad> slt = SlCompatTableHeader(_sign_desc, _sign_sl_compat);
49
50 int index;
51 while ((index = SlIterateArray()) != -1) {
52 Sign *si = new (index) Sign();
53 SlObject(si, slt);
54 /* Before version 6.1, signs didn't have owner.
55 * Before version 83, invalid signs were determined by si->str == 0.
56 * Before version 103, owner could be a bankrupted company.
57 * - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame()
58 * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER).
59 * - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
61 si->owner = OWNER_NONE;
62 }
63
64 /* Signs placed in scenario editor shall now be OWNER_DEITY */
66 si->owner = OWNER_DEITY;
67 }
68 }
69 }
70};
71
72static const SIGNChunkHandler SIGN;
73static const ChunkHandlerRef sign_chunk_handlers[] = {
74 SIGN,
75};
76
77extern const ChunkHandlerTable _sign_chunk_handlers(sign_chunk_handlers);
@ INVALID_OWNER
An invalid owner.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
@ OWNER_NONE
The tile has no ownership.
@ FT_SCENARIO
old or new scenario
Definition fileio_type.h:19
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:659
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:60
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_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition saveload.h:933
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:868
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1263
@ SLV_84
84 11822
Definition saveload.h:143
@ SLV_171
171 23835
Definition saveload.h:248
@ SLV_83
83 11589
Definition saveload.h:142
@ SLV_6
6.0 1721 6.1 1768
Definition saveload.h:46
@ SL_MAX_VERSION
Highest possible saveload version.
Definition saveload.h:399
@ SLV_164
164 23290
Definition saveload.h:239
@ SL_MIN_VERSION
First savegame version.
Definition saveload.h:31
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition saveload.h:43
static const SaveLoad _sign_desc[]
Description of a sign within the savegame.
Definition signs_sl.cpp:21
Loading of signs chunks before table headers were added.
const SaveLoadCompat _sign_sl_compat[]
Original field order for _sign_desc.
Handlers and description of chunk.
Definition saveload.h:463
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition saveload.h:413
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void Load() const override
Load the chunk.
Definition signs_sl.cpp:46
void Save() const override
Save the chunk.
Definition signs_sl.cpp:36
SaveLoad type struct.
Definition saveload.h:717