Fix: Don't allow right-click to close world generation progress window. (#13084)
[openttd-github.git] / src / ai / ai.hpp
blob5750ae6c53dc557d948308b2960ba46b4df95aae
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 */
8 /** @file ai.hpp Base functions for all AIs. */
10 #ifndef AI_HPP
11 #define AI_HPP
13 #include "../script/api/script_event_types.hpp"
14 #include "ai_scanner.hpp"
16 /**
17 * Main AI class. Contains all functions needed to start, stop, save and load AIs.
19 class AI {
20 public:
21 /**
22 * Is it possible to start a new AI company?
23 * @return True if a new AI company can be started.
25 static bool CanStartNew();
27 /**
28 * Start a new AI company.
29 * @param company At which slot the AI company should start.
31 static void StartNew(CompanyID company);
33 /**
34 * Called every game-tick to let AIs do something.
36 static void GameLoop();
38 /**
39 * Get the current AI tick.
41 static uint GetTick();
43 /**
44 * Stop a company to be controlled by an AI.
45 * @param company The company from which the AI needs to detach.
46 * @pre Company::IsValidAiID(company)
48 static void Stop(CompanyID company);
50 /**
51 * Suspend the AI and then pause execution of the script. The script
52 * will not be resumed from its suspended state until the script has
53 * been unpaused.
54 * @param company The company for which the AI should be paused.
55 * @pre Company::IsValidAiID(company)
57 static void Pause(CompanyID company);
59 /**
60 * Resume execution of the AI. This function will not actually execute
61 * the script, but set a flag so that the script is executed my the usual
62 * mechanism that executes the script.
63 * @param company The company for which the AI should be unpaused.
64 * @pre Company::IsValidAiID(company)
66 static void Unpause(CompanyID company);
68 /**
69 * Checks if the AI is paused.
70 * @param company The company for which to check if the AI is paused.
71 * @pre Company::IsValidAiID(company)
72 * @return true if the AI is paused, otherwise false.
74 static bool IsPaused(CompanyID company);
76 /**
77 * Kill any and all AIs we manage.
79 static void KillAll();
81 /**
82 * Initialize the AI system.
84 static void Initialize();
86 /**
87 * Uninitialize the AI system
88 * @param keepConfig Should we keep AIConfigs, or can we free that memory?
90 static void Uninitialize(bool keepConfig);
92 /**
93 * Reset all AIConfigs, and make them reload their AIInfo.
94 * If the AIInfo could no longer be found, an error is reported to the user.
96 static void ResetConfig();
98 /**
99 * Queue a new event for an AI.
101 static void NewEvent(CompanyID company, ScriptEvent *event);
104 * Broadcast a new event to all active AIs.
106 static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company = MAX_COMPANIES);
109 * Save data from an AI to a savegame.
111 static void Save(CompanyID company);
113 /** Wrapper function for AIScanner::GetAIConsoleList */
114 static void GetConsoleList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only);
115 /** Wrapper function for AIScanner::GetAIConsoleLibraryList */
116 static void GetConsoleLibraryList(std::back_insert_iterator<std::string> &output_iterator);
117 /** Wrapper function for AIScanner::GetAIInfoList */
118 static const ScriptInfoList *GetInfoList();
119 /** Wrapper function for AIScanner::GetUniqueAIInfoList */
120 static const ScriptInfoList *GetUniqueInfoList();
121 /** Wrapper function for AIScanner::FindInfo */
122 static class AIInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
123 /** Wrapper function for AIScanner::FindLibrary */
124 static class AILibrary *FindLibrary(const std::string &library, int version);
127 * Rescans all searchpaths for available AIs. If a used AI is no longer
128 * found it is removed from the config.
130 static void Rescan();
132 /** Gets the ScriptScanner instance that is used to find AIs */
133 static AIScannerInfo *GetScannerInfo();
134 /** Gets the ScriptScanner instance that is used to find AI Libraries */
135 static AIScannerLibrary *GetScannerLibrary();
137 /** Wrapper function for AIScanner::HasAI */
138 static bool HasAI(const struct ContentInfo *ci, bool md5sum);
139 static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
140 private:
141 static uint frame_counter; ///< Tick counter for the AI code
142 static class AIScannerInfo *scanner_info; ///< ScriptScanner instance that is used to find AIs
143 static class AIScannerLibrary *scanner_library; ///< ScriptScanner instance that is used to find AI Libraries
146 #endif /* AI_HPP */