OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../core/backup_type.hpp"
12 #include "../core/bitmath_func.hpp"
13 #include "../company_base.h"
14 #include "../company_func.h"
15 #include "../network/network.h"
16 #include "../window_func.h"
17 #include "../framerate_type.h"
24 #include "../safeguards.h"
44 AIInfo *info = config->GetInfo();
45 if (info ==
nullptr || (rerandomise_ai && config->
IsRandom())) {
47 assert(info !=
nullptr);
57 assert(c->ai_instance ==
nullptr);
81 cur_company.
Change(c->index);
82 c->ai_instance->GameLoop();
110 delete c->ai_instance;
111 c->ai_instance =
nullptr;
112 c->ai_info =
nullptr;
144 bool paused =
Company::Get(company)->ai_instance->IsPaused();
282 assert(c !=
nullptr && c->ai_instance !=
nullptr);
285 c->ai_instance->
Save();
296 assert(c !=
nullptr && c->ai_instance !=
nullptr);
372 bool AI::HasAILibrary(
const ContentInfo *ci,
bool md5sum)
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
static class AILibrary * FindLibrary(const char *library, int version)
Wrapper function for AIScanner::FindLibrary.
void Change(const U &new_value)
Change the value of the variable.
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-...
class AIConfig * ai_config[MAX_COMPANIES]
settings per company
static Titem * Get(size_t index)
Returns Titem with given index.
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
void Save()
Call the script Save function and save all data in the savegame.
Class to backup a specific variable and restore it later.
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
static class AIInfo * FindInfo(const char *name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
bool _network_server
network-server is active
static void Load(CompanyID company, int version)
Load data for an AI from a savegame.
static int GetStartNextTime()
Get the number of days before the next AI should start.
DifficultySettings difficulty
settings related to the difficulty
void Initialize(class AIInfo *info)
Initialize the AI and prepare it for its first run.
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.
static bool CanStartNew()
Is it possible to start a new AI company?
byte competitor_speed
the speed at which the AI builds
Owner
Enum for all companies/owners.
char * GetConsoleList(char *p, const char *last, bool newest_only) const
Get the list of registered scripts to print on the console.
void RescanDir()
Rescan the script dir.
PerformanceElement
Elements of game performance that can be measured.
const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
int version
Version of the script.
@ COMPANY_FIRST
First company, same as owner.
static void Unpause(CompanyID company)
Resume execution of the AI.
static size_t GetPoolSize()
Returns first unused index.
class AILibrary * FindLibrary(const char *library, int version)
Find a library in the pool.
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
static void Save(CompanyID company)
Save data from an AI to a savegame.
Container for all important information about a piece of content.
static void SaveEmpty()
Don't save any data in the savegame.
const char * GetName() const
Get the name of the Script.
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
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.
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
static void Initialize()
Initialize the AI system.
bool IsRandom() const
Is the current Script a randomly chosen Script?
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
@ MAX_COMPANIES
Maximum number of companies.
static bool HasAI(const struct ContentInfo *ci, bool md5sum)
Wrapper function for AIScanner::HasAI.
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
bool _networking
are we in networking mode?
static uint GetTick()
Get the current AI tick.
bool _network_dedicated
are we a dedicated server?
static void GameLoop()
Called every game-tick to let AIs do something.
static void LoadEmpty()
Load and discard data from a savegame.
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
static uint frame_counter
Tick counter for the AI code.
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
AISettings ai
what may the AI do?
CompanyID _current_company
Company currently doing an action.
@ WC_AI_DEBUG
AI debug window; Window numbers:
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
bool HasScript(const struct ContentInfo *ci, bool md5sum)
Check whether we have a script with the exact characteristics as ci.
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored.
const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
static void KillAll()
Kill any and all AIs we manage.
void Restore()
Restore the variable.
@ WC_AI_LIST
AI list; Window numbers:
@ AI
Scan for AIs and its libraries.
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...
@ WC_AI_SETTINGS
AI settings; Window numbers:
static const int DAYS_IN_YEAR
days per year
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
All static information from an AI like name, version, etc.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Runtime information about an AI like a pointer to the squirrel vm and the current state.
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.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
void Load(int version)
Load data from a savegame and store it on the stack.
const char * GetName() const
Get the Name of the script.
@ PFE_AI0
AI execution for player slot 1.
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
const char * name
Full name of the script.
static void Rescan()
Rescans all searchpaths for available AIs.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
@ SSS_FORCE_GAME
Get the Script config from the current game.
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
int GetSetting(const char *name) const override
Get the value of a setting for this config.
bool ai_in_multiplayer
so we allow AIs in multiplayer
class AIInfo * SelectRandomAI() const
Select a random AI.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
bool ResetInfo(bool force_exact_match)
When ever the AI Scanner is reloaded, all infos become invalid.