12 #include "../stdafx.h" 13 #include "../core/backup_type.hpp" 14 #include "../core/bitmath_func.hpp" 15 #include "../company_base.h" 16 #include "../company_func.h" 17 #include "../network/network.h" 18 #include "../window_func.h" 25 #include "../safeguards.h" 45 AIInfo *info = config->GetInfo();
46 if (info == NULL || (rerandomise_ai && config->
IsRandom())) {
58 assert(c->ai_instance == NULL);
80 FOR_ALL_COMPANIES(c) {
108 delete c->ai_instance;
109 c->ai_instance = NULL;
142 bool paused =
Company::Get(company)->ai_instance->IsPaused();
155 FOR_ALL_COMPANIES(c) {
165 if (AI::scanner_info == NULL) {
168 AI::scanner_info->Initialize();
170 AI::scanner_library->Initialize();
185 AI::scanner_info = NULL;
186 AI::scanner_library = NULL;
281 assert(c != NULL && c->ai_instance != NULL);
284 c->ai_instance->
Save();
295 assert(c != NULL && c->ai_instance != NULL);
298 c->ai_instance->
Load(version);
339 return AI::scanner_info->
FindInfo(name, version, force_exact_match);
344 return AI::scanner_library->
FindLibrary(library, version);
360 #if defined(ENABLE_NETWORK) 370 return AI::scanner_info->
HasScript(ci, md5sum);
373 bool AI::HasAILibrary(
const ContentInfo *ci,
bool md5sum)
375 return AI::scanner_library->
HasScript(ci, md5sum);
AISettings ai
what may the AI do?
const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
bool _networking
are we in networking mode?
static const int DAYS_IN_YEAR
days per year
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
int version
Version of the script.
static void Unpause(CompanyID company)
Resume execution of the AI.
Runtime information about an AI like a pointer to the squirrel vm and the current state...
static Titem * Get(size_t index)
Returns Titem with given index.
const char * GetName() const
Get the Name of the script.
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
static void Initialize()
Initialize the AI system.
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 Change(const U &new_value)
Change the value of the variable.
DifficultySettings difficulty
settings related to the difficulty
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Tindex index
Index of this pool item.
static int GetStartNextTime()
Get the number of days before the next AI should start.
The AIInstance tracks an AI.
AI debug window; Window numbers:
static class AIInfo * FindInfo(const char *name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
void Save()
Call the script Save function and save all data in the savegame.
declarations of the class for AI scanner
const char * GetName() const
Get the name of the Script.
bool _network_dedicated
are we a dedicated server?
Class to backup a specific variable and restore it later.
bool ResetInfo(bool force_exact_match)
When ever the AI Scanner is reloaded, all infos become invalid.
bool IsRandom() const
Is the current Script a randomly chosen Script?
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
bool HasScript(const struct ContentInfo *ci, bool md5sum)
Check whether we have a script with the exact characteristics as ci.
static void Save(CompanyID company)
Save data from an AI to a savegame.
static uint GetTick()
Get the current AI tick.
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
static void GameLoop()
Called every game-tick to let AIs do something.
static size_t GetPoolSize()
Returns first unused index.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
int GetSetting(const char *name) const
Get the value of a setting for this config.
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
First company, same as owner.
All static information from an AI library like name, version, etc.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
class AIInfo * FindInfo(const char *nameParam, int versionParam, bool force_exact_match)
Check if we have an AI by name and version available in our list.
void Initialize(class AIInfo *info)
Initialize the AI and prepare it for its first run.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
static void Load(CompanyID company, int version)
Load data for an AI from a savegame.
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Maximum number of companies.
void RescanDir()
Rescan the script dir.
static bool HasAI(const struct ContentInfo *ci, bool md5sum)
Wrapper function for AIScanner::HasAI.
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
const char * name
Full name of the script.
#define DEBUG(name, level,...)
Output a line of debugging information.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static void SaveEmpty()
Don't save any data in the savegame.
All static information from an AI like name, version, etc.
CompanyByte _current_company
Company currently doing an action.
class AILibrary * FindLibrary(const char *library, int version)
Find a library in the pool.
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
static uint frame_counter
Tick counter for the AI code.
static void KillAll()
Kill any and all AIs we manage.
static void Rescan()
Rescans all searchpaths for available AIs.
static class AILibrary * FindLibrary(const char *library, int version)
Wrapper function for AIScanner::FindLibrary.
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored...
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
char * GetConsoleList(char *p, const char *last, bool newest_only) const
Get the list of registered scripts to print on the console.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Scan for AIs and its libraries.
bool _network_server
network-server is active
class AIConfig * ai_config[MAX_COMPANIES]
settings per company
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
bool ai_in_multiplayer
so we allow AIs in multiplayer
AI settings; Window numbers:
byte competitor_speed
the speed at which the AI builds
static bool CanStartNew()
Is it possible to start a new AI company?
void Restore()
Restore the variable.
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
Owner
Enum for all companies/owners.
AIInfo keeps track of all information of an AI, like Author, Description, ...
static void LoadEmpty()
Load and discard data from a savegame.
void Load(int version)
Load data from a savegame and store it on the stack.
class AIInfo * SelectRandomAI() const
Select a random AI.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Get the Script config from the current game.
Container for all important information about a piece of content.
void GameLoop()
Run the GameLoop of a script.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...