OpenTTD Source
20241125-master-g5b02f51e17
|
#include <ai.hpp>
Static Public Member Functions | |
static bool | CanStartNew () |
Is it possible to start a new AI company? More... | |
static void | StartNew (CompanyID company) |
Start a new AI company. More... | |
static void | GameLoop () |
Called every game-tick to let AIs do something. | |
static uint | GetTick () |
Get the current AI tick. | |
static void | Stop (CompanyID company) |
Stop a company to be controlled by an AI. More... | |
static void | Pause (CompanyID company) |
Suspend the AI and then pause execution of the script. More... | |
static void | Unpause (CompanyID company) |
Resume execution of the AI. More... | |
static bool | IsPaused (CompanyID company) |
Checks if the AI is paused. More... | |
static void | KillAll () |
Kill any and all AIs we manage. | |
static void | Initialize () |
Initialize the AI system. | |
static void | Uninitialize (bool keepConfig) |
Uninitialize the AI system. More... | |
static void | ResetConfig () |
Reset all AIConfigs, and make them reload their AIInfo. More... | |
static void | NewEvent (CompanyID company, ScriptEvent *event) |
Queue a new event for an AI. | |
static void | BroadcastNewEvent (ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES) |
Broadcast a new event to all active AIs. | |
static void | Save (CompanyID company) |
Save data from an AI to a savegame. | |
static void | GetConsoleList (std::back_insert_iterator< std::string > &output_iterator, bool newest_only) |
Wrapper function for AIScanner::GetAIConsoleList. | |
static void | GetConsoleLibraryList (std::back_insert_iterator< std::string > &output_iterator) |
Wrapper function for AIScanner::GetAIConsoleLibraryList. | |
static const ScriptInfoList * | GetInfoList () |
Wrapper function for AIScanner::GetAIInfoList. | |
static const ScriptInfoList * | GetUniqueInfoList () |
Wrapper function for AIScanner::GetUniqueAIInfoList. | |
static class AIInfo * | FindInfo (const std::string &name, int version, bool force_exact_match) |
Wrapper function for AIScanner::FindInfo. | |
static class AILibrary * | FindLibrary (const std::string &library, int version) |
Wrapper function for AIScanner::FindLibrary. | |
static void | Rescan () |
Rescans all searchpaths for available AIs. More... | |
static AIScannerInfo * | GetScannerInfo () |
Gets the ScriptScanner instance that is used to find AIs. | |
static AIScannerLibrary * | GetScannerLibrary () |
Gets the ScriptScanner instance that is used to find AI Libraries. | |
static bool | HasAI (const struct ContentInfo *ci, bool md5sum) |
Wrapper function for AIScanner::HasAI. More... | |
static bool | HasAILibrary (const ContentInfo *ci, bool md5sum) |
Static Private Attributes | |
static uint | frame_counter = 0 |
Tick counter for the AI code. | |
static class AIScannerInfo * | scanner_info = nullptr |
ScriptScanner instance that is used to find AIs. | |
static class AIScannerLibrary * | scanner_library = nullptr |
ScriptScanner instance that is used to find AI Libraries. | |
Main AI class.
Contains all functions needed to start, stop, save and load AIs.
|
static |
Is it possible to start a new AI company?
Definition at line 30 of file ai_core.cpp.
References _network_server, _networking, _settings_game, GameSettings::ai, and AISettings::ai_in_multiplayer.
|
static |
Wrapper function for AIScanner::HasAI.
Check whether we have an AI (library) with the exact characteristics as ci.
ci | the characteristics to search on (shortname and md5sum) |
md5sum | whether to check the MD5 checksum |
Definition at line 345 of file ai_core.cpp.
References ScriptScanner::HasScript(), and scanner_info.
Referenced by ClientNetworkContentSocketHandler::Receive_SERVER_INFO().
|
static |
Checks if the AI is paused.
company | The company for which to check if the AI is paused. |
Definition at line 145 of file ai_core.cpp.
References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), and Backup< T >::Restore().
|
static |
Suspend the AI and then pause execution of the script.
The script will not be resumed from its suspended state until the script has been unpaused.
company | The company for which the AI should be paused. |
Definition at line 124 of file ai_core.cpp.
References _current_company, _network_dedicated, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), and Backup< T >::Restore().
Referenced by ScriptDebugWindow::OnInvalidateData().
|
static |
Rescans all searchpaths for available AIs.
If a used AI is no longer found it is removed from the config.
Definition at line 326 of file ai_core.cpp.
References TarScanner::AI, TarScanner::DoScan(), InvalidateWindowClassesData(), InvalidateWindowData(), ScriptScanner::RescanDir(), ResetConfig(), scanner_info, scanner_library, SetWindowClassesDirty(), WC_SCRIPT_DEBUG, WC_SCRIPT_LIST, and WC_SCRIPT_SETTINGS.
Referenced by Uninitialize().
|
static |
Reset all AIConfigs, and make them reload their AIInfo.
If the AIInfo could no longer be found, an error is reported to the user.
Definition at line 206 of file ai_core.cpp.
References _settings_game, _settings_newgame, GameSettings::ai_config, ScriptConfig::Change(), COMPANY_FIRST, Debug, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), ScriptConfig::GetName(), ScriptConfig::HasScript(), Company::IsValidAiID(), MAX_COMPANIES, AIConfig::ResetInfo(), StartNew(), and Stop().
Referenced by Rescan().
|
static |
Start a new AI company.
company | At which slot the AI company should start. |
Definition at line 36 of file ai_core.cpp.
References _current_company, _network_server, _networking, ScriptConfig::AnchorUnchangeableSettings(), ScriptConfig::Change(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), AIConfig::GetConfig(), ScriptInfo::GetName(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Backup< T >::Restore(), scanner_info, AIScannerInfo::SelectRandomAI(), ScriptConfig::SSS_FORCE_GAME, and WC_SCRIPT_DEBUG.
Referenced by ResetConfig(), and StartScripts().
|
static |
Stop a company to be controlled by an AI.
company | The company from which the AI needs to detach. |
Definition at line 107 of file ai_core.cpp.
References _current_company, _network_server, _networking, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), InvalidateWindowClassesData(), PFE_AI0, Backup< T >::Restore(), PerformanceMeasurer::SetInactive(), and WC_SCRIPT_DEBUG.
Referenced by KillAll(), and ResetConfig().
|
static |
Uninitialize the AI system.
keepConfig | Should we keep AIConfigs, or can we free that memory? |
Definition at line 179 of file ai_core.cpp.
References _settings_game, _settings_newgame, GameSettings::ai_config, COMPANY_FIRST, KillAll(), MAX_COMPANIES, Rescan(), scanner_info, and scanner_library.
Referenced by Initialize(), and AfterNewGRFScan::OnNewGRFsScanned().
|
static |
Resume execution of the AI.
This function will not actually execute the script, but set a flag so that the script is executed my the usual mechanism that executes the script.
company | The company for which the AI should be unpaused. |
Definition at line 137 of file ai_core.cpp.
References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), and Backup< T >::Restore().