(svn r18747) -Codechange: add some constness to the AI code

This commit is contained in:
rubidium 2010-01-07 00:09:27 +00:00
parent 1967084bc3
commit 0e404038f2
6 changed files with 24 additions and 24 deletions

View File

@ -70,7 +70,7 @@ AIConfig::~AIConfig()
if (this->config_list != NULL) delete this->config_list;
}
AIInfo *AIConfig::GetInfo()
AIInfo *AIConfig::GetInfo() const
{
return this->info;
}
@ -103,9 +103,9 @@ AIConfig *AIConfig::GetConfig(CompanyID company, bool forceNewgameSetting)
return *config;
}
int AIConfig::GetSetting(const char *name)
int AIConfig::GetSetting(const char *name) const
{
SettingValueList::iterator it = this->settings.find(name);
SettingValueList::const_iterator it = this->settings.find(name);
/* Return the default value if the setting is not set, or if we are in a not-custom difficult level */
if (it == this->settings.end() || ((_game_mode == GM_MENU) ? _settings_newgame.difficulty.diff_level : _settings_game.difficulty.diff_level) != 3) {
if (this->info == NULL) {
@ -162,17 +162,17 @@ void AIConfig::AddRandomDeviation()
}
}
bool AIConfig::HasAI()
bool AIConfig::HasAI() const
{
return this->info != NULL;
}
const char *AIConfig::GetName()
const char *AIConfig::GetName() const
{
return this->name;
}
int AIConfig::GetVersion()
int AIConfig::GetVersion() const
{
return this->version;
}
@ -203,10 +203,10 @@ void AIConfig::StringToSettings(const char *value)
free(value_copy);
}
void AIConfig::SettingsToString(char *string, size_t size)
void AIConfig::SettingsToString(char *string, size_t size) const
{
string[0] = '\0';
for (SettingValueList::iterator it = this->settings.begin(); it != this->settings.end(); it++) {
for (SettingValueList::const_iterator it = this->settings.begin(); it != this->settings.end(); it++) {
char no[10];
snprintf(no, sizeof(no), "%d", (*it).second);

View File

@ -48,7 +48,7 @@ public:
/**
* Get the AIInfo linked to this AIConfig.
*/
class AIInfo *GetInfo();
class AIInfo *GetInfo() const;
/**
* Get the config list for this AIConfig.
@ -67,7 +67,7 @@ public:
* @return The (default) value of the setting, or -1 if the setting was not
* found.
*/
int GetSetting(const char *name);
int GetSetting(const char *name) const;
/**
* Set the value of a setting for this config.
@ -87,17 +87,17 @@ public:
/**
* Is this config attached to an AI?
*/
bool HasAI();
bool HasAI() const;
/**
* Get the name of the AI.
*/
const char *GetName();
const char *GetName() const;
/**
* Get the version of the AI.
*/
int GetVersion();
int GetVersion() const;
/**
* Convert a string which is stored in the config file or savegames to
@ -109,7 +109,7 @@ public:
* Convert the custom settings to a string that can be stored in the config
* file or savegames.
*/
void SettingsToString(char *string, size_t size);
void SettingsToString(char *string, size_t size) const;
private:
const char *name;

View File

@ -391,7 +391,7 @@ void AIInstance::GameLoop()
}
}
void AIInstance::CollectGarbage()
void AIInstance::CollectGarbage() const
{
if (this->is_started && !this->IsDead()) this->engine->CollectGarbage();
}

View File

@ -70,7 +70,7 @@ public:
/**
* Let the VM collect any garbage.
*/
void CollectGarbage();
void CollectGarbage() const;
/**
* Get the storage of this AI.
@ -105,7 +105,7 @@ public:
/**
* Return the "this AI died" value
*/
inline bool IsDead() { return this->is_dead; }
inline bool IsDead() const { return this->is_dead; }
/**
* Call the AI Save function and save all data in the savegame.

View File

@ -245,10 +245,10 @@ void AIScanner::RegisterAI(AIInfo *info)
}
}
AIInfo *AIScanner::SelectRandomAI()
AIInfo *AIScanner::SelectRandomAI() const
{
uint num_random_ais = 0;
for (AIInfoList::iterator it = this->info_single_list.begin(); it != this->info_single_list.end(); it++) {
for (AIInfoList::const_iterator it = this->info_single_list.begin(); it != this->info_single_list.end(); it++) {
if (it->second->UseAsRandomAI()) num_random_ais++;
}
@ -266,7 +266,7 @@ AIInfo *AIScanner::SelectRandomAI()
}
/* Find the Nth item from the array */
AIInfoList::iterator it = this->info_single_list.begin();
AIInfoList::const_iterator it = this->info_single_list.begin();
while (!it->second->UseAsRandomAI()) it++;
for (; pos > 0; pos--) {
it++;
@ -323,10 +323,10 @@ AIInfo *AIScanner::FindInfo(const char *nameParam, int versionParam)
return info;
}
char *AIScanner::GetAIConsoleList(char *p, const char *last)
char *AIScanner::GetAIConsoleList(char *p, const char *last) const
{
p += seprintf(p, last, "List of AIs:\n");
AIInfoList::iterator it = this->info_list.begin();
AIInfoList::const_iterator it = this->info_list.begin();
for (; it != this->info_list.end(); it++) {
AIInfo *i = (*it).second;
p += seprintf(p, last, "%10s (v%d): %s\n", i->GetName(), i->GetVersion(), i->GetDescription());

View File

@ -41,7 +41,7 @@ public:
/**
* Select a Random AI.
*/
class AIInfo *SelectRandomAI();
class AIInfo *SelectRandomAI() const;
/**
* Find an AI by name.
@ -51,7 +51,7 @@ public:
/**
* Get the list of available AIs for the console.
*/
char *GetAIConsoleList(char *p, const char *last);
char *GetAIConsoleList(char *p, const char *last) const;
/**
* Get the list of all registered AIs.