OpenTTD Source  1.11.2
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 void Load(CompanyID company, int version);
135 
139  static int GetStartNextTime();
140 
142  static char *GetConsoleList(char *p, const char *last, bool newest_only = false);
144  static char *GetConsoleLibraryList(char *p, const char *last);
146  static const ScriptInfoList *GetInfoList();
148  static const ScriptInfoList *GetUniqueInfoList();
150  static class AIInfo *FindInfo(const char *name, int version, bool force_exact_match);
152  static class AILibrary *FindLibrary(const char *library, int version);
153 
158  static void Rescan();
159 
161  static AIScannerInfo *GetScannerInfo();
164 
166  static bool HasAI(const struct ContentInfo *ci, bool md5sum);
167  static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
168 private:
169  static uint frame_counter;
170  static class AIScannerInfo *scanner_info;
172 };
173 
174 #endif /* AI_HPP */
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition: ai_core.cpp:175
AI::FindLibrary
static class AILibrary * FindLibrary(const char *library, int version)
Wrapper function for AIScanner::FindLibrary.
Definition: ai_core.cpp:343
AI::GetScannerInfo
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Definition: ai_core.cpp:377
AI::FindInfo
static class AIInfo * FindInfo(const char *name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition: ai_core.cpp:338
AIScannerLibrary
Definition: ai_scanner.hpp:53
AI::Load
static void Load(CompanyID company, int version)
Load data for an AI from a savegame.
Definition: ai_core.cpp:292
AI::GetStartNextTime
static int GetStartNextTime()
Get the number of days before the next AI should start.
Definition: ai_core.cpp:307
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:133
AI::GetConsoleLibraryList
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition: ai_core.cpp:323
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:234
AI::scanner_library
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition: ai.hpp:171
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:278
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:49
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:120
AI::GetScannerLibrary
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
Definition: ai_core.cpp:382
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:161
AI::scanner_info
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
Definition: ai.hpp:170
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:367
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:259
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:328
AIScannerInfo
Definition: ai_scanner.hpp:15
AI::GetTick
static uint GetTick()
Get the current AI tick.
Definition: ai_core.cpp:97
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition: ai_core.cpp:67
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition: ai_core.cpp:141
AI::frame_counter
static uint frame_counter
Tick counter for the AI code.
Definition: ai.hpp:169
AI::GetConsoleList
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:318
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition: ai_core.cpp:151
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_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:333
AI::Stop
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition: ai_core.cpp:102
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:348
AI::ResetConfig
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition: ai_core.cpp:202