mirror of https://github.com/OpenTTD/OpenTTD
(svn r15465) -Codechange: constify most of AIInfo/AIFileInfo methods, move definition of very simple getters to header file
parent
9292c90360
commit
d3f018a7e3
|
@ -46,52 +46,12 @@ AILibrary::~AILibrary()
|
||||||
free((void *)this->category);
|
free((void *)this->category);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *AIFileInfo::GetAuthor()
|
void AIFileInfo::GetSettings() const
|
||||||
{
|
|
||||||
return this->author;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *AIFileInfo::GetName()
|
|
||||||
{
|
|
||||||
return this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *AIFileInfo::GetShortName()
|
|
||||||
{
|
|
||||||
return this->short_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *AIFileInfo::GetDescription()
|
|
||||||
{
|
|
||||||
return this->description;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AIFileInfo::GetVersion()
|
|
||||||
{
|
|
||||||
return this->version;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AIFileInfo::GetSettings()
|
|
||||||
{
|
{
|
||||||
this->engine->CallMethod(*this->SQ_instance, "GetSettings", NULL, -1);
|
this->engine->CallMethod(*this->SQ_instance, "GetSettings", NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *AIFileInfo::GetDate()
|
bool AIFileInfo::CheckMethod(const char *name) const
|
||||||
{
|
|
||||||
return this->date;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *AIFileInfo::GetInstanceName()
|
|
||||||
{
|
|
||||||
return this->instance_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *AIFileInfo::GetMainScript()
|
|
||||||
{
|
|
||||||
return this->main_script;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AIFileInfo::CheckMethod(const char *name)
|
|
||||||
{
|
{
|
||||||
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
|
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
|
||||||
char error[1024];
|
char error[1024];
|
||||||
|
@ -207,7 +167,7 @@ AIInfo::~AIInfo()
|
||||||
this->config_list.clear();
|
this->config_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AIInfo::CanLoadFromVersion(int version)
|
bool AIInfo::CanLoadFromVersion(int version) const
|
||||||
{
|
{
|
||||||
if (version == -1) return true;
|
if (version == -1) return true;
|
||||||
return version >= this->min_loadable_version && version <= this->GetVersion();
|
return version >= this->min_loadable_version && version <= this->GetVersion();
|
||||||
|
@ -365,22 +325,22 @@ SQInteger AIInfo::AddLabels(HSQUIRRELVM vm)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AIConfigItemList *AIInfo::GetConfigList()
|
const AIConfigItemList *AIInfo::GetConfigList() const
|
||||||
{
|
{
|
||||||
return &this->config_list;
|
return &this->config_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AIConfigItem *AIInfo::GetConfigItem(const char *name)
|
const AIConfigItem *AIInfo::GetConfigItem(const char *name) const
|
||||||
{
|
{
|
||||||
for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) {
|
for (AIConfigItemList::const_iterator it = this->config_list.begin(); it != this->config_list.end(); it++) {
|
||||||
if (strcmp((*it).name, name) == 0) return &(*it);
|
if (strcmp((*it).name, name) == 0) return &(*it);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AIInfo::GetSettingDefaultValue(const char *name)
|
int AIInfo::GetSettingDefaultValue(const char *name) const
|
||||||
{
|
{
|
||||||
for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) {
|
for (AIConfigItemList::const_iterator it = this->config_list.begin(); it != this->config_list.end(); it++) {
|
||||||
if (strcmp((*it).name, name) != 0) continue;
|
if (strcmp((*it).name, name) != 0) continue;
|
||||||
/* The default value depends on the difficulty level */
|
/* The default value depends on the difficulty level */
|
||||||
switch ((_game_mode == GM_MENU) ? _settings_newgame.difficulty.diff_level : _settings_game.difficulty.diff_level) {
|
switch ((_game_mode == GM_MENU) ? _settings_newgame.difficulty.diff_level : _settings_game.difficulty.diff_level) {
|
||||||
|
@ -416,11 +376,6 @@ int AIInfo::GetSettingDefaultValue(const char *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *AILibrary::GetCategory()
|
|
||||||
{
|
|
||||||
return this->category;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ SQInteger AILibrary::Import(HSQUIRRELVM vm)
|
/* static */ SQInteger AILibrary::Import(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
SQConvert::SQAutoFreePointers ptr;
|
SQConvert::SQAutoFreePointers ptr;
|
||||||
|
|
|
@ -47,52 +47,52 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get the Author of the AI.
|
* Get the Author of the AI.
|
||||||
*/
|
*/
|
||||||
const char *GetAuthor();
|
const char *GetAuthor() const { return this->author; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Name of the AI.
|
* Get the Name of the AI.
|
||||||
*/
|
*/
|
||||||
const char *GetName();
|
const char *GetName() const { return this->name; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the 4 character long short name of the AI.
|
* Get the 4 character long short name of the AI.
|
||||||
*/
|
*/
|
||||||
const char *GetShortName();
|
const char *GetShortName() const { return this->short_name; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the description of the AI.
|
* Get the description of the AI.
|
||||||
*/
|
*/
|
||||||
const char *GetDescription();
|
const char *GetDescription() const { return this->description; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of the AI.
|
* Get the version of the AI.
|
||||||
*/
|
*/
|
||||||
int GetVersion();
|
int GetVersion() const { return this->version; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the settings of the AI.
|
* Get the settings of the AI.
|
||||||
*/
|
*/
|
||||||
void GetSettings();
|
void GetSettings() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the date of the AI.
|
* Get the date of the AI.
|
||||||
*/
|
*/
|
||||||
const char *GetDate();
|
const char *GetDate() const { return this->date; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the instance of the AI to create.
|
* Get the name of the instance of the AI to create.
|
||||||
*/
|
*/
|
||||||
const char *GetInstanceName();
|
const char *GetInstanceName() const { return this->instance_name; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the filename of the main.nut script.
|
* Get the filename of the main.nut script.
|
||||||
*/
|
*/
|
||||||
const char *GetMainScript();
|
const char *GetMainScript() const { return this->main_script; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given method exists.
|
* Check if a given method exists.
|
||||||
*/
|
*/
|
||||||
bool CheckMethod(const char *name);
|
bool CheckMethod(const char *name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the creation of a FileInfo object.
|
* Process the creation of a FileInfo object.
|
||||||
|
@ -128,17 +128,17 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get the config list for this AI.
|
* Get the config list for this AI.
|
||||||
*/
|
*/
|
||||||
const AIConfigItemList *GetConfigList();
|
const AIConfigItemList *GetConfigList() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the description of a certain ai config option.
|
* Get the description of a certain ai config option.
|
||||||
*/
|
*/
|
||||||
const AIConfigItem *GetConfigItem(const char *name);
|
const AIConfigItem *GetConfigItem(const char *name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if we can start this AI.
|
* Check if we can start this AI.
|
||||||
*/
|
*/
|
||||||
bool CanLoadFromVersion(int version);
|
bool CanLoadFromVersion(int version) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a setting.
|
* Set a setting.
|
||||||
|
@ -153,7 +153,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get the default value for a setting.
|
* Get the default value for a setting.
|
||||||
*/
|
*/
|
||||||
int GetSettingDefaultValue(const char *name);
|
int GetSettingDefaultValue(const char *name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AIConfigItemList config_list;
|
AIConfigItemList config_list;
|
||||||
|
@ -175,7 +175,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get the category this library is in.
|
* Get the category this library is in.
|
||||||
*/
|
*/
|
||||||
const char *GetCategory();
|
const char *GetCategory() const { return this->category; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *category;
|
const char *category;
|
||||||
|
|
Loading…
Reference in New Issue