1
0
Fork 0

(svn r23613) -Add: allow IsDeveloperOnly in info.nut, to indicate if you can select this GS via the GUI (optional, defaults to false)

release/1.2
truebrain 2011-12-19 20:57:08 +00:00
parent 963802e9a7
commit 1616961ea2
5 changed files with 36 additions and 7 deletions

View File

@ -67,7 +67,12 @@ template <> const char *GetClassName<GameInfo, ST_GS>() { return "GSInfo"; }
} else { } else {
info->min_loadable_version = info->GetVersion(); 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. */ /* Try to get the API version the AI is written for. */
if (!info->CheckMethod("GetAPIVersion")) return SQ_ERROR; if (!info->CheckMethod("GetAPIVersion")) return SQ_ERROR;
if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) 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<GameInfo, ST_GS>() { return "GSInfo"; }
GameInfo::GameInfo() : GameInfo::GameInfo() :
min_loadable_version(0), min_loadable_version(0),
is_developer_only(false),
api_version(NULL) api_version(NULL)
{ {
} }

View File

@ -41,8 +41,11 @@ public:
*/ */
const char *GetAPIVersion() const { return this->api_version; } const char *GetAPIVersion() const { return this->api_version; }
/* virtual */ bool IsDeveloperOnly() const { return this->is_developer_only; }
private: private:
int min_loadable_version; ///< The Game can load savegame data if the version is equal or greater than this. 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. const char *api_version; ///< API version used by this Game.
}; };

View File

@ -129,6 +129,19 @@ public:
*/ */
bool UseAsRandomAI(); 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 * Gets the name of main class of the Script so OpenTTD knows
* what class to instantiate. * what class to instantiate.

View File

@ -142,6 +142,10 @@ public:
*/ */
int GetSettingDefaultValue(const char *name) const; int GetSettingDefaultValue(const char *name) const;
/**
* Can this script be selected by developers only?
*/
virtual bool IsDeveloperOnly() const { return false; }
protected: protected:
class Squirrel *engine; ///< Engine used to register for Squirrel. class Squirrel *engine; ///< Engine used to register for Squirrel.

View File

@ -13,6 +13,7 @@
#include "../debug.h" #include "../debug.h"
#include "../string_func.h" #include "../string_func.h"
#include "../fileio_func.h" #include "../fileio_func.h"
#include "../settings_type.h"
#include <sys/stat.h> #include <sys/stat.h>
#include "../script/squirrel.hpp" #include "../script/squirrel.hpp"
@ -144,6 +145,7 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
this->info_list[strdup(script_name)] = info; this->info_list[strdup(script_name)] = info;
if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
/* Add the script to the 'unique' script list, where only the highest version /* Add the script to the 'unique' script list, where only the highest version
* of the script is registered. */ * of the script is registered. */
if (this->info_single_list.find(script_original_name) == this->info_single_list.end()) { if (this->info_single_list.find(script_original_name) == this->info_single_list.end()) {
@ -152,6 +154,7 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
this->info_single_list[script_original_name] = info; this->info_single_list[script_original_name] = info;
} }
} }
}
char *ScriptScanner::GetConsoleList(char *p, const char *last, bool newest_only) const char *ScriptScanner::GetConsoleList(char *p, const char *last, bool newest_only) const
{ {