diff options
author | rubidium <rubidium@openttd.org> | 2010-01-07 00:09:27 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-01-07 00:09:27 +0000 |
commit | 0e404038f27544fe7ebad2127b1651cd471732b6 (patch) | |
tree | 2ff838abb0b51b6374b89c68770e32acb03208cc /src/ai | |
parent | 1967084bc3800615e6584d9d3115e0109a0e40da (diff) | |
download | openttd-0e404038f27544fe7ebad2127b1651cd471732b6.tar.xz |
(svn r18747) -Codechange: add some constness to the AI code
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/ai_config.cpp | 16 | ||||
-rw-r--r-- | src/ai/ai_config.hpp | 12 | ||||
-rw-r--r-- | src/ai/ai_instance.cpp | 2 | ||||
-rw-r--r-- | src/ai/ai_instance.hpp | 4 | ||||
-rw-r--r-- | src/ai/ai_scanner.cpp | 10 | ||||
-rw-r--r-- | src/ai/ai_scanner.hpp | 4 |
6 files changed, 24 insertions, 24 deletions
diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp index e92d3978d..aec2760d5 100644 --- a/src/ai/ai_config.cpp +++ b/src/ai/ai_config.cpp @@ -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); diff --git a/src/ai/ai_config.hpp b/src/ai/ai_config.hpp index 8b6007c67..5008b3a3e 100644 --- a/src/ai/ai_config.hpp +++ b/src/ai/ai_config.hpp @@ -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; diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index 7adb797f8..d91fff0a1 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -391,7 +391,7 @@ void AIInstance::GameLoop() } } -void AIInstance::CollectGarbage() +void AIInstance::CollectGarbage() const { if (this->is_started && !this->IsDead()) this->engine->CollectGarbage(); } diff --git a/src/ai/ai_instance.hpp b/src/ai/ai_instance.hpp index b2cc2f49c..f0862ea9e 100644 --- a/src/ai/ai_instance.hpp +++ b/src/ai/ai_instance.hpp @@ -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. diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp index 7467f773a..065d4e4c2 100644 --- a/src/ai/ai_scanner.cpp +++ b/src/ai/ai_scanner.cpp @@ -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()); diff --git a/src/ai/ai_scanner.hpp b/src/ai/ai_scanner.hpp index e65a7f354..ff3ce7790 100644 --- a/src/ai/ai_scanner.hpp +++ b/src/ai/ai_scanner.hpp @@ -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. |