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

OpenTTD Source 15.0-beta1

goal_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#include "compat/goal_sl_compat.h"
14
15#include "../goal_base.h"
16
17#include "../safeguards.h"
18
19static const SaveLoad _goals_desc[] = {
20 SLE_VAR(Goal, company, SLE_FILE_U16 | SLE_VAR_U8),
21 SLE_VAR(Goal, type, SLE_FILE_U16 | SLE_VAR_U8),
22 SLE_VAR(Goal, dst, SLE_UINT32),
23 SLE_SSTR(Goal, text, SLE_STR | SLF_ALLOW_CONTROL),
24 SLE_CONDSSTR(Goal, progress, SLE_STR | SLF_ALLOW_CONTROL, SLV_182, SL_MAX_VERSION),
25 SLE_CONDVAR(Goal, completed, SLE_BOOL, SLV_182, SL_MAX_VERSION),
26};
27
28 struct GOALChunkHandler : ChunkHandler {
29 GOALChunkHandler() : ChunkHandler('GOAL', CH_TABLE) {}
30
31 void Save() const override
32 {
33 SlTableHeader(_goals_desc);
34
35 for (Goal *s : Goal::Iterate()) {
36 SlSetArrayIndex(s->index);
37 SlObject(s, _goals_desc);
38 }
39 }
40
41 void Load() const override
42 {
43 const std::vector<SaveLoad> slt = SlCompatTableHeader(_goals_desc, _goals_sl_compat);
44
45 int index;
46 while ((index = SlIterateArray()) != -1) {
47 Goal *s = new (index) Goal();
48 SlObject(s, slt);
49 }
50 }
51};
52
53static const GOALChunkHandler GOAL;
54static const ChunkHandlerRef goal_chunk_handlers[] = {
55 GOAL,
56};
57
58extern const ChunkHandlerTable _goal_chunk_handlers(goal_chunk_handlers);
goal_sl_compat.h
Loading of goal chunks before table headers were added.
_goals_sl_compat
const SaveLoadCompat _goals_sl_compat[]
Original field order for _goals_desc.
Definition goal_sl_compat.h:16
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition saveload.cpp:1924
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:659
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition saveload.cpp:1733
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition saveload.cpp:1786
saveload.h
Functions/types related to saving and loading games.
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition saveload.h:688
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:509
ChunkHandlerTable
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:512
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition saveload.h:933
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:868
SLE_SSTR
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
Definition saveload.h:1046
SLV_182
@ SLV_182
182 25115 FS#5492, r25259, r25296 Goal status
Definition saveload.h:261
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition saveload.h:399
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1002
ChunkHandler
Handlers and description of chunk.
Definition saveload.h:463
GOALChunkHandler
Definition goal_sl.cpp:28
GOALChunkHandler::Save
void Save() const override
Save the chunk.
Definition goal_sl.cpp:31
GOALChunkHandler::Load
void Load() const override
Load the chunk.
Definition goal_sl.cpp:41
Goal
Struct about goals, current and completed.
Definition goal_base.h:21
Pool::PoolItem<&_goal_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:388
SaveLoad
SaveLoad type struct.
Definition saveload.h:717