Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / script / script_info.hpp
blobc2e952b821e0caa0ca8e5fbccf2c5b6c1c7d5229
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 */
8 /** @file script_info.hpp ScriptInfo keeps track of all information of a script, like Author, Description, ... */
10 #ifndef SCRIPT_INFO_HPP
11 #define SCRIPT_INFO_HPP
13 #include <squirrel.h>
14 #include "../misc/countedptr.hpp"
16 #include "script_config.hpp"
18 /** The maximum number of operations for saving or loading the data of a script. */
19 static const int MAX_SL_OPS = 100000;
20 /** The maximum number of operations for initial start of a script. */
21 static const int MAX_CONSTRUCTOR_OPS = 100000;
22 /** Number of operations to create an instance of a script. */
23 static const int MAX_CREATEINSTANCE_OPS = 100000;
24 /** Number of operations to get the author and similar information. */
25 static const int MAX_GET_OPS = 1000;
26 /** Maximum number of operations allowed for getting a particular setting. */
27 static const int MAX_GET_SETTING_OPS = 100000;
29 /** All static information from an Script like name, version, etc. */
30 class ScriptInfo : public SimpleCountedObject {
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)
45 ~ScriptInfo();
47 /**
48 * Get the Author of the script.
50 const char *GetAuthor() const { return this->author; }
52 /**
53 * Get the Name of the script.
55 const char *GetName() const { return this->name; }
57 /**
58 * Get the 4 character long short name of the script.
60 const char *GetShortName() const { return this->short_name; }
62 /**
63 * Get the description of the script.
65 const char *GetDescription() const { return this->description; }
67 /**
68 * Get the version of the script.
70 int GetVersion() const { return this->version; }
72 /**
73 * Get the last-modified date of the script.
75 const char *GetDate() const { return this->date; }
77 /**
78 * Get the name of the instance of the script to create.
80 const char *GetInstanceName() const { return this->instance_name; }
82 /**
83 * Get the website for this script.
85 const char *GetURL() const { return this->url; }
87 /**
88 * Get the filename of the main.nut script.
90 const char *GetMainScript() const { return this->main_script.c_str(); }
92 /**
93 * Get the filename of the tar the script is in.
95 std::string GetTarFile() const { return this->tar_file; }
97 /**
98 * Check if a given method exists.
100 bool CheckMethod(const char *name) const;
103 * Process the creation of a FileInfo object.
105 static SQInteger Constructor(HSQUIRRELVM vm, ScriptInfo *info);
108 * Get the scanner which has found this ScriptInfo.
110 virtual class ScriptScanner *GetScanner() { return this->scanner; }
113 * Get the settings of the Script.
115 bool GetSettings();
118 * Get the config list for this Script.
120 const ScriptConfigItemList *GetConfigList() const;
123 * Get the description of a certain Script config option.
125 const ScriptConfigItem *GetConfigItem(const char *name) const;
128 * Set a setting.
130 SQInteger AddSetting(HSQUIRRELVM vm);
133 * Add labels for a setting.
135 SQInteger AddLabels(HSQUIRRELVM vm);
138 * Get the default value for a setting.
140 int GetSettingDefaultValue(const char *name) const;
143 * Can this script be selected by developers only?
145 virtual bool IsDeveloperOnly() const { return false; }
147 protected:
148 class Squirrel *engine; ///< Engine used to register for Squirrel.
149 HSQOBJECT *SQ_instance; ///< The Squirrel instance created for this info.
150 ScriptConfigItemList config_list; ///< List of settings from this Script.
152 private:
153 std::string main_script; ///< The full path of the script.
154 std::string tar_file; ///< If, which tar file the script was in.
155 const char *author; ///< Author of the script.
156 const char *name; ///< Full name of the script.
157 const char *short_name; ///< Short name (4 chars) which uniquely identifies the script.
158 const char *description; ///< Small description of the script.
159 const char *date; ///< The date the script was written at.
160 const char *instance_name; ///< Name of the main class in the script.
161 int version; ///< Version of the script.
162 const char *url; ///< URL of the script.
164 class ScriptScanner *scanner; ///< ScriptScanner object that was used to scan this script info.
167 #endif /* SCRIPT_INFO_HPP */