Changeset - r28744:ea3c121812c9
[Not reviewed]
master
0 4 1
Loïc Guilloux - 10 months ago 2024-02-12 00:22:57
glx22@users.noreply.github.com
Change: [Script] Store randomizers in savegame (#12063)
5 files changed with 59 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/saveload/CMakeLists.txt
Show inline comments
 
@@ -30,6 +30,7 @@ add_files(
 
    oldloader.h
 
    oldloader_sl.cpp
 
    order_sl.cpp
 
    randomizer_sl.cpp
 
    saveload.cpp
 
    saveload.h
 
    saveload_filter.h
src/saveload/afterload.cpp
Show inline comments
 
@@ -255,8 +255,6 @@ static void InitializeWindowsAndCaches()
 
	UpdateAllVirtCoords();
 
	ResetViewportAfterLoadGame();
 

	
 
	ScriptObject::InitializeRandomizers();
 

	
 
	for (Company *c : Company::Iterate()) {
 
		/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
 
		 * accordingly if it is not the case.  No need to set it on companies that are not been used already,
 
@@ -3288,6 +3286,10 @@ bool AfterLoadGame()
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_SCRIPT_RANDOMIZER)) {
 
		ScriptObject::InitializeRandomizers();
 
	}
 

	
 
	for (Company *c : Company::Iterate()) {
 
		UpdateCompanyLiveries(c);
 
	}
src/saveload/randomizer_sl.cpp
Show inline comments
 
new file 100644
 
/*
 
 * This file is part of OpenTTD.
 
 * 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.
 
 * 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.
 
 * 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/>.
 
 */
 

	
 
/** @file randomizer_sl.cpp Code handling saving and loading of script randomizers */
 

	
 
#include "../stdafx.h"
 
#include "../script/api/script_object.hpp"
 
#include "saveload.h"
 
#include "saveload_internal.h"
 
#include "../safeguards.h"
 

	
 
static const SaveLoad _randomizer_desc[] = {
 
	SLE_VAR(Randomizer, state[0], SLE_UINT32),
 
	SLE_VAR(Randomizer, state[1], SLE_UINT32),
 
};
 

	
 
struct SRNDChunkHandler : ChunkHandler {
 
	SRNDChunkHandler() : ChunkHandler('SRND', CH_TABLE)
 
	{}
 

	
 
	void Save() const override
 
	{
 
		SlTableHeader(_randomizer_desc);
 

	
 
		for (Owner owner = OWNER_BEGIN; owner < OWNER_END; owner++) {
 
			SlSetArrayIndex(owner);
 
			SlObject(&ScriptObject::GetRandomizer(owner), _randomizer_desc);
 
		}
 
	}
 

	
 
	void Load() const override
 
	{
 
		SlTableHeader(_randomizer_desc);
 

	
 
		Owner index;
 
		while ((index = (Owner)SlIterateArray()) != (Owner)-1) {
 
			SlObject(&ScriptObject::GetRandomizer(index), _randomizer_desc);
 
		}
 
	}
 
};
 

	
 
static const SRNDChunkHandler SRND;
 
static const ChunkHandlerRef randomizer_chunk_handlers[] = {
 
	SRND,
 
};
 

	
 
extern const ChunkHandlerTable _randomizer_chunk_handlers(randomizer_chunk_handlers);
src/saveload/saveload.cpp
Show inline comments
 
@@ -250,6 +250,7 @@ static const std::vector<ChunkHandlerRef
 
	extern const ChunkHandlerTable _object_chunk_handlers;
 
	extern const ChunkHandlerTable _persistent_storage_chunk_handlers;
 
	extern const ChunkHandlerTable _water_region_chunk_handlers;
 
	extern const ChunkHandlerTable _randomizer_chunk_handlers;
 

	
 
	/** List of all chunks in a savegame. */
 
	static const ChunkHandlerTable _chunk_handler_tables[] = {
 
@@ -288,6 +289,7 @@ static const std::vector<ChunkHandlerRef
 
		_object_chunk_handlers,
 
		_persistent_storage_chunk_handlers,
 
		_water_region_chunk_handlers,
 
		_randomizer_chunk_handlers,
 
	};
 

	
 
	static std::vector<ChunkHandlerRef> _chunk_handlers;
src/saveload/saveload.h
Show inline comments
 
@@ -376,6 +376,7 @@ enum SaveLoadVersion : uint16_t {
 
	SLV_MAX_LOAN_FOR_COMPANY,               ///< 330  PR#11224 Separate max loan for each company.
 
	SLV_DEPOT_UNBUNCHING,                   ///< 331  PR#11945 Allow unbunching shared order vehicles at a depot.
 
	SLV_AI_LOCAL_CONFIG,                    ///< 332  PR#12003 Config of running AI is stored inside Company.
 
	SLV_SCRIPT_RANDOMIZER,                  ///< 333  PR#12063 Save script randomizers.
 

	
 
	SL_MAX_VERSION,                         ///< Highest possible saveload version
 
};
0 comments (0 inline, 0 general)