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

OpenTTD Source 15.0-beta1

randomizer_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 "../script/api/script_object.hpp"
12#include "saveload.h"
13#include "saveload_internal.h"
14#include "../safeguards.h"
15
16static const SaveLoad _randomizer_desc[] = {
17 SLE_VAR(Randomizer, state[0], SLE_UINT32),
18 SLE_VAR(Randomizer, state[1], SLE_UINT32),
19};
20
21 struct SRNDChunkHandler : ChunkHandler {
22 SRNDChunkHandler() : ChunkHandler('SRND', CH_TABLE)
23 {}
24
25 void Save() const override
26 {
27 SlTableHeader(_randomizer_desc);
28
29 for (Owner owner = OWNER_BEGIN; owner < OWNER_END; owner++) {
30 SlSetArrayIndex(owner);
31 SlObject(&ScriptObject::GetRandomizer(owner), _randomizer_desc);
32 }
33 }
34
35 void Load() const override
36 {
37 SlTableHeader(_randomizer_desc);
38
39 Owner index;
40 while ((index = (Owner)SlIterateArray()) != (Owner)-1) {
41 SlObject(&ScriptObject::GetRandomizer(index), _randomizer_desc);
42 }
43 }
44};
45
46static const SRNDChunkHandler SRND;
47static const ChunkHandlerRef randomizer_chunk_handlers[] = {
48 SRND,
49};
50
51extern const ChunkHandlerTable _randomizer_chunk_handlers(randomizer_chunk_handlers);
Owner
Owner
Enum for all companies/owners.
Definition company_type.h:18
OWNER_END
@ OWNER_END
Last + 1 owner.
Definition company_type.h:28
OWNER_BEGIN
@ OWNER_BEGIN
First owner.
Definition company_type.h:21
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.
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_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1002
saveload_internal.h
Declaration of functions used in more save/load files.
ChunkHandler
Handlers and description of chunk.
Definition saveload.h:463
Randomizer
Structure to encapsulate the pseudo random number generators.
Definition random_func.hpp:27
SRNDChunkHandler
Definition randomizer_sl.cpp:21
SRNDChunkHandler::Save
void Save() const override
Save the chunk.
Definition randomizer_sl.cpp:25
SRNDChunkHandler::Load
void Load() const override
Load the chunk.
Definition randomizer_sl.cpp:35
SaveLoad
SaveLoad type struct.
Definition saveload.h:717