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

pull/155/head
rubidium 15 years ago
parent 0a54cc9335
commit d9f86b6f97

@ -70,7 +70,7 @@ AIConfig::~AIConfig()
if (this->config_list != NULL) delete this->config_list; if (this->config_list != NULL) delete this->config_list;
} }
AIInfo *AIConfig::GetInfo() AIInfo *AIConfig::GetInfo() const
{ {
return this->info; return this->info;
} }
@ -103,9 +103,9 @@ AIConfig *AIConfig::GetConfig(CompanyID company, bool forceNewgameSetting)
return *config; 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 */ /* 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 (it == this->settings.end() || ((_game_mode == GM_MENU) ? _settings_newgame.difficulty.diff_level : _settings_game.difficulty.diff_level) != 3) {
if (this->info == NULL) { if (this->info == NULL) {
@ -162,17 +162,17 @@ void AIConfig::AddRandomDeviation()
} }
} }
bool AIConfig::HasAI() bool AIConfig::HasAI() const
{ {
return this->info != NULL; return this->info != NULL;
} }
const char *AIConfig::GetName() const char *AIConfig::GetName() const
{ {
return this->name; return this->name;
} }
int AIConfig::GetVersion() int AIConfig::GetVersion() const
{ {
return this->version; return this->version;
} }
@ -203,10 +203,10 @@ void AIConfig::StringToSettings(const char *value)
free(value_copy); free(value_copy);
} }
void AIConfig::SettingsToString(char *string, size_t size) void AIConfig::SettingsToString(char *string, size_t size) const
{ {
string[0] = '\0'; 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]; char no[10];
snprintf(no, sizeof(no), "%d", (*it).second); snprintf(no, sizeof(no), "%d", (*it).second);

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

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

@ -70,7 +70,7 @@ public:
/** /**
* Let the VM collect any garbage. * Let the VM collect any garbage.
*/ */
void CollectGarbage(); void CollectGarbage() const;
/** /**
* Get the storage of this AI. * Get the storage of this AI.
@ -105,7 +105,7 @@ public:
/** /**
* Return the "this AI died" value * 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. * Call the AI Save function and save all data in the savegame.

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

@ -41,7 +41,7 @@ public:
/** /**
* Select a Random AI. * Select a Random AI.
*/ */
class AIInfo *SelectRandomAI(); class AIInfo *SelectRandomAI() const;
/** /**
* Find an AI by name. * Find an AI by name.
@ -51,7 +51,7 @@ public:
/** /**
* Get the list of available AIs for the console. * 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. * Get the list of all registered AIs.

Loading…
Cancel
Save