OpenTTD Source 20260218-master-g2123fca5ea
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef AI_HPP
11#define AI_HPP
12
13#include "../script/api/script_event_types.hpp"
14#include "ai_scanner.hpp"
15
19class AI {
20public:
25 static bool CanStartNew();
26
31 static void StartNew(CompanyID company);
32
36 static void GameLoop();
37
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
104 static void NewEvent(CompanyID company, ScriptEvent *event);
105
111 static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company = CompanyID::Invalid());
112
117 static void Save(CompanyID company);
118
120 static void GetConsoleList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only);
122 static void GetConsoleLibraryList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only);
124 static const ScriptInfoList *GetInfoList();
126 static const ScriptInfoList *GetUniqueInfoList();
128 static class AIInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
130 static class AILibrary *FindLibrary(const std::string &library, int version);
131
136 static void Rescan();
137
142
144 static bool HasAI(const ContentInfo &ci, bool md5sum);
145 static bool HasAILibrary(const ContentInfo &ci, bool md5sum);
146private:
147 static uint frame_counter;
148 static std::unique_ptr<AIScannerInfo> scanner_info;
149 static std::unique_ptr<AIScannerLibrary> scanner_library;
150};
151
152#endif /* AI_HPP */
Declarations of the class for AI scanner.
All static information from an AI like name, version, etc.
Definition ai_info.hpp:16
All static information from an AI library like name, version, etc.
Definition ai_info.hpp:69
AI instantiation of a ScriptScanner.
AI instantiation of a ScriptScanner for libraries.
Main AI class.
Definition ai.hpp:19
static uint GetTick()
Get the current AI tick.
Definition ai_core.cpp:102
static std::unique_ptr< AIScannerLibrary > scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition ai.hpp:149
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
Definition ai_core.cpp:293
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition ai_core.cpp:179
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
Definition ai_core.cpp:366
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition ai_core.cpp:124
static void Initialize()
Initialize the AI system.
Definition ai_core.cpp:165
static bool HasAILibrary(const ContentInfo &ci, bool md5sum)
Check whether we have an AI library with the exact characteristics as ci.
Definition ai_core.cpp:348
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
Definition ai_core.cpp:288
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=CompanyID::Invalid())
Broadcast a new event to all active AIs.
Definition ai_core.cpp:255
static std::unique_ptr< AIScannerInfo > scanner_info
ScriptScanner instance that is used to find AIs.
Definition ai.hpp:148
static void GameLoop()
Called every game-tick to let AIs do something.
Definition ai_core.cpp:74
static bool CanStartNew()
Is it possible to start a new AI company?
Definition ai_core.cpp:30
static void StartNew(CompanyID company)
Start a new AI company.
Definition ai_core.cpp:36
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition ai_core.cpp:107
static class AILibrary * FindLibrary(const std::string &library, int version)
Find a library.
Definition ai_core.cpp:313
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition ai_core.cpp:198
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition ai_core.cpp:235
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Definition ai_core.cpp:357
static const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
Definition ai_core.cpp:303
static bool HasAI(const ContentInfo &ci, bool md5sum)
Wrapper function for AIScanner::HasAI.
Definition ai_core.cpp:337
static void Rescan()
Rescans all searchpaths for available AIs.
Definition ai_core.cpp:318
static uint frame_counter
Tick counter for the AI code.
Definition ai.hpp:147
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition ai_core.cpp:145
static void Save(CompanyID company)
Save data from an AI to a savegame.
Definition ai_core.cpp:270
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition ai_core.cpp:137
static void KillAll()
Kill any and all AIs we manage.
Definition ai_core.cpp:155
static const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
Definition ai_core.cpp:298
static class AIInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Finds the appropriate ScriptInfo for a given script name and version.
Definition ai_core.cpp:308
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Container for all important information about a piece of content.