OpenTTD Source: src/saveload/signs_sl.cpp Source File

OpenTTD Source 1.11.0-RC1

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 #include "../signs_base.h"
12 #include "../fios.h"
13
14 #include "saveload.h"
15
16 #include "../safeguards.h"
17
19 static const SaveLoad _sign_desc[] = {
20 SLE_CONDVAR(Sign, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
21 SLE_CONDSSTR(Sign, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
22 SLE_CONDVAR(Sign, x, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_5),
23 SLE_CONDVAR(Sign, y, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_5),
24 SLE_CONDVAR(Sign, x, SLE_INT32, SLV_5, SL_MAX_VERSION),
25 SLE_CONDVAR(Sign, y, SLE_INT32, SLV_5, SL_MAX_VERSION),
26 SLE_CONDVAR(Sign, owner, SLE_UINT8, SLV_6, SL_MAX_VERSION),
27 SLE_CONDVAR(Sign, z, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_164),
28 SLE_CONDVAR(Sign, z, SLE_INT32, SLV_164, SL_MAX_VERSION),
29 SLE_END()
30 };
31
33 static void Save_SIGN()
34 {
35 for (Sign *si : Sign::Iterate()) {
36 SlSetArrayIndex(si->index);
37 SlObject(si, _sign_desc);
38 }
39 }
40
42 static void Load_SIGN()
43 {
44 int index;
45 while ((index = SlIterateArray()) != -1) {
46 Sign *si = new (index) Sign();
47 SlObject(si, _sign_desc);
48 /* Before version 6.1, signs didn't have owner.
49 * Before version 83, invalid signs were determined by si->str == 0.
50 * Before version 103, owner could be a bankrupted company.
51 * - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame()
52 * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER).
53 * - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
54 if (IsSavegameVersionBefore(SLV_6, 1) || (IsSavegameVersionBefore(SLV_83) && si->owner == INVALID_OWNER)) {
55 si->owner = OWNER_NONE;
56 }
57
58 /* Signs placed in scenario editor shall now be OWNER_DEITY */
59 if (IsSavegameVersionBefore(SLV_171) && si->owner == OWNER_NONE && _file_to_saveload.abstract_ftype == FT_SCENARIO) {
60 si->owner = OWNER_DEITY;
61 }
62 }
63 }
64
66 extern const ChunkHandler _sign_chunk_handlers[] = {
67 { 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_ARRAY | CH_LAST},
68 };
FT_SCENARIO
@ FT_SCENARIO
old or new scenario
Definition: fileio_type.h:19
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:31
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition: saveload.h:593
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:551
SLV_84
@ SLV_84
84 11822
Definition: saveload.h:143
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:647
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:410
saveload.h
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:379
SLV_83
@ SLV_83
83 11589
Definition: saveload.h:142
Load_SIGN
static void Load_SIGN()
Load all signs.
Definition: signs_sl.cpp:42
Save_SIGN
static void Save_SIGN()
Save all signs.
Definition: signs_sl.cpp:33
FileToSaveLoad::abstract_ftype
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:342
SLV_5
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:43
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
allow control codes in the strings
Definition: saveload.h:489
_sign_desc
static const SaveLoad _sign_desc[]
Description of a sign within the savegame.
Definition: signs_sl.cpp:19
SLV_164
@ SLV_164
164 23290
Definition: saveload.h:239
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:686
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:815
_sign_chunk_handlers
const ChunkHandler _sign_chunk_handlers[]
Chunk handlers related to signs.
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:328
Pool::PoolItem<&_sign_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:46
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:62
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
Sign
Definition: signs_base.h:22
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
SLV_171
@ SLV_171
171 23835
Definition: saveload.h:248
SaveLoad
SaveLoad type struct.
Definition: saveload.h:516
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:631