OpenTTD Source  1.11.2
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  SQ_instance(nullptr),
35  author(nullptr),
36  name(nullptr),
37  short_name(nullptr),
38  description(nullptr),
39  date(nullptr),
40  instance_name(nullptr),
41  version(0),
42  url(nullptr),
43  scanner(nullptr)
44  {}
45  ~ScriptInfo();
46 
50  const char *GetAuthor() const { return this->author; }
51 
55  const char *GetName() const { return this->name; }
56 
60  const char *GetShortName() const { return this->short_name; }
61 
65  const char *GetDescription() const { return this->description; }
66 
70  int GetVersion() const { return this->version; }
71 
75  const char *GetDate() const { return this->date; }
76 
80  const char *GetInstanceName() const { return this->instance_name; }
81 
85  const char *GetURL() const { return this->url; }
86 
90  const char *GetMainScript() const { return this->main_script.c_str(); }
91 
95  std::string GetTarFile() const { return this->tar_file; }
96 
100  bool CheckMethod(const char *name) const;
101 
105  static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
106 
110  virtual class ScriptScanner *GetScanner() { return this->scanner; }
111 
115  bool GetSettings();
116 
120  const ScriptConfigItemList *GetConfigList() const;
121 
125  const ScriptConfigItem *GetConfigItem(const char *name) const;
126 
130  SQInteger AddSetting(HSQUIRRELVM vm);
131 
135  SQInteger AddLabels(HSQUIRRELVM vm);
136 
140  int GetSettingDefaultValue(const char *name) const;
141 
145  virtual bool IsDeveloperOnly() const { return false; }
146 
147 protected:
148  class Squirrel *engine;
149  HSQOBJECT *SQ_instance;
151 
152 private:
153  std::string main_script;
154  std::string tar_file;
155  const char *author;
156  const char *name;
157  const char *short_name;
158  const char *description;
159  const char *date;
160  const char *instance_name;
161  int version;
162  const char *url;
163 
165 };
166 
167 #endif /* SCRIPT_INFO_HPP */
ScriptInfo::AddSetting
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
Definition: script_info.cpp:112
ScriptInfo::main_script
std::string main_script
The full path of the script.
Definition: script_info.hpp:153
ScriptInfo::GetAuthor
const char * GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:50
ScriptInfo::engine
class Squirrel * engine
Engine used to register for Squirrel.
Definition: script_info.hpp:148
ScriptInfo::GetMainScript
const char * GetMainScript() const
Get the filename of the main.nut script.
Definition: script_info.hpp:90
ScriptInfo::GetDate
const char * GetDate() const
Get the last-modified date of the script.
Definition: script_info.hpp:75
ScriptInfo::Constructor
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
Definition: script_info.cpp:56
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::GetURL
const char * GetURL() const
Get the website for this script.
Definition: script_info.hpp:85
ScriptInfo::description
const char * description
Small description of the script.
Definition: script_info.hpp:158
SimpleCountedObject
Simple counted object.
Definition: countedptr.hpp:204
ScriptInfo::GetTarFile
std::string GetTarFile() const
Get the filename of the tar the script is in.
Definition: script_info.hpp:95
ScriptInfo::GetDescription
const char * GetDescription() const
Get the description of the script.
Definition: script_info.hpp:65
ScriptInfo::IsDeveloperOnly
virtual bool IsDeveloperOnly() const
Can this script be selected by developers only?
Definition: script_info.hpp:145
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:161
Squirrel
Definition: squirrel.hpp:23
ScriptConfigItemList
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
Definition: script_config.hpp:48
ScriptInfo::GetConfigList
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
Definition: script_info.cpp:277
script_config.hpp
ScriptInfo::scanner
class ScriptScanner * scanner
ScriptScanner object that was used to scan this script info.
Definition: script_info.hpp:164
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:20
ScriptInfo::GetShortName
const char * GetShortName() const
Get the 4 character long short name of the script.
Definition: script_info.hpp:60
ScriptInfo::CheckMethod
bool CheckMethod(const char *name) const
Check if a given method exists.
Definition: script_info.cpp:45
ScriptInfo::date
const char * date
The date the script was written at.
Definition: script_info.hpp:159
ScriptInfo::url
const char * url
URL of the script.
Definition: script_info.hpp:162
ScriptInfo::config_list
ScriptConfigItemList config_list
List of settings from this Script.
Definition: script_info.hpp:150
ScriptInfo::GetInstanceName
const char * GetInstanceName() const
Get the name of the instance of the script to create.
Definition: script_info.hpp:80
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::short_name
const char * short_name
Short name (4 chars) which uniquely identifies the script.
Definition: script_info.hpp:157
ScriptInfo::GetVersion
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:70
ScriptInfo::AddLabels
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
Definition: script_info.cpp:225
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::author
const char * author
Author of the script.
Definition: script_info.hpp:155
ScriptInfo::tar_file
std::string tar_file
If, which tar file the script was in.
Definition: script_info.hpp:154
ScriptInfo::SQ_instance
HSQOBJECT * SQ_instance
The Squirrel instance created for this info.
Definition: script_info.hpp:149
ScriptInfo::GetConfigItem
const ScriptConfigItem * GetConfigItem(const char *name) const
Get the description of a certain Script config option.
Definition: script_info.cpp:282
ScriptInfo::instance_name
const char * instance_name
Name of the main class in the script.
Definition: script_info.hpp:160
ScriptInfo::GetSettingDefaultValue
int GetSettingDefaultValue(const char *name) const
Get the default value for a setting.
Definition: script_info.cpp:290
ScriptInfo::GetName
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:55
ScriptInfo::name
const char * name
Full name of the script.
Definition: script_info.hpp:156
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:107
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:110
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