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[] = {
32 SLEG_SSTR(
"name", _ai_saveload_name, SLE_STR),
33 SLEG_SSTR(
"settings", _ai_saveload_settings, SLE_STR),
38 static const SaveLoad _ai_running_desc[] = {
44 static void SaveReal_AIPL(
int arg)
50 _ai_saveload_name = config->
GetName();
54 _ai_saveload_name.clear();
55 _ai_saveload_version = -1;
66 _ai_saveload_name = config->
GetName();
91 _ai_saveload_is_random =
false;
92 _ai_saveload_version = -1;
104 if (_ai_saveload_name.empty() || _ai_saveload_is_random) {
106 config->
Change(std::nullopt, -1,
false);
108 config->
Change(_ai_saveload_name, _ai_saveload_version,
false);
112 config->
Change(_ai_saveload_name, -1,
false);
114 if (_ai_saveload_name.compare(
"%_dummy") != 0) {
115 Debug(script, 0,
"The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
116 Debug(script, 0,
"Configuration switched to Random AI.");
119 Debug(script, 0,
"The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
120 Debug(script, 0,
"The latest version of that AI has been configured instead");
129 SlObject(
nullptr, _ai_running_desc);
131 Company::Get(index)->ai_config = std::make_unique<AIConfig>();
133 config->
Change(_ai_saveload_name, _ai_saveload_version,
false);
137 config->
Change(_ai_saveload_name, -1,
false);
139 if (_ai_saveload_name.compare(
"%_dummy") != 0) {
140 Debug(script, 0,
"The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
141 Debug(script, 0,
"A random other AI will be loaded in its place.");
143 Debug(script, 0,
"The savegame had no AIs available at the time of saving.");
144 Debug(script, 0,
"A random available AI will be loaded now.");
147 Debug(script, 0,
"The savegame has an AI by the name '{}', version {} which is no longer available.", _ai_saveload_name, _ai_saveload_version);
148 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.");
152 _ai_saveload_version = -1;
Loading for ai chunks before table headers were added.
const SaveLoadCompat _ai_company_sl_compat[]
Original field order for _ai_company_desc.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static void Save(CompanyID company)
Save data from an AI to a savegame.
@ 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...
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
const std::string & GetName() const
Get the name of the Script.
int GetVersion() const
Get the version of the Script.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
static ScriptData * Load(int version)
Load data from a savegame.
static void LoadEmpty()
Load and discard data from a savegame.
Owner
Enum for all companies/owners.
@ COMPANY_FIRST
First company, same as owner.
@ MAX_COMPANIES
Maximum number of companies.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
void SlAutolength(AutolengthProc *proc, int arg)
Do something of which I have no idea what it is :P.
Functions/types related to saving and loading games.
#define SLEG_CONDSSTR(name, variable, type, from, to)
Storage of a global std::string in some savegame versions.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
#define SLEG_SSTR(name, variable, type)
Storage of a global std::string in every savegame version.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
@ SLV_AI_LOCAL_CONFIG
332 PR#12003 Config of running AI is stored inside Company.
@ SL_MAX_VERSION
Highest possible saveload version.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
Handlers and description of chunk.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
static Titem * Get(size_t index)
Returns Titem with given index.