OpenTTD Source: src/ai/ai.hpp Source File

OpenTTD Source 14.0-beta1

ai.hpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef AI_HPP
11 #define AI_HPP
12
13 #include "../script/api/script_event_types.hpp"
14 #include "ai_scanner.hpp"
15
19 class AI {
20 public:
25 static bool CanStartNew();
26
32 static void StartNew(CompanyID company, bool rerandomise_ai = true);
33
37 static void GameLoop();
38
42 static uint GetTick();
43
49 static void Stop(CompanyID company);
50
58 static void Pause(CompanyID company);
59
67 static void Unpause(CompanyID company);
68
75 static bool IsPaused(CompanyID company);
76
80 static void KillAll();
81
85 static void Initialize();
86
91 static void Uninitialize(bool keepConfig);
92
97 static void ResetConfig();
98
102 static void NewEvent(CompanyID company, ScriptEvent *event);
103
107 static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company = MAX_COMPANIES);
108
112 static void Save(CompanyID company);
113
115 static void GetConsoleList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only);
117 static void GetConsoleLibraryList(std::back_insert_iterator<std::string> &output_iterator);
119 static const ScriptInfoList *GetInfoList();
121 static const ScriptInfoList *GetUniqueInfoList();
123 static class AIInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
125 static class AILibrary *FindLibrary(const std::string &library, int version);
126
131 static void Rescan();
132
134 static AIScannerInfo *GetScannerInfo();
136 static AIScannerLibrary *GetScannerLibrary();
137
139 static bool HasAI(const struct ContentInfo *ci, bool md5sum);
140 static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
141 private:
142 static uint frame_counter;
143 static class AIScannerInfo *scanner_info;
144 static class AIScannerLibrary *scanner_library;
145 };
146
147 #endif /* AI_HPP */
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition: ai_core.cpp:176
ScriptInfoList
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Definition: script_scanner.hpp:16
AI::GetScannerInfo
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Definition: ai_core.cpp:352
AIScannerLibrary
Definition: ai_scanner.hpp:53
AI::CanStartNew
static bool CanStartNew()
Is it possible to start a new AI company?
Definition: ai_core.cpp:30
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:152
AI::Unpause
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition: ai_core.cpp:134
AI::GetConsoleLibraryList
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition: ai_core.cpp:298
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:235
AI::scanner_library
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition: ai.hpp:144
AI::Save
static void Save(CompanyID company)
Save data from an AI to a savegame.
Definition: ai_core.cpp:279
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:52
AI::StartNew
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
Definition: ai_core.cpp:36
AILibrary
All static information from an AI library like name, version, etc.
Definition: ai_info.hpp:57
AI::Pause
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition: ai_core.cpp:121
AI::GetScannerLibrary
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
Definition: ai_core.cpp:357
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:162
AI::scanner_info
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
Definition: ai.hpp:143
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
AI::HasAI
static bool HasAI(const struct ContentInfo *ci, bool md5sum)
Wrapper function for AIScanner::HasAI.
Definition: ai_core.cpp:342
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:260
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:303
AIScannerInfo
Definition: ai_scanner.hpp:15
AI::GetTick
static uint GetTick()
Get the current AI tick.
Definition: ai_core.cpp:98
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition: ai_core.cpp:70
AI::FindLibrary
static class AILibrary * FindLibrary(const std::string &library, int version)
Wrapper function for AIScanner::FindLibrary.
Definition: ai_core.cpp:318
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition: ai_core.cpp:142
AI::frame_counter
static uint frame_counter
Tick counter for the AI code.
Definition: ai.hpp:142
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition: ai_core.cpp:152
ScriptInfo::name
std::string name
Full name of the script.
Definition: script_info.hpp:147
AI
Main AI class.
Definition: ai.hpp:19
ai_scanner.hpp
AIInfo
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
AI::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition: ai_core.cpp:308
AI::GetConsoleList
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:293
AI::FindInfo
static class AIInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition: ai_core.cpp:313
AI::Stop
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition: ai_core.cpp:103
AI::Rescan
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:323
AI::ResetConfig
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition: ai_core.cpp:203