OpenTTD Source  20241121-master-g67a0fccfad
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 
15 #include "script_object.hpp"
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 
30 class ScriptInfo : public SimpleCountedObject {
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 */
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
const std::string & GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:41
std::string short_name
Short name (4 chars) which uniquely identifies the script.
int version
Version of the script.
class ScriptScanner * scanner
ScriptScanner object that was used to scan this script info.
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
Definition: script_info.cpp:30
const std::string & GetDate() const
Get the last-modified date of the script.
Definition: script_info.hpp:66
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
std::string description
Small description of the script.
ScriptConfigItemList config_list
List of settings from this Script.
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
bool CheckMethod(const char *name) const
Check if a given method exists.
Definition: script_info.cpp:21
class Squirrel * engine
Engine used to register for Squirrel.
std::string name
Full name of the script.
const std::string & GetInstanceName() const
Get the name of the instance of the script to create.
Definition: script_info.hpp:71
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
Definition: script_info.cpp:85
const std::string & GetShortName() const
Get the 4 character long short name of the script.
Definition: script_info.hpp:51
std::string main_script
The full path of the script.
const std::string & GetTarFile() const
Get the filename of the tar the script is in.
Definition: script_info.hpp:86
const std::string & GetMainScript() const
Get the filename of the main.nut script.
Definition: script_info.hpp:81
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:61
std::string instance_name
Name of the main class in the script.
bool GetSettings()
Get the settings of the Script.
Definition: script_info.cpp:80
const std::string & GetName() const
Get the Name of the script.
Definition: script_info.hpp:46
HSQOBJECT SQ_instance
The Squirrel instance created for this info.
std::string author
Author of the script.
int GetSettingDefaultValue(const std::string &name) const
Get the default value for a setting.
std::string tar_file
If, which tar file the script was in.
const ScriptConfigItem * GetConfigItem(const std::string_view name) const
Get the description of a certain Script config option.
std::string url
URL of the script.
const std::string & GetDescription() const
Get the description of the script.
Definition: script_info.hpp:56
virtual bool IsDeveloperOnly() const
Can this script be selected by developers only?
const std::string & GetURL() const
Get the website for this script.
Definition: script_info.hpp:76
std::string date
The date the script was written at.
Scanner to help finding scripts.
ScriptConfig stores the configuration settings of every Script.
std::vector< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
static const int MAX_CREATEINSTANCE_OPS
Number of operations to create an instance of a script.
Definition: script_info.hpp:23
static const int MAX_GET_SETTING_OPS
Maximum number of operations allowed for getting a particular setting.
Definition: script_info.hpp:27
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
static const int MAX_CONSTRUCTOR_OPS
The maximum number of operations for initial start of a script.
Definition: script_info.hpp:21
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
Definition: script_info.hpp:25
void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir)
Run the dummy info.nut.
void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type)
Run the dummy AI and let it generate an error message.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Info about a single Script setting.