OpenTTD Source 20241224-master-gf74b0cf984
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
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
Enum for all companies/owners.
@ OWNER_END
Last + 1 owner.
@ OWNER_BEGIN
First owner.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:659
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.
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_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1002
Declaration of functions used in more save/load files.
Handlers and description of chunk.
Definition saveload.h:463
Structure to encapsulate the pseudo random number generators.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
SaveLoad type struct.
Definition saveload.h:717