From d4582d27049323e4d8ce848e96ef7e1faae8320c Mon Sep 17 00:00:00 2001 From: truebrain Date: Mon, 19 Dec 2011 20:57:08 +0000 Subject: [PATCH] (svn r23613) -Add: allow IsDeveloperOnly in info.nut, to indicate if you can select this GS via the GUI (optional, defaults to false) --- src/game/game_info.cpp | 8 +++++++- src/game/game_info.hpp | 3 +++ src/script/api/script_info_docs.hpp | 13 +++++++++++++ src/script/script_info.hpp | 4 ++++ src/script/script_scanner.cpp | 15 +++++++++------ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/game/game_info.cpp b/src/game/game_info.cpp index 2d304bc94f..ab4f4edc7e 100644 --- a/src/game/game_info.cpp +++ b/src/game/game_info.cpp @@ -67,7 +67,12 @@ template <> const char *GetClassName() { return "GSInfo"; } } else { info->min_loadable_version = info->GetVersion(); } - + /* When there is an IsSelectable function, call it. */ + if (info->engine->MethodExists(*info->SQ_instance, "IsDeveloperOnly")) { + if (!info->engine->CallBoolMethod(*info->SQ_instance, "IsDeveloperOnly", &info->is_developer_only, MAX_GET_OPS)) return SQ_ERROR; + } else { + info->is_developer_only = false; + } /* Try to get the API version the AI is written for. */ if (!info->CheckMethod("GetAPIVersion")) return SQ_ERROR; if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) return SQ_ERROR; @@ -85,6 +90,7 @@ template <> const char *GetClassName() { return "GSInfo"; } GameInfo::GameInfo() : min_loadable_version(0), + is_developer_only(false), api_version(NULL) { } diff --git a/src/game/game_info.hpp b/src/game/game_info.hpp index 8fe588dd0c..3d42d3379e 100644 --- a/src/game/game_info.hpp +++ b/src/game/game_info.hpp @@ -41,8 +41,11 @@ public: */ const char *GetAPIVersion() const { return this->api_version; } + /* virtual */ bool IsDeveloperOnly() const { return this->is_developer_only; } + private: int min_loadable_version; ///< The Game can load savegame data if the version is equal or greater than this. + bool is_developer_only; ///< Is the script selectable by non-developers? const char *api_version; ///< API version used by this Game. }; diff --git a/src/script/api/script_info_docs.hpp b/src/script/api/script_info_docs.hpp index 10d2f09f7c..dd7673294c 100644 --- a/src/script/api/script_info_docs.hpp +++ b/src/script/api/script_info_docs.hpp @@ -129,6 +129,19 @@ public: */ bool UseAsRandomAI(); + /** + * Can a non-developer select Script for a new game. + * + * The idea behind this function is to 'forbid' using your script with a new + * game if you for example specificly wrote it for a certain scenario. + * + * @return True if the Script can be selected from the GUI as non-developer. + * @note This function is optional. Default is false. + * + * @api -ai + */ + bool IsDeveloperOnly(); + /** * Gets the name of main class of the Script so OpenTTD knows * what class to instantiate. diff --git a/src/script/script_info.hpp b/src/script/script_info.hpp index 4e59c7d72b..4ed1607263 100644 --- a/src/script/script_info.hpp +++ b/src/script/script_info.hpp @@ -142,6 +142,10 @@ public: */ int GetSettingDefaultValue(const char *name) const; + /** + * Can this script be selected by developers only? + */ + virtual bool IsDeveloperOnly() const { return false; } protected: class Squirrel *engine; ///< Engine used to register for Squirrel. diff --git a/src/script/script_scanner.cpp b/src/script/script_scanner.cpp index 0f572a7c0c..233bf09cc0 100644 --- a/src/script/script_scanner.cpp +++ b/src/script/script_scanner.cpp @@ -13,6 +13,7 @@ #include "../debug.h" #include "../string_func.h" #include "../fileio_func.h" +#include "../settings_type.h" #include #include "../script/squirrel.hpp" @@ -144,12 +145,14 @@ void ScriptScanner::RegisterScript(ScriptInfo *info) this->info_list[strdup(script_name)] = info; - /* Add the script to the 'unique' script list, where only the highest version - * of the script is registered. */ - if (this->info_single_list.find(script_original_name) == this->info_single_list.end()) { - this->info_single_list[strdup(script_original_name)] = info; - } else if (this->info_single_list[script_original_name]->GetVersion() < info->GetVersion()) { - this->info_single_list[script_original_name] = info; + if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) { + /* Add the script to the 'unique' script list, where only the highest version + * of the script is registered. */ + if (this->info_single_list.find(script_original_name) == this->info_single_list.end()) { + this->info_single_list[strdup(script_original_name)] = info; + } else if (this->info_single_list[script_original_name]->GetVersion() < info->GetVersion()) { + this->info_single_list[script_original_name] = info; + } } }