OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
16 #include "../company_base.h"
17 #include "../string_func.h"
19 #include "../ai/ai.hpp"
20 #include "../ai/ai_config.hpp"
21 #include "../network/network.h"
22 #include "../ai/ai_instance.hpp"
24 #include "../safeguards.h"
26 static std::string _ai_saveload_name;
27 static int _ai_saveload_version;
28 static std::string _ai_saveload_settings;
29 static bool _ai_saveload_is_random;
31 static const SaveLoad _ai_company_desc[] = {
38 static void SaveReal_AIPL(
int *index_ptr)
44 _ai_saveload_name = config->
GetName();
48 _ai_saveload_name.clear();
49 _ai_saveload_version = -1;
52 _ai_saveload_is_random = config->
IsRandom();
76 _ai_saveload_is_random =
false;
77 _ai_saveload_version = -1;
86 if (_ai_saveload_name.empty()) {
88 config->
Change(
nullptr, -1,
false,
true);
90 config->
Change(_ai_saveload_name.c_str(), _ai_saveload_version,
false, _ai_saveload_is_random);
94 config->
Change(_ai_saveload_name.c_str(), -1,
false, _ai_saveload_is_random);
96 if (_ai_saveload_name.compare(
"%_dummy") != 0) {
97 Debug(script, 0,
"The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
98 Debug(script, 0,
"A random other AI will be loaded in its place.");
100 Debug(script, 0,
"The savegame had no AIs available at the time of saving.");
101 Debug(script, 0,
"A random available AI will be loaded now.");
104 Debug(script, 0,
"The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
105 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.");
109 _ai_saveload_version = -1;
118 AI::Load(index, _ai_saveload_version);
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
bool _network_server
network-server is active
static void Load(CompanyID company, int version)
Load data for an AI from a savegame.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
const SaveLoadCompat _ai_company_sl_compat[]
Original field order for _ai_company_desc.
Handlers and description of chunk.
Owner
Enum for all companies/owners.
@ COMPANY_FIRST
First company, same as owner.
static void Save(CompanyID company)
Save data from an AI to a savegame.
A trimmed down version of what std::span will be in C++20.
const char * GetName() const
Get the name of the Script.
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
bool IsRandom() const
Is the current Script a randomly chosen Script?
@ MAX_COMPANIES
Maximum number of companies.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
#define SLEG_SSTR(name, variable, type)
Storage of a global std::string in every savegame version.
bool _networking
are we in networking mode?
static void LoadEmpty()
Load and discard data from a savegame.
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
int GetVersion() const
Get the version of the Script.
@ SL_MAX_VERSION
Highest possible saveload version.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
void Change(const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
@ SSS_FORCE_GAME
Get the Script config from the current game.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.