OpenTTD Source 20241224-master-gf74b0cf984
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
19class AI {
20public:
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
136
138 static bool HasAI(const struct ContentInfo *ci, bool md5sum);
139 static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
140private:
141 static uint frame_counter;
144};
145
146#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:57
Main AI class.
Definition ai.hpp:19
static uint GetTick()
Get the current AI tick.
Definition ai_core.cpp:102
static class AIScannerInfo * scanner_info
ScriptScanner instance that is used to find AIs.
Definition ai.hpp:142
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:360
static bool HasAI(const struct ContentInfo *ci, bool md5sum)
Wrapper function for AIScanner::HasAI.
Definition ai_core.cpp:345
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition ai_core.cpp:124
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition ai_core.cpp:301
static void Initialize()
Initialize the AI system.
Definition ai_core.cpp:165
static class AIScannerLibrary * scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition ai.hpp:143
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
Definition ai_core.cpp:296
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 BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition ai_core.cpp:263
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)
Wrapper function for AIScanner::FindLibrary.
Definition ai_core.cpp:321
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition ai_core.cpp:206
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition ai_core.cpp:243
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Definition ai_core.cpp:355
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition ai_core.cpp:311
static void Rescan()
Rescans all searchpaths for available AIs.
Definition ai_core.cpp:326
static uint frame_counter
Tick counter for the AI code.
Definition ai.hpp:141
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:278
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()
Wrapper function for AIScanner::GetAIInfoList.
Definition ai_core.cpp:306
static class AIInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition ai_core.cpp:316
Owner
Enum for all companies/owners.
@ MAX_COMPANIES
Maximum number of companies.
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Container for all important information about a piece of content.