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

OpenTTD Source 13.2.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 "../core/string_compare_type.hpp"
15 #include "ai_scanner.hpp"
16 #include <map>
17
19 typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList;
20
24 class AI {
25 public:
29 enum StartNext {
30 START_NEXT_EASY = DAYS_IN_YEAR * 2,
31 START_NEXT_MEDIUM = DAYS_IN_YEAR,
32 START_NEXT_HARD = DAYS_IN_YEAR / 2,
33 START_NEXT_MIN = 0,
34 START_NEXT_MAX = 3600,
35 START_NEXT_DEVIATION = 60,
36 };
37
42 static bool CanStartNew();
43
49 static void StartNew(CompanyID company, bool rerandomise_ai = true);
50
54 static void GameLoop();
55
59 static uint GetTick();
60
66 static void Stop(CompanyID company);
67
75 static void Pause(CompanyID company);
76
84 static void Unpause(CompanyID company);
85
92 static bool IsPaused(CompanyID company);
93
97 static void KillAll();
98
102 static void Initialize();
103
108 static void Uninitialize(bool keepConfig);
109
114 static void ResetConfig();
115
119 static void NewEvent(CompanyID company, ScriptEvent *event);
120
124 static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company = MAX_COMPANIES);
125
129 static void Save(CompanyID company);
130
134 static int GetStartNextTime();
135
137 static std::string GetConsoleList(bool newest_only = false);
139 static std::string GetConsoleLibraryList();
141 static const ScriptInfoList *GetInfoList();
143 static const ScriptInfoList *GetUniqueInfoList();
145 static class AIInfo *FindInfo(const char *name, int version, bool force_exact_match);
147 static class AILibrary *FindLibrary(const char *library, int version);
148
153 static void Rescan();
154
156 static AIScannerInfo *GetScannerInfo();
158 static AIScannerLibrary *GetScannerLibrary();
159
161 static bool HasAI(const struct ContentInfo *ci, bool md5sum);
162 static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
163 private:
164 static uint frame_counter;
165 static class AIScannerInfo *scanner_info;
166 static class AIScannerLibrary *scanner_library;
167 };
168
169 #endif /* AI_HPP */
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition: ai_core.cpp:177
AI::FindLibrary
static class AILibrary * FindLibrary(const char *library, int version)
Wrapper function for AIScanner::FindLibrary.
Definition: ai_core.cpp:330
AI::GetScannerInfo
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Definition: ai_core.cpp:364
AI::FindInfo
static class AIInfo * FindInfo(const char *name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition: ai_core.cpp:325
AIScannerLibrary
Definition: ai_scanner.hpp:53
AI::GetStartNextTime
static int GetStartNextTime()
Get the number of days before the next AI should start.
Definition: ai_core.cpp:294
AI::CanStartNew
static bool CanStartNew()
Is it possible to start a new AI company?
Definition: ai_core.cpp:30
AI::StartNext
StartNext
The default months AIs start after each other.
Definition: ai.hpp:29
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:161
AI::Unpause
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition: ai_core.cpp:135
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:236
AI::scanner_library
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition: ai.hpp:166
ScriptInfoList
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
Definition: ai.hpp:19
AI::Save
static void Save(CompanyID company)
Save data from an AI to a savegame.
Definition: ai_core.cpp:280
AI::GetConsoleLibraryList
static std::string GetConsoleLibraryList()
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition: ai_core.cpp:310
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:50
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:58
AI::Pause
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition: ai_core.cpp:122
AI::GetScannerLibrary
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
Definition: ai_core.cpp:369
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:163
AI::scanner_info
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
Definition: ai.hpp:165
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:354
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:261
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:315
AIScannerInfo
Definition: ai_scanner.hpp:15
AI::GetTick
static uint GetTick()
Get the current AI tick.
Definition: ai_core.cpp:99
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition: ai_core.cpp:69
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition: ai_core.cpp:143
AI::frame_counter
static uint frame_counter
Tick counter for the AI code.
Definition: ai.hpp:164
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition: ai_core.cpp:153
DAYS_IN_YEAR
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:29
AI
Main AI class.
Definition: ai.hpp:24
AI::GetConsoleList
static std::string GetConsoleList(bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:305
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:320
AI::Stop
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition: ai_core.cpp:104
ScriptInfo::name
const char * name
Full name of the script.
Definition: script_info.hpp:156
AI::Rescan
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:335
AI::ResetConfig
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition: ai_core.cpp:204