OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../company_base.h"
14 #include "../string_func.h"
16 #include "../ai/ai.hpp"
17 #include "../ai/ai_config.hpp"
18 #include "../network/network.h"
19 #include "../ai/ai_instance.hpp"
21 #include "../safeguards.h"
23 static char _ai_saveload_name[64];
24 static int _ai_saveload_version;
25 static char _ai_saveload_settings[1024];
26 static bool _ai_saveload_is_random;
28 static const SaveLoad _ai_company[] = {
29 SLEG_STR(_ai_saveload_name, SLE_STRB),
30 SLEG_STR(_ai_saveload_settings, SLE_STRB),
36 static void SaveReal_AIPL(
int *index_ptr)
46 _ai_saveload_name[0] =
'\0';
47 _ai_saveload_version = -1;
50 _ai_saveload_is_random = config->
IsRandom();
51 _ai_saveload_settings[0] =
'\0';
59 static void Load_AIPL()
70 _ai_saveload_is_random = 0;
71 _ai_saveload_version = -1;
82 config->
Change(
nullptr, -1,
false,
true);
84 config->
Change(_ai_saveload_name, _ai_saveload_version,
false, _ai_saveload_is_random);
88 config->
Change(_ai_saveload_name, -1,
false, _ai_saveload_is_random);
90 if (strcmp(_ai_saveload_name,
"%_dummy") != 0) {
91 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);
92 DEBUG(script, 0,
"A random other AI will be loaded in its place.");
94 DEBUG(script, 0,
"The savegame had no AIs available at the time of saving.");
95 DEBUG(script, 0,
"A random available AI will be loaded now.");
98 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);
99 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.");
103 _ai_saveload_version = -1;
112 AI::Load(index, _ai_saveload_version);
117 static void Save_AIPL()
126 {
'AIPL', Save_AIPL, Load_AIPL,
nullptr,
nullptr, CH_ARRAY |
CH_LAST},
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.
bool _network_server
network-server is active
static void Load(CompanyID company, int version)
Load data for an AI from a savegame.
@ CH_LAST
Last chunk in this array.
Handlers and description of chunk.
Owner
Enum for all companies/owners.
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
@ COMPANY_FIRST
First company, same as owner.
static void Save(CompanyID company)
Save data from an AI to a savegame.
#define DEBUG(name, level,...)
Output a line of debugging information.
const char * GetName() const
Get the name of the Script.
#define SLE_END()
End marker of a struct/class save or load.
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)?
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
bool _networking
are we in networking mode?
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
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.
#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.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
@ SSS_FORCE_GAME
Get the Script config from the current game.
#define lastof(x)
Get the last element of an fixed size array.
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.