12 #include "../stdafx.h" 13 #include "../company_base.h" 16 #include "../string_func.h" 18 #include "../ai/ai.hpp" 19 #include "../ai/ai_config.hpp" 20 #include "../network/network.h" 21 #include "../ai/ai_instance.hpp" 23 #include "../safeguards.h" 25 static char _ai_saveload_name[64];
26 static int _ai_saveload_version;
27 static char _ai_saveload_settings[1024];
28 static bool _ai_saveload_is_random;
30 static const SaveLoad _ai_company[] = {
31 SLEG_STR(_ai_saveload_name, SLE_STRB),
32 SLEG_STR(_ai_saveload_settings, SLE_STRB),
38 static void SaveReal_AIPL(
int *index_ptr)
48 _ai_saveload_name[0] =
'\0';
49 _ai_saveload_version = -1;
52 _ai_saveload_is_random = config->
IsRandom();
53 _ai_saveload_settings[0] =
'\0';
61 static void Load_AIPL()
72 _ai_saveload_is_random = 0;
73 _ai_saveload_version = -1;
84 config->
Change(NULL, -1,
false,
true);
86 config->
Change(_ai_saveload_name, _ai_saveload_version,
false, _ai_saveload_is_random);
90 config->
Change(_ai_saveload_name, -1,
false, _ai_saveload_is_random);
92 if (strcmp(_ai_saveload_name,
"%_dummy") != 0) {
93 DEBUG(script, 0,
"The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version);
94 DEBUG(script, 0,
"A random other AI will be loaded in its place.");
96 DEBUG(script, 0,
"The savegame had no AIs available at the time of saving.");
97 DEBUG(script, 0,
"A random available AI will be loaded now.");
100 DEBUG(script, 0,
"The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version);
101 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.");
105 _ai_saveload_version = -1;
114 AI::Load(index, _ai_saveload_version);
119 static void Save_AIPL()
128 {
'AIPL', Save_AIPL, Load_AIPL, NULL, NULL, CH_ARRAY |
CH_LAST},
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
bool _networking
are we in networking mode?
#define SLEG_STR(variable, type)
Storage of a global string in every savegame version.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
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.
#define lastof(x)
Get the last element of an fixed size array.
const char * GetName() const
Get the name of the Script.
bool IsRandom() const
Is the current Script a randomly chosen Script?
static void Save(CompanyID company)
Save data from an AI to a savegame.
Functions/types related to saving and loading games.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
First company, same as owner.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
#define SL_MAX_VERSION
Highest possible savegame version.
static void Load(CompanyID company, int version)
Load data for an AI from a savegame.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Maximum number of companies.
Handlers and description of chunk.
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
#define DEBUG(name, level,...)
Output a line of debugging information.
#define SLE_END()
End marker of a struct/class save or load.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
bool _network_server
network-server is active
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
Owner
Enum for all companies/owners.
static void LoadEmpty()
Load and discard data from a savegame.
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script...
void SettingsToString(char *string, const char *last) const
Convert the custom settings to a string that can be stored in the config file or savegames.
Get the Script config from the current game.
Last chunk in this array.
int GetVersion() const
Get the version of the Script.