10 #include "../stdafx.h"
12 #include "../network/network.h"
13 #include "../openttd.h"
14 #include "../core/random_func.hpp"
16 #include "../script/squirrel_class.hpp"
17 #include "../script/api/script_object.hpp"
21 #include "../safeguards.h"
24 AIScannerInfo::AIScannerInfo() :
30 void AIScannerInfo::Initialize()
32 ScriptScanner::Initialize(
"AIScanner");
46 AIScannerInfo::~AIScannerInfo()
63 if (_game_mode == GM_MENU) {
64 Debug(script, 0,
"The intro game should not use AI, loading 'dummy' AI.");
68 uint num_random_ais = 0;
74 if (num_random_ais == 0) {
75 Debug(script, 0,
"No suitable AI found, loading 'dummy' AI.");
80 uint pos = ScriptObject::GetRandomizer(
OWNER_NONE).Next(num_random_ais);
83 ScriptInfoList::const_iterator it = this->info_single_list.begin();
85 #define GetAIInfo(it) static_cast<AIInfo *>((*it).second)
86 while (!GetAIInfo(it)->UseAsRandomAI()) it++;
87 for (; pos > 0; pos--) {
89 while (!GetAIInfo(it)->UseAsRandomAI()) it++;
97 if (this->
info_list.empty())
return nullptr;
98 if (name.empty())
return nullptr;
107 if (force_exact_match) {
109 std::string name_with_version = fmt::format(
"{}.{}", name, version);
110 auto it = this->
info_list.find(name_with_version);
111 if (it != this->
info_list.end())
return static_cast<AIInfo *
>(it->second);
116 int highest_version = -1;
120 for (
const auto &item : this->
info_list) {
132 void AIScannerLibrary::Initialize()
134 ScriptScanner::Initialize(
"AIScanner");
151 std::string library_name = fmt::format(
"{}.{}", library, version);
154 ScriptInfoList::iterator it = this->
info_list.find(library_name);
155 if (it == this->
info_list.end())
return nullptr;
157 return static_cast<AILibrary *
>((*it).second);
AIInfo keeps track of all information of an AI, like Author, Description, ...
declarations of the class for AI scanner
All static information from an AI like name, version, etc.
bool CanLoadFromVersion(int version) const
Check if we can start this AI.
bool UseAsRandomAI() const
Use this AI as a random AI.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
All static information from an AI library like name, version, etc.
static void RegisterAPI(Squirrel *engine)
Register the functions of this class.
const std::string & GetCategory() const
Get the category this library is in.
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.
AIInfo * info_dummy
The dummy AI.
class AIInfo * SelectRandomAI() const
Select a random AI.
std::string GetScriptName(ScriptInfo *info) override
Get the script name how to store the script in memory.
void RegisterAPI(class Squirrel *engine) override
Register the API for this ScriptInfo.
void SetDummyAI(class AIInfo *info)
Set the Dummy AI.
void RegisterAPI(class Squirrel *engine) override
Register the API for this ScriptInfo.
std::string GetScriptName(ScriptInfo *info) override
Get the script name how to store the script in memory.
class AILibrary * FindLibrary(const std::string &library, int version)
Find a library in the pool.
All static information from an Script like name, version, etc.
const std::string & GetInstanceName() const
Get the name of the instance of the script to create.
int GetVersion() const
Get the version of the script.
const std::string & GetName() const
Get the Name of the script.
Scanner to help finding scripts.
class Squirrel * engine
The engine we're scanning with.
std::string main_script
The full path of the script.
ScriptInfoList info_list
The list of all script.
ScriptInfoList info_single_list
The list of all unique script. The best script (highest version) is shown.
HSQUIRRELVM GetVM()
Get the squirrel VM.
@ OWNER_NONE
The tile has no ownership.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir)
Run the dummy info.nut.
bool StrEqualsIgnoreCase(const std::string_view str1, const std::string_view str2)
Compares two string( view)s for equality, while ignoring the case of the characters.