Merge branch 'master' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/autoreplace_cmd.cpp
#	src/industry_gui.cpp
#	src/landscape.cpp
#	src/network/network_content.cpp
#	src/newgrf_roadstop.cpp
#	src/pathfinder/yapf/yapf_ship.cpp
#	src/road_gui.cpp
#	src/saveload/ai_sl.cpp
#	src/saveload/saveload.h
#	src/saveload/vehicle_sl.cpp
#	src/station.cpp
#	src/station_gui.cpp
#	src/video/cocoa/cocoa_ogl.h
#	src/video/sdl2_opengl_v.h
#	src/video/video_driver.hpp
#	src/video/win32_v.h
#	src/widget_type.h
#	src/widgets/dropdown.cpp
#	src/widgets/dropdown_type.h
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-19 18:50:33 +00:00
119 changed files with 4346 additions and 2129 deletions

View File

@@ -27,6 +27,7 @@ add_files(
newgrf_sl.h
object_sl.cpp
order_sl.cpp
randomizer_sl.cpp
saveload.cpp
saveload.h
settings_sl.cpp

View File

@@ -273,8 +273,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,
@@ -4408,6 +4406,10 @@ bool AfterLoadGame()
}
}
if (IsSavegameVersionBefore(SLV_SCRIPT_RANDOMIZER)) {
ScriptObject::InitializeRandomizers();
}
for (Company *c : Company::Iterate()) {
UpdateCompanyLiveries(c);
}

View File

@@ -9,6 +9,7 @@
#include "../stdafx.h"
#include "../debug.h"
#include "../debug_fmt.h"
#include "saveload.h"
#include "compat/ai_sl_compat.h"
@@ -34,13 +35,19 @@ static const SaveLoad _ai_company_desc[] = {
SLEG_SSTR("name", _ai_saveload_name, SLE_STR),
SLEG_SSTR("settings", _ai_saveload_settings, SLE_STR),
SLEG_CONDVAR("version", _ai_saveload_version, SLE_UINT32, SLV_108, SL_MAX_VERSION),
SLEG_CONDVAR("is_random", _ai_saveload_is_random, SLE_BOOL, SLV_136, SL_MAX_VERSION),
SLEG_CONDVAR("is_random", _ai_saveload_is_random, SLE_BOOL, SLV_136, SLV_AI_LOCAL_CONFIG),
};
static const SaveLoad _ai_running_desc[] = {
SLEG_CONDSSTR("running_name", _ai_saveload_name, SLE_STR, SLV_AI_LOCAL_CONFIG, SL_MAX_VERSION),
SLEG_CONDSSTR("running_settings", _ai_saveload_settings, SLE_STR, SLV_AI_LOCAL_CONFIG, SL_MAX_VERSION),
SLEG_CONDVAR("running_version", _ai_saveload_version, SLE_UINT32, SLV_AI_LOCAL_CONFIG, SL_MAX_VERSION),
};
static void SaveReal_AIPL(int *index_ptr)
{
CompanyID index = (CompanyID)*index_ptr;
AIConfig *config = AIConfig::GetConfig(index);
AIConfig *config = AIConfig::GetConfig(index, AIConfig::SSS_FORCE_GAME);
if (config->HasScript()) {
_ai_saveload_name = config->GetName();
@@ -51,12 +58,21 @@ static void SaveReal_AIPL(int *index_ptr)
_ai_saveload_version = -1;
}
_ai_saveload_is_random = config->IsRandom();
_ai_saveload_settings = config->SettingsToString();
SlObject(nullptr, _ai_company_desc);
if (!Company::IsValidAiID(index)) return;
/* If the AI was active, store its data too */
if (Company::IsValidAiID(index)) AI::Save(index);
config = AIConfig::GetConfig(index);
_ai_saveload_name = config->GetName();
_ai_saveload_version = config->GetVersion();
_ai_saveload_settings = config->SettingsToString();
SlObject(nullptr, _ai_running_desc);
AI::Save(index);
}
struct AIPLChunkHandler : ChunkHandler {
@@ -80,42 +96,66 @@ struct AIPLChunkHandler : ChunkHandler {
SlObject(nullptr, slt);
if (_game_mode == GM_MENU || (_networking && !_network_server)) {
if (Company::IsValidAiID(index)) AIInstance::LoadEmpty();
if (Company::IsValidAiID(index)) {
SlObject(nullptr, _ai_running_desc);
AIInstance::LoadEmpty();
}
continue;
}
AIConfig *config = AIConfig::GetConfig(index, AIConfig::SSS_FORCE_GAME);
if (_ai_saveload_name.empty()) {
if (_ai_saveload_name.empty() || _ai_saveload_is_random) {
/* A random AI. */
config->Change(std::nullopt, -1, false, true);
config->Change(std::nullopt, -1, false);
} else {
config->Change(_ai_saveload_name, _ai_saveload_version, false, _ai_saveload_is_random);
config->Change(_ai_saveload_name, _ai_saveload_version, false);
if (!config->HasScript()) {
/* No version of the AI available that can load the data. Try to load the
/* No version of the AI available. Try to configure the
* latest version of the AI instead. */
config->Change(_ai_saveload_name, -1, false, _ai_saveload_is_random);
config->Change(_ai_saveload_name, -1, false);
if (!config->HasScript()) {
if (_ai_saveload_name.compare("%_dummy") != 0) {
DEBUG(script, 0, "The savegame has an AI by the name '%s', version %u which is no longer available.", _ai_saveload_name.c_str(), _ai_saveload_version);
DEBUG(script, 0, "A random other AI will be loaded in its place.");
} else {
DEBUG(script, 0, "The savegame had no AIs available at the time of saving.");
DEBUG(script, 0, "A random available AI will be loaded now.");
Debug(script, 0, "The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
Debug(script, 0, "Configuration switched to Random AI.");
}
} else {
DEBUG(script, 0, "The savegame has an AI by the name '%s', version %u which is no longer available.", _ai_saveload_name.c_str(), _ai_saveload_version);
DEBUG(script, 0, "The latest version of that AI has been loaded instead, but it'll not get the savegame data as it's incompatible.");
Debug(script, 0, "The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
Debug(script, 0, "The latest version of that AI has been configured instead");
}
/* Make sure the AI doesn't get the saveload data, as it was not the
* writer of the saveload data in the first place */
_ai_saveload_version = -1;
}
}
config->StringToSettings(_ai_saveload_settings);
if (!Company::IsValidAiID(index)) continue;
/* Load the AI saved data */
if (Company::IsValidAiID(index)) config->SetToLoadData(AIInstance::Load(_ai_saveload_version));
SlObject(nullptr, _ai_running_desc);
Company::Get(index)->ai_config = std::make_unique<AIConfig>();
config = Company::Get(index)->ai_config.get();
config->Change(_ai_saveload_name, _ai_saveload_version, false);
if (!config->HasScript()) {
/* No version of the AI available that can load the data. Try to load the
* latest version of the AI instead. */
config->Change(_ai_saveload_name, -1, false);
if (!config->HasScript()) {
if (_ai_saveload_name.compare("%_dummy") != 0) {
Debug(script, 0, "The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
Debug(script, 0, "A random other AI will be loaded in its place.");
} else {
Debug(script, 0, "The savegame had no AIs available at the time of saving.");
Debug(script, 0, "A random available AI will be loaded now.");
}
} else {
Debug(script, 0, "The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
Debug(script, 0, "The latest version of that AI has been loaded instead, but it'll not get the savegame data as it's incompatible.");
}
/* Make sure the AI doesn't get the saveload data, as it was not the
* writer of the saveload data in the first place */
_ai_saveload_version = -1;
}
config->StringToSettings(_ai_saveload_settings);
config->SetToLoadData(AIInstance::Load(_ai_saveload_version));
}
}

View File

@@ -19,7 +19,7 @@ const SaveLoadCompat _game_script_sl_compat[] = {
SLC_VAR("name"),
SLC_VAR("settings"),
SLC_VAR("version"),
SLC_VAR("is_random"),
SLC_NULL(1, SL_MIN_VERSION, SLV_AI_LOCAL_CONFIG),
};
/** Original field order for SlGameLanguageString. */

View File

@@ -29,13 +29,11 @@ namespace upstream_sl {
static std::string _game_saveload_name;
static int _game_saveload_version;
static std::string _game_saveload_settings;
static bool _game_saveload_is_random;
static const SaveLoad _game_script_desc[] = {
SLEG_SSTR("name", _game_saveload_name, SLE_STR),
SLEG_SSTR("settings", _game_saveload_settings, SLE_STR),
SLEG_VAR("version", _game_saveload_version, SLE_UINT32),
SLEG_VAR("is_random", _game_saveload_is_random, SLE_BOOL),
};
static void SaveReal_GSDT(int *)
@@ -51,7 +49,6 @@ static void SaveReal_GSDT(int *)
_game_saveload_version = -1;
}
_game_saveload_is_random = config->IsRandom();
_game_saveload_settings = config->SettingsToString();
SlObject(nullptr, _game_script_desc);
@@ -81,11 +78,11 @@ struct GSDTChunkHandler : ChunkHandler {
GameConfig *config = GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME);
if (!_game_saveload_name.empty()) {
config->Change(_game_saveload_name, _game_saveload_version, false, _game_saveload_is_random);
config->Change(_game_saveload_name, _game_saveload_version, false);
if (!config->HasScript()) {
/* No version of the GameScript available that can load the data. Try to load the
* latest version of the GameScript instead. */
config->Change(_game_saveload_name, -1, false, _game_saveload_is_random);
config->Change(_game_saveload_name, -1, false);
if (!config->HasScript()) {
if (_game_saveload_name.compare("%_dummy") != 0) {
DEBUG(script, 0, "The savegame has an GameScript by the name '%s', version %u which is no longer available.", _game_saveload_name.c_str(), _game_saveload_version);

View File

@@ -0,0 +1,54 @@
/*
* 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 "../safeguards.h"
namespace upstream_sl {
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);
};

View File

@@ -121,6 +121,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
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[] = {
@@ -159,6 +160,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
_object_chunk_handlers,
_persistent_storage_chunk_handlers,
_water_region_chunk_handlers,
_randomizer_chunk_handlers,
};
static std::vector<ChunkHandlerRef> _chunk_handlers;