OpenTTD

script_info.hpp
Go to the documentation of this file.
1 /* $Id: script_info.hpp 26057 2013-11-23 13:12:19Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef SCRIPT_INFO_HPP
13 #define SCRIPT_INFO_HPP
14
15 #include <squirrel.h>
16 #include "../misc/countedptr.hpp"
17
18 #include "script_config.hpp"
19
21 static const int MAX_SL_OPS = 100000;
23 static const int MAX_CONSTRUCTOR_OPS = 100000;
25 static const int MAX_CREATEINSTANCE_OPS = 100000;
27 static const int MAX_GET_OPS = 1000;
29 static const int MAX_GET_SETTING_OPS = 100000;
30
32 class ScriptInfo : public SimpleCountedObject {
33 public:
34 ScriptInfo() :
35 engine(NULL),
36 SQ_instance(NULL),
37 main_script(NULL),
38 tar_file(NULL),
39 author(NULL),
40 name(NULL),
41 short_name(NULL),
42 description(NULL),
43 date(NULL),
44 instance_name(NULL),
45 version(0),
46 url(NULL),
47 scanner(NULL)
48 {}
49 ~ScriptInfo();
50
54 const char *GetAuthor() const { return this->author; }
55
59 const char *GetName() const { return this->name; }
60
64 const char *GetShortName() const { return this->short_name; }
65
69 const char *GetDescription() const { return this->description; }
70
74 int GetVersion() const { return this->version; }
75
79 const char *GetDate() const { return this->date; }
80
84 const char *GetInstanceName() const { return this->instance_name; }
85
89 const char *GetURL() const { return this->url; }
90
94 const char *GetMainScript() const { return this->main_script; }
95
99 const char *GetTarFile() const { return this->tar_file; }
100
104 bool CheckMethod(const char *name) const;
105
109 static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
110
114 virtual class ScriptScanner *GetScanner() { return this->scanner; }
115
119 bool GetSettings();
120
124 const ScriptConfigItemList *GetConfigList() const;
125
129 const ScriptConfigItem *GetConfigItem(const char *name) const;
130
134 SQInteger AddSetting(HSQUIRRELVM vm);
135
139 SQInteger AddLabels(HSQUIRRELVM vm);
140
144 int GetSettingDefaultValue(const char *name) const;
145
149 virtual bool IsDeveloperOnly() const { return false; }
150
151 protected:
152 class Squirrel *engine;
153 HSQOBJECT *SQ_instance;
154 ScriptConfigItemList config_list;
155
156 private:
157 char *main_script;
158 char *tar_file;
159 const char *author;
160 const char *name;
161 const char *short_name;
162 const char *description;
163 const char *date;
164 const char *instance_name;
165 int version;
166 const char *url;
167
168 class ScriptScanner *scanner;
169 };
170
171 #endif /* SCRIPT_INFO_HPP */
ScriptInfo::GetVersion
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:74
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:165
ScriptInfo::scanner
class ScriptScanner * scanner
ScriptScanner object that was used to scan this script info.
Definition: script_info.hpp:168
ScriptInfo::SQ_instance
HSQOBJECT * SQ_instance
The Squirrel instance created for this info.
Definition: script_info.hpp:153
ScriptInfo::CheckMethod
bool CheckMethod(const char *name) const
Check if a given method exists.
Definition: script_info.cpp:49
ScriptInfo::GetConfigList
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
Definition: script_info.cpp:282
ScriptInfo::GetName
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:59
ScriptInfo::date
const char * date
The date the script was written at.
Definition: script_info.hpp:163
ScriptConfigItemList
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
Definition: script_config.hpp:50
ScriptInfo::url
const char * url
URL of the script.
Definition: script_info.hpp:166
ScriptInfo::GetShortName
const char * GetShortName() const
Get the 4 character long short name of the script.
Definition: script_info.hpp:64
ScriptInfo::config_list
ScriptConfigItemList config_list
List of settings from this Script.
Definition: script_info.hpp:154
ScriptInfo::instance_name
const char * instance_name
Name of the main class in the script.
Definition: script_info.hpp:164
ScriptInfo::GetSettingDefaultValue
int GetSettingDefaultValue(const char *name) const
Get the default value for a setting.
Definition: script_info.cpp:295
ScriptScanner
Scanner to help finding scripts.
Definition: script_scanner.hpp:22
ScriptInfo::GetMainScript
const char * GetMainScript() const
Get the filename of the main.nut script.
Definition: script_info.hpp:94
ScriptInfo::GetDate
const char * GetDate() const
Get the last-modified date of the script.
Definition: script_info.hpp:79
ScriptInfo::short_name
const char * short_name
Short name (4 chars) which uniquely identifies the script.
Definition: script_info.hpp:161
ScriptInfo::AddLabels
SQInteger AddLabels(HSQUIRRELVM vm)
Add labels for a setting.
Definition: script_info.cpp:230
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:32
ScriptInfo::author
const char * author
Author of the script.
Definition: script_info.hpp:159
ScriptInfo::GetSettings
bool GetSettings()
Get the settings of the Script.
Definition: script_info.cpp:112
ScriptInfo::GetURL
const char * GetURL() const
Get the website for this script.
Definition: script_info.hpp:89
SimpleCountedObject
Simple counted object.
Definition: countedptr.hpp:206
ScriptInfo::GetConfigItem
const ScriptConfigItem * GetConfigItem(const char *name) const
Get the description of a certain Script config option.
Definition: script_info.cpp:287
ScriptInfo::GetScanner
virtual class ScriptScanner * GetScanner()
Get the scanner which has found this ScriptInfo.
Definition: script_info.hpp:114
ScriptInfo::GetDescription
const char * GetDescription() const
Get the description of the script.
Definition: script_info.hpp:69
ScriptInfo::name
const char * name
Full name of the script.
Definition: script_info.hpp:160
ScriptInfo::AddSetting
SQInteger AddSetting(HSQUIRRELVM vm)
Set a setting.
Definition: script_info.cpp:117
script_config.hpp
ScriptConfig stores the configuration settings of every Script.
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:34
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:21
MAX_GET_OPS
static const int MAX_GET_OPS
Number of operations to get the author and similar information.
Definition: script_info.hpp:27
ScriptInfo::main_script
char * main_script
The full path of the script.
Definition: script_info.hpp:157
MAX_CREATEINSTANCE_OPS
static const int MAX_CREATEINSTANCE_OPS
Number of operations to create an instance of a script.
Definition: script_info.hpp:25
ScriptInfo::GetAuthor
const char * GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:54
ScriptInfo::engine
class Squirrel * engine
Engine used to register for Squirrel.
Definition: script_info.hpp:152
MAX_CONSTRUCTOR_OPS
static const int MAX_CONSTRUCTOR_OPS
The maximum number of operations for initial start of a script.
Definition: script_info.hpp:23
ScriptInfo::Constructor
static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info)
Process the creation of a FileInfo object.
Definition: script_info.cpp:60
ScriptInfo::description
const char * description
Small description of the script.
Definition: script_info.hpp:162
ScriptInfo::tar_file
char * tar_file
If, which tar file the script was in.
Definition: script_info.hpp:158
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:29
ScriptInfo::GetInstanceName
const char * GetInstanceName() const
Get the name of the instance of the script to create.
Definition: script_info.hpp:84
Squirrel
Definition: squirrel.hpp:23
ScriptInfo::GetTarFile
const char * GetTarFile() const
Get the filename of the tar the script is in.
Definition: script_info.hpp:99
ScriptInfo::IsDeveloperOnly
virtual bool IsDeveloperOnly() const
Can this script be selected by developers only?
Definition: script_info.hpp:149