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/>.
8 /** @file randomizer_sl.cpp Code handling saving and loading of script randomizers */
10 #include "../stdafx.h"
11 #include "../script/api/script_object.hpp"
13 #include "saveload_internal.h"
14 #include "../safeguards.h"
16 static const SaveLoad _randomizer_desc
[] = {
17 SLE_VAR(Randomizer
, state
[0], SLE_UINT32
),
18 SLE_VAR(Randomizer
, state
[1], SLE_UINT32
),
21 struct SRNDChunkHandler
: ChunkHandler
{
22 SRNDChunkHandler() : ChunkHandler('SRND', CH_TABLE
)
25 void Save() const override
27 SlTableHeader(_randomizer_desc
);
29 for (Owner owner
= OWNER_BEGIN
; owner
< OWNER_END
; owner
++) {
30 SlSetArrayIndex(owner
);
31 SlObject(&ScriptObject::GetRandomizer(owner
), _randomizer_desc
);
35 void Load() const override
37 SlTableHeader(_randomizer_desc
);
40 while ((index
= (Owner
)SlIterateArray()) != (Owner
)-1) {
41 SlObject(&ScriptObject::GetRandomizer(index
), _randomizer_desc
);
46 static const SRNDChunkHandler SRND
;
47 static const ChunkHandlerRef randomizer_chunk_handlers
[] = {
51 extern const ChunkHandlerTable
_randomizer_chunk_handlers(randomizer_chunk_handlers
);