OpenTTD Source 20260711-master-g3fb3006dff
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 <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 "../signs_base.h"
16#include "../fios.h"
17
18#include "../safeguards.h"
19
33
34struct SIGNChunkHandler : ChunkHandler {
35 SIGNChunkHandler() : ChunkHandler('SIGN', ChunkType::Table) {}
36
37 void Save() const override
38 {
40
41 for (Sign *si : Sign::Iterate()) {
42 SlSetArrayIndex(si->index);
44 }
45 }
46
47 void Load() const override
48 {
49 const std::vector<SaveLoad> slt = SlCompatTableHeader(_sign_desc, _sign_sl_compat);
50
51 int index;
52 while ((index = SlIterateArray()) != -1) {
53 Sign *si = Sign::CreateAtIndex(SignID(index));
54 SlObject(si, slt);
55 /* Before version 6.1, signs didn't have owner.
56 * Before version 83, invalid signs were determined by si->str == 0.
57 * Before version 103, owner could be a bankrupted company.
58 * - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame()
59 * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER).
60 * - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
62 si->owner = OWNER_NONE;
63 }
64
65 /* Signs placed in scenario editor shall now be OWNER_DEITY */
67 si->owner = OWNER_DEITY;
68 }
69 }
70 }
71};
72
73static const SIGNChunkHandler SIGN;
74static const ChunkHandlerRef sign_chunk_handlers[] = {
75 SIGN,
76};
77
78extern const ChunkHandlerTable _sign_chunk_handlers(sign_chunk_handlers);
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
static constexpr Owner OWNER_NONE
The tile has no ownership.
static constexpr Owner INVALID_OWNER
An invalid owner.
@ Scenario
old or new scenario
Definition fileio_type.h:20
Declarations for savegames operations.
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
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:78
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.
@ I32
A 32 bit signed int.
Definition saveload.h:683
@ U8
A 8 bit unsigned int.
Definition saveload.h:662
@ I16
A 16 bit signed int.
Definition saveload.h:663
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_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition saveload.h:958
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:904
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1278
@ ReplaceCustomNameArray
Saveload version: 84, SVN revision: 11822 Replace single fixed size array of custom names,...
Definition saveload.h:144
@ SignTextColours
Saveload version: 363, GitHub pull request: 14743 Configurable sign text colors in scenario editor.
Definition saveload.h:415
@ VehicleCentreAndZPos
Saveload version: 164, SVN revision: 23290 Vehicle centres are not fixed at 4/8 of the vehicle; chan...
Definition saveload.h:240
@ BigMap
Saveload version: 5.0, SVN revision: 1429 Making maps a different size than 256x256.
Definition saveload.h:44
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
Definition saveload.h:47
@ MinVersion
First savegame version.
Definition saveload.h:31
@ ScenarioDeitySigns
Saveload version: 171, SVN revision: 23835 Signs made in scenarios become of OWNER_DEITY,...
Definition saveload.h:249
@ DepotWaterOwners
Saveload version: 83, SVN revision: 11589 Store the owner of the water under depots,...
Definition saveload.h:143
@ MaxVersion
Highest possible saveload version.
Definition saveload.h:421
@ Table
An Array with a header describing the elements.
Definition saveload.h:475
Base class for signs.
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.
PoolID< uint16_t, struct SignIDTag, 64000, 0xFFFF > SignID
The type of the IDs of signs.
Definition signs_type.h:16
Definition of base types and functions in a cross-platform compatible way.
@ AllowControlCode
Allow the special control codes.
Definition string_type.h:47
static Pool::IterateWrapper< Sign > Iterate(size_t from=0)
static T * CreateAtIndex(SignID index, Targs &&... args)
void Load() const override
Load the chunk.
Definition signs_sl.cpp:47
void Save() const override
Save the chunk.
Definition signs_sl.cpp:37
SaveLoad type struct.
Definition saveload.h:787
Owner owner
Placed by this company. Anyone can delete them though. OWNER_NONE for gray signs from old games.
Definition signs_base.h:27
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 NAME
A string stored in the custom string array.
Definition saveload.h:762
static constexpr VarType I32
Store a 32 bits signed int.
Definition saveload.h:755