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

OpenTTD Source 14.1

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
31 static void StartNew(CompanyID company);
32
36 static void GameLoop();
37
41 static uint GetTick();
42
48 static void Stop(CompanyID company);
49
57 static void Pause(CompanyID company);
58
66 static void Unpause(CompanyID company);
67
74 static bool IsPaused(CompanyID company);
75
79 static void KillAll();
80
84 static void Initialize();
85
90 static void Uninitialize(bool keepConfig);
91
96 static void ResetConfig();
97
101 static void NewEvent(CompanyID company, ScriptEvent *event);
102
106 static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company = MAX_COMPANIES);
107
111 static void Save(CompanyID company);
112
114 static void GetConsoleList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only);
116 static void GetConsoleLibraryList(std::back_insert_iterator<std::string> &output_iterator);
118 static const ScriptInfoList *GetInfoList();
120 static const ScriptInfoList *GetUniqueInfoList();
122 static class AIInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
124 static class AILibrary *FindLibrary(const std::string &library, int version);
125
130 static void Rescan();
131
133 static AIScannerInfo *GetScannerInfo();
135 static AIScannerLibrary *GetScannerLibrary();
136
138 static bool HasAI(const struct ContentInfo *ci, bool md5sum);
139 static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
140 private:
141 static uint frame_counter;
142 static class AIScannerInfo *scanner_info;
143 static class AIScannerLibrary *scanner_library;
144 };
145
146 #endif /* AI_HPP */
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition: ai_core.cpp:180
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:365
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
AI::StartNew
static void StartNew(CompanyID company)
Start a new AI company.
Definition: ai_core.cpp:36
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:138
AI::GetConsoleLibraryList
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition: ai_core.cpp:311
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:244
AI::scanner_library
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition: ai.hpp:143
AI::Save
static void Save(CompanyID company)
Save data from an AI to a savegame.
Definition: ai_core.cpp:288
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:52
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:125
AI::GetScannerLibrary
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
Definition: ai_core.cpp:370
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:166
AI::scanner_info
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
Definition: ai.hpp:142
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:355
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:269
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:316
AIScannerInfo
Definition: ai_scanner.hpp:15
AI::GetTick
static uint GetTick()
Get the current AI tick.
Definition: ai_core.cpp:102
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition: ai_core.cpp:74
AI::FindLibrary
static class AILibrary * FindLibrary(const std::string &library, int version)
Wrapper function for AIScanner::FindLibrary.
Definition: ai_core.cpp:331
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition: ai_core.cpp:146
AI::frame_counter
static uint frame_counter
Tick counter for the AI code.
Definition: ai.hpp:141
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition: ai_core.cpp:156
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:321
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:306
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:326
AI::Stop
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition: ai_core.cpp:107
AI::Rescan
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:336
AI::ResetConfig
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition: ai_core.cpp:207