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

OpenTTD Source 15.3

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
10#ifndef AI_HPP
11#define AI_HPP
12
13#include "../script/api/script_event_types.hpp"
14#include "ai_scanner.hpp"
15
19 class 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 = CompanyID::Invalid());
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
133 static AIScannerInfo *GetScannerInfo();
135 static AIScannerLibrary *GetScannerLibrary();
136
138 static bool HasAI(const ContentInfo &ci, bool md5sum);
139 static bool HasAILibrary(const ContentInfo &ci, bool md5sum);
140private:
141 static uint frame_counter;
142 static std::unique_ptr<AIScannerInfo> scanner_info;
143 static std::unique_ptr<AIScannerLibrary> scanner_library;
144};
145
146#endif /* AI_HPP */
ai_scanner.hpp
declarations of the class for AI scanner
AIInfo
All static information from an AI like name, version, etc.
Definition ai_info.hpp:16
AILibrary
All static information from an AI library like name, version, etc.
Definition ai_info.hpp:60
AIScannerInfo
Definition ai_scanner.hpp:15
AIScannerLibrary
Definition ai_scanner.hpp:53
AI
Main AI class.
Definition ai.hpp:19
AI::GetTick
static uint GetTick()
Get the current AI tick.
Definition ai_core.cpp:102
AI::scanner_library
static std::unique_ptr< AIScannerLibrary > scanner_library
ScriptScanner instance that is used to find AI Libraries.
Definition ai.hpp:143
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition ai_core.cpp:179
AI::GetScannerLibrary
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
Definition ai_core.cpp:352
AI::Pause
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition ai_core.cpp:124
AI::GetConsoleLibraryList
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition ai_core.cpp:293
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition ai_core.cpp:165
AI::GetConsoleList
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
Definition ai_core.cpp:288
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=CompanyID::Invalid())
Broadcast a new event to all active AIs.
Definition ai_core.cpp:255
AI::scanner_info
static std::unique_ptr< AIScannerInfo > scanner_info
ScriptScanner instance that is used to find AIs.
Definition ai.hpp:142
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition ai_core.cpp:74
AI::CanStartNew
static bool CanStartNew()
Is it possible to start a new AI company?
Definition ai_core.cpp:30
AI::StartNew
static void StartNew(CompanyID company)
Start a new AI company.
Definition ai_core.cpp:36
AI::FindLibrary
static class AILibrary * FindLibrary(const std::string &library, int version)
Wrapper function for AIScanner::FindLibrary.
Definition ai_core.cpp:313
AI::ResetConfig
static void ResetConfig()
Reset all AIConfigs, and make them reload their AIInfo.
Definition ai_core.cpp:198
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition ai_core.cpp:235
AI::GetScannerInfo
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
Definition ai_core.cpp:347
AI::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition ai_core.cpp:303
AI::HasAI
static bool HasAI(const ContentInfo &ci, bool md5sum)
Wrapper function for AIScanner::HasAI.
Definition ai_core.cpp:337
AI::Rescan
static void Rescan()
Rescans all searchpaths for available AIs.
Definition ai_core.cpp:318
AI::frame_counter
static uint frame_counter
Tick counter for the AI code.
Definition ai.hpp:141
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition ai_core.cpp:145
AI::Save
static void Save(CompanyID company)
Save data from an AI to a savegame.
Definition ai_core.cpp:270
AI::Unpause
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition ai_core.cpp:137
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition ai_core.cpp:155
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition ai_core.cpp:298
AI::FindInfo
static class AIInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition ai_core.cpp:308
OrderDepotAction::Stop
@ Stop
Go to the depot and stop there.
ScriptInfoList
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Definition script_scanner.hpp:16
ContentInfo
Container for all important information about a piece of content.
Definition tcp_content_type.h:56
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >