OpenTTD Source  20240917-master-g9ab0a47812
script_info.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 SCRIPT_INFO_HPP
11 #define SCRIPT_INFO_HPP
12 
13 #include <squirrel.h>
14 #include "../misc/countedptr.hpp"
15 
16 #include "script_config.hpp"
17 
19 static const int MAX_SL_OPS = 100000;
21 static const int MAX_CONSTRUCTOR_OPS = 100000;
23 static const int MAX_CREATEINSTANCE_OPS = 100000;
25 static const int MAX_GET_OPS = 1000;
27 static const int MAX_GET_SETTING_OPS = 100000;
28 
31 public:
32  ScriptInfo() :
33  engine(nullptr),
34  version(0),
35  scanner(nullptr)
36  {}
37 
41  const std::string &GetAuthor() const { return this->author; }
42 
46  const std::string &GetName() const { return this->name; }
47 
51  const std::string &GetShortName() const { return this->short_name; }
52 
56  const std::string &GetDescription() const { return this->description; }
57 
61  int GetVersion() const { return this->version; }
62 
66  const std::string &GetDate() const { return this->date; }
67 
71  const std::string &GetInstanceName() const { return this->instance_name; }
72 
76  const std::string &GetURL() const { return this->url; }
77 
81  const std::string &GetMainScript() const { return this->main_script; }
82 
86  const std::string &GetTarFile() const { return this->tar_file; }
87 
91  bool CheckMethod(const char *name) const;
92 
96  static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
97 
101  virtual class ScriptScanner *GetScanner() { return this->scanner; }
102 
106  bool GetSettings();
107 
111  const ScriptConfigItemList *GetConfigList() const;
112 
116  const ScriptConfigItem *GetConfigItem(const std::string_view name) const;
117 
121  SQInteger AddSetting(HSQUIRRELVM vm);
122 
126  SQInteger AddLabels(HSQUIRRELVM vm);
127 
131  int GetSettingDefaultValue(const std::string &name) const;
132 
136  virtual bool IsDeveloperOnly() const { return false; }
137 
138 protected:
139  class Squirrel *engine;
140  HSQOBJECT SQ_instance;
142 
143 private:
144  std::string main_script;
145  std::string tar_file;
146  std::string author;
147  std::string name;
148  std::string short_name;
149  std::string description;
150  std::string date;
151  std::string instance_name;
152  int version;
153  std::string url;
154 
156 };
157 
158 void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir);
159 void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type);
160 
161 #endif /* SCRIPT_INFO_HPP */
ScriptInfo::short_name
std::string short_name
Short name (4 chars) which uniquely identifies the script.
Definition: script_info.hpp:148
ScriptInfo::AddSetting
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
Definition: script_info.cpp:85
ScriptInfo::main_script
std::string main_script
The full path of the script.
Definition: script_info.hpp:144
ScriptInfo::date
std::string date
The date the script was written at.
Definition: script_info.hpp:150
ScriptInfo::engine
class Squirrel * engine
Engine used to register for Squirrel.
Definition: script_info.hpp:139
ScriptInfo::Constructor
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
Definition: script_info.cpp:30
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
ScriptConfigItemList
std::vector< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
Definition: script_config.hpp:44
MAX_CREATEINSTANCE_OPS
static const int MAX_CREATEINSTANCE_OPS
Number of operations to create an instance of a script.
Definition: script_info.hpp:23
ScriptInfo::GetDate
const std::string & GetDate() const
Get the last-modified date of the script.
Definition: script_info.hpp:66
ScriptInfo::GetMainScript
const std::string & GetMainScript() const
Get the filename of the main.nut script.
Definition: script_info.hpp:81
SimpleCountedObject
Simple counted object.
Definition: countedptr.hpp:198
ScriptInfo::IsDeveloperOnly
virtual bool IsDeveloperOnly() const
Can this script be selected by developers only?
Definition: script_info.hpp:136
Script_CreateDummy
void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type)
Run the dummy AI and let it generate an error message.
Definition: script_info_dummy.cpp:80
ScriptInfo::GetAuthor
const std::string & GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:41
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:152
Squirrel
Definition: squirrel.hpp:23
ScriptInfo::GetSettingDefaultValue
int GetSettingDefaultValue(const std::string &name) const
Get the default value for a setting.
Definition: script_info.cpp:255
ScriptInfo::GetConfigList
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
Definition: script_info.cpp:242
ScriptInfo::GetURL
const std::string & GetURL() const
Get the website for this script.
Definition: script_info.hpp:76
ScriptInfo::description
std::string description
Small description of the script.
Definition: script_info.hpp:149
script_config.hpp
ScriptInfo::scanner
class ScriptScanner * scanner
ScriptScanner object that was used to scan this script info.
Definition: script_info.hpp:155
MAX_GET_OPS
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
Definition: script_info.hpp:25
ScriptScanner
Scanner to help finding scripts.
Definition: script_scanner.hpp:19
ScriptInfo::CheckMethod
bool CheckMethod(const char *name) const
Check if a given method exists.
Definition: script_info.cpp:21
ScriptInfo::GetName
const std::string & GetName() const
Get the Name of the script.
Definition: script_info.hpp:46
Script_CreateDummyInfo
void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir)
Run the dummy info.nut.
Definition: script_info_dummy.cpp:29
ScriptInfo::config_list
ScriptConfigItemList config_list
List of settings from this Script.
Definition: script_info.hpp:141
ScriptInfo::GetDescription
const std::string & GetDescription() const
Get the description of the script.
Definition: script_info.hpp:56
ScriptInfo::author
std::string author
Author of the script.
Definition: script_info.hpp:146
MAX_CONSTRUCTOR_OPS
static const int MAX_CONSTRUCTOR_OPS
The maximum number of operations for initial start of a script.
Definition: script_info.hpp:21
ScriptInfo::GetVersion
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:61
ScriptInfo::AddLabels
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
Definition: script_info.cpp:190
MAX_GET_SETTING_OPS
static const int MAX_GET_SETTING_OPS
Maximum number of operations allowed for getting a particular setting.
Definition: script_info.hpp:27
ScriptInfo::name
std::string name
Full name of the script.
Definition: script_info.hpp:147
ScriptInfo::GetTarFile
const std::string & GetTarFile() const
Get the filename of the tar the script is in.
Definition: script_info.hpp:86
ScriptInfo::GetShortName
const std::string & GetShortName() const
Get the 4 character long short name of the script.
Definition: script_info.hpp:51
ScriptInfo::tar_file
std::string tar_file
If, which tar file the script was in.
Definition: script_info.hpp:145
ScriptInfo::instance_name
std::string instance_name
Name of the main class in the script.
Definition: script_info.hpp:151
ScriptInfo::GetInstanceName
const std::string & GetInstanceName() const
Get the name of the instance of the script to create.
Definition: script_info.hpp:71
ScriptInfo::SQ_instance
HSQOBJECT SQ_instance
The Squirrel instance created for this info.
Definition: script_info.hpp:140
ScriptInfo::url
std::string url
URL of the script.
Definition: script_info.hpp:153
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
ScriptInfo::GetSettings
bool GetSettings()
Get the settings of the Script.
Definition: script_info.cpp:80
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:32
ScriptInfo::GetScanner
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
Definition: script_info.hpp:101
ScriptInfo::GetConfigItem
const ScriptConfigItem * GetConfigItem(const std::string_view name) const
Get the description of a certain Script config option.
Definition: script_info.cpp:247
MAX_SL_OPS
static const int MAX_SL_OPS
The maximum number of operations for saving or loading the data of a script.
Definition: script_info.hpp:19