OpenTTD Source  20240919-master-gdf0233f4c2
ai_scanner.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_SCANNER_HPP
11 #define AI_SCANNER_HPP
12 
13 #include "../script/script_scanner.hpp"
14 
15 class AIScannerInfo : public ScriptScanner {
16 public:
17  AIScannerInfo();
18  ~AIScannerInfo();
19 
20  void Initialize() override;
21 
26  class AIInfo *SelectRandomAI() const;
27 
35  class AIInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
36 
40  void SetDummyAI(class AIInfo *info);
41 
42 protected:
43  std::string GetScriptName(ScriptInfo *info) override;
44  const char *GetFileName() const override { return PATHSEP "info.nut"; }
45  Subdirectory GetDirectory() const override { return AI_DIR; }
46  const char *GetScannerName() const override { return "AIs"; }
47  void RegisterAPI(class Squirrel *engine) override;
48 
49 private:
51 };
52 
54 public:
55  void Initialize() override;
56 
63  class AILibrary *FindLibrary(const std::string &library, int version);
64 
65 protected:
66  std::string GetScriptName(ScriptInfo *info) override;
67  const char *GetFileName() const override { return PATHSEP "library.nut"; }
68  Subdirectory GetDirectory() const override { return AI_LIBRARY_DIR; }
69  const char *GetScannerName() const override { return "AI Libraries"; }
70  void RegisterAPI(class Squirrel *engine) override;
71 };
72 
73 #endif /* AI_SCANNER_HPP */
AIScannerLibrary::GetFileName
const char * GetFileName() const override
Get the filename to scan for this type of script.
Definition: ai_scanner.hpp:67
ScriptScanner::engine
class Squirrel * engine
The engine we're scanning with.
Definition: script_scanner.hpp:87
AIScannerLibrary::FindLibrary
class AILibrary * FindLibrary(const std::string &library, int version)
Find a library in the pool.
Definition: ai_scanner.cpp:148
AIScannerInfo::GetFileName
const char * GetFileName() const override
Get the filename to scan for this type of script.
Definition: ai_scanner.hpp:44
AIScannerLibrary
Definition: ai_scanner.hpp:53
AIScannerInfo::GetDirectory
Subdirectory GetDirectory() const override
Get the directory to scan in.
Definition: ai_scanner.hpp:45
AIScannerLibrary::GetScriptName
std::string GetScriptName(ScriptInfo *info) override
Get the script name how to store the script in memory.
Definition: ai_scanner.cpp:137
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:152
Squirrel
Definition: squirrel.hpp:23
AI_DIR
@ AI_DIR
Subdirectory for all AI files.
Definition: fileio_type.h:126
AIScannerLibrary::GetDirectory
Subdirectory GetDirectory() const override
Get the directory to scan in.
Definition: ai_scanner.hpp:68
AIScannerInfo::info_dummy
AIInfo * info_dummy
The dummy AI.
Definition: ai_scanner.hpp:50
AILibrary
All static information from an AI library like name, version, etc.
Definition: ai_info.hpp:57
ScriptScanner
Scanner to help finding scripts.
Definition: script_scanner.hpp:19
AIScannerInfo
Definition: ai_scanner.hpp:15
AIScannerInfo::GetScriptName
std::string GetScriptName(ScriptInfo *info) override
Get the script name how to store the script in memory.
Definition: ai_scanner.cpp:51
AIScannerInfo::SetDummyAI
void SetDummyAI(class AIInfo *info)
Set the Dummy AI.
Definition: ai_scanner.cpp:41
AIScannerLibrary::GetScannerName
const char * GetScannerName() const override
Get the type of the script, in plural.
Definition: ai_scanner.hpp:69
ScriptInfo::name
std::string name
Full name of the script.
Definition: script_info.hpp:147
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:115
AI_LIBRARY_DIR
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
Definition: fileio_type.h:127
AIInfo
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
AIScannerLibrary::RegisterAPI
void RegisterAPI(class Squirrel *engine) override
Register the API for this ScriptInfo.
Definition: ai_scanner.cpp:143
AIScannerInfo::GetScannerName
const char * GetScannerName() const override
Get the type of the script, in plural.
Definition: ai_scanner.hpp:46
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
AIScannerInfo::FindInfo
class AIInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Check if we have an AI by name and version available in our list.
Definition: ai_scanner.cpp:95
AIScannerInfo::SelectRandomAI
class AIInfo * SelectRandomAI() const
Select a random AI.
Definition: ai_scanner.cpp:61
AIScannerInfo::RegisterAPI
void RegisterAPI(class Squirrel *engine) override
Register the API for this ScriptInfo.
Definition: ai_scanner.cpp:56