summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2020-12-25 19:38:18 +0100
committerGitHub <noreply@github.com>2020-12-25 19:38:18 +0100
commitf66baa444ff5575b2b40e3bfd514cdb463f6f560 (patch)
treef0977f8443106be749dac7a84fb01c2eebaedd45 /src/ai
parent9add62796c91c8eb7dd971cb21c8cdeba49cadfa (diff)
downloadopenttd-f66baa444ff5575b2b40e3bfd514cdb463f6f560.tar.xz
Codechange: use C++11 constructs for for-each loops (#8432)
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai_gui.cpp25
-rw-r--r--src/ai/ai_scanner.cpp17
2 files changed, 21 insertions, 21 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index d61cfea0d..078bde4e1 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -87,8 +87,8 @@ struct AIListWindow : public Window {
if (GetConfig(slot)->HasScript()) {
ScriptInfo *info = GetConfig(slot)->GetInfo();
int i = 0;
- for (ScriptInfoList::const_iterator it = this->info_list->begin(); it != this->info_list->end(); it++, i++) {
- if ((*it).second == info) {
+ for (const auto &item : *this->info_list) {
+ if (item.second == info) {
this->selected = i;
break;
}
@@ -127,10 +127,11 @@ struct AIListWindow : public Window {
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_LEFT, y + WD_MATRIX_TOP, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
y += this->line_height;
}
- ScriptInfoList::const_iterator it = this->info_list->begin();
- for (int i = 1; it != this->info_list->end(); i++, it++) {
+ int i = 1;
+ for (const auto &item : *this->info_list) {
+ i++;
if (this->vscroll->IsVisible(i)) {
- DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, (*it).second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
+ DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
y += this->line_height;
}
}
@@ -138,9 +139,10 @@ struct AIListWindow : public Window {
}
case WID_AIL_INFO_BG: {
AIInfo *selected_info = nullptr;
- ScriptInfoList::const_iterator it = this->info_list->begin();
- for (int i = 1; selected_info == nullptr && it != this->info_list->end(); i++, it++) {
- if (this->selected == i - 1) selected_info = static_cast<AIInfo *>((*it).second);
+ int i = 1;
+ for (const auto &item : *this->info_list) {
+ i++;
+ if (this->selected == i - 1) selected_info = static_cast<AIInfo *>(item.second);
}
/* Some info about the currently selected AI. */
if (selected_info != nullptr) {
@@ -334,11 +336,10 @@ struct AISettingsWindow : public Window {
{
visible_settings.clear();
- ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
- for (; it != this->ai_config->GetConfigList()->end(); it++) {
- bool no_hide = (it->flags & SCRIPTCONFIG_DEVELOPER) == 0;
+ for (const auto &item : *this->ai_config->GetConfigList()) {
+ bool no_hide = (item.flags & SCRIPTCONFIG_DEVELOPER) == 0;
if (no_hide || _settings_client.gui.ai_developer_tools) {
- visible_settings.push_back(&(*it));
+ visible_settings.push_back(&item);
}
}
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index aeb5b50fa..1431a2820 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -61,8 +61,8 @@ void AIScannerInfo::RegisterAPI(class Squirrel *engine)
AIInfo *AIScannerInfo::SelectRandomAI() const
{
uint num_random_ais = 0;
- for (ScriptInfoList::const_iterator it = this->info_single_list.begin(); it != this->info_single_list.end(); it++) {
- AIInfo *i = static_cast<AIInfo *>((*it).second);
+ for (const auto &item : info_single_list) {
+ AIInfo *i = static_cast<AIInfo *>(item.second);
if (i->UseAsRandomAI()) num_random_ais++;
}
@@ -121,11 +121,10 @@ AIInfo *AIScannerInfo::FindInfo(const char *nameParam, int versionParam, bool fo
/* See if there is a compatible AI which goes by that name, with the highest
* version which allows loading the requested version */
- ScriptInfoList::iterator it = this->info_list.begin();
- for (; it != this->info_list.end(); it++) {
- AIInfo *i = static_cast<AIInfo *>((*it).second);
+ for (const auto &item : this->info_list) {
+ AIInfo *i = static_cast<AIInfo *>(item.second);
if (strcasecmp(ai_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
- version = (*it).second->GetVersion();
+ version = item.second->GetVersion();
info = i;
}
}
@@ -158,8 +157,8 @@ AILibrary *AIScannerLibrary::FindLibrary(const char *library, int version)
strtolower(library_name);
/* Check if the library + version exists */
- ScriptInfoList::iterator iter = this->info_list.find(library_name);
- if (iter == this->info_list.end()) return nullptr;
+ ScriptInfoList::iterator it = this->info_list.find(library_name);
+ if (it == this->info_list.end()) return nullptr;
- return static_cast<AILibrary *>((*iter).second);
+ return static_cast<AILibrary *>((*it).second);
}