OpenTTD
ai.hpp
Go to the documentation of this file.
1 /* $Id: ai.hpp 24900 2013-01-08 22:46:42Z planetmaker $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef AI_HPP
13 #define AI_HPP
14 
15 #include "../script/api/script_event_types.hpp"
16 #include "../core/string_compare_type.hpp"
17 #include "ai_scanner.hpp"
18 #include <map>
19 
21 typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList;
22 
26 class AI {
27 public:
31  enum StartNext {
32  START_NEXT_EASY = DAYS_IN_YEAR * 2,
33  START_NEXT_MEDIUM = DAYS_IN_YEAR,
34  START_NEXT_HARD = DAYS_IN_YEAR / 2,
35  START_NEXT_MIN = 1,
36  START_NEXT_MAX = 3600,
37  START_NEXT_DEVIATION = 60,
38  };
39 
44  static bool CanStartNew();
45 
51  static void StartNew(CompanyID company, bool rerandomise_ai = true);
52 
56  static void GameLoop();
57 
61  static uint GetTick();
62 
68  static void Stop(CompanyID company);
69 
77  static void Pause(CompanyID company);
78 
86  static void Unpause(CompanyID company);
87 
94  static bool IsPaused(CompanyID company);
95 
99  static void KillAll();
100 
104  static void Initialize();
105 
110  static void Uninitialize(bool keepConfig);
111 
116  static void ResetConfig();
117 
121  static void NewEvent(CompanyID company, ScriptEvent *event);
122 
126  static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company = MAX_COMPANIES);
127 
131  static void Save(CompanyID company);
132 
136  static void Load(CompanyID company, int version);
137 
141  static int GetStartNextTime();
142 
144  static char *GetConsoleList(char *p, const char *last, bool newest_only = false);
146  static char *GetConsoleLibraryList(char *p, const char *last);
148  static const ScriptInfoList *GetInfoList();
150  static const ScriptInfoList *GetUniqueInfoList();
152  static class AIInfo *FindInfo(const char *name, int version, bool force_exact_match);
154  static class AILibrary *FindLibrary(const char *library, int version);
155 
160  static void Rescan();
161 
163  static AIScannerInfo *GetScannerInfo();
166 
167 #if defined(ENABLE_NETWORK)
168 
169  static bool HasAI(const struct ContentInfo *ci, bool md5sum);
170  static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
171 #endif
172 private:
173  static uint frame_counter;
174  static class AIScannerInfo *scanner_info;
176 };
177 
178 #endif /* AI_HPP */
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
Definition: ai_core.cpp:37
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:31
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:327
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition: ai_core.cpp:131
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:317
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
Definition: ai.hpp:21
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition: ai_core.cpp:139
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition: ai_core.cpp:118
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
Definition: ai_core.cpp:385
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:160
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:258
static int GetStartNextTime()
Get the number of days before the next AI should start.
Definition: ai_core.cpp:306
static class AIInfo * FindInfo(const char *name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition: ai_core.cpp:337
declarations of the class for AI scanner
StartNext
The default months AIs start after each other.
Definition: ai.hpp:31
Main AI class.
Definition: ai.hpp:26
static void Save(CompanyID company)
Save data from an AI to a savegame.
Definition: ai_core.cpp:277
static uint GetTick()
Get the current AI tick.
Definition: ai_core.cpp:96
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition: ai_core.cpp:201
static void GameLoop()
Called every game-tick to let AIs do something.
Definition: ai_core.cpp:68
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition: ai_core.cpp:174
All static information from an AI library like name, version, etc.
Definition: ai_info.hpp:60
static void Load(CompanyID company, int version)
Load data for an AI from a savegame.
Definition: ai_core.cpp:291
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition: ai_core.cpp:101
Maximum number of companies.
Definition: company_type.h:25
static bool HasAI(const struct ContentInfo *ci, bool md5sum)
Wrapper function for AIScanner::HasAI.
Definition: ai_core.cpp:368
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:233
const char * name
Full name of the script.
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:18
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition: ai.hpp:175
static uint frame_counter
Tick counter for the AI code.
Definition: ai.hpp:173
static void KillAll()
Kill any and all AIs we manage.
Definition: ai_core.cpp:149
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:347
static class AILibrary * FindLibrary(const char *library, int version)
Wrapper function for AIScanner::FindLibrary.
Definition: ai_core.cpp:342
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition: ai_core.cpp:332
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition: ai_core.cpp:322
static bool CanStartNew()
Is it possible to start a new AI company?
Definition: ai_core.cpp:31
Owner
Enum for all companies/owners.
Definition: company_type.h:20
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
Definition: ai.hpp:174
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Definition: ai_core.cpp:380
Container for all important information about a piece of content.
Definition: tcp_content.h:58