diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp --- a/src/script/script_config.cpp +++ b/src/script/script_config.cpp @@ -32,9 +32,9 @@ void ScriptConfig::Change(const char *na if (_game_mode == GM_NORMAL && this->info != nullptr) { /* If we're in an existing game and the Script is changed, set all settings * for the Script that have the random flag to a random value. */ - for (ScriptConfigItemList::const_iterator it = this->info->GetConfigList()->begin(); it != this->info->GetConfigList()->end(); it++) { - if ((*it).flags & SCRIPTCONFIG_RANDOM) { - this->SetSetting((*it).name, InteractiveRandomRange((*it).max_value + 1 - (*it).min_value) + (*it).min_value); + for (const auto &item : *this->info->GetConfigList()) { + if (item.flags & SCRIPTCONFIG_RANDOM) { + this->SetSetting(item.name, InteractiveRandomRange(item.max_value + 1 - item.min_value) + item.min_value); } } this->AddRandomDeviation(); @@ -49,8 +49,8 @@ ScriptConfig::ScriptConfig(const ScriptC this->config_list = nullptr; this->is_random = config->is_random; - for (SettingValueList::const_iterator it = config->settings.begin(); it != config->settings.end(); it++) { - this->settings[stredup((*it).first)] = (*it).second; + for (const auto &item : config->settings) { + this->settings[stredup(item.first)] = item.second; } this->AddRandomDeviation(); } @@ -79,24 +79,24 @@ const ScriptConfigItemList *ScriptConfig void ScriptConfig::ClearConfigList() { - for (SettingValueList::iterator it = this->settings.begin(); it != this->settings.end(); it++) { - free((*it).first); + for (const auto &item : this->settings) { + free(item.first); } this->settings.clear(); } void ScriptConfig::AnchorUnchangeableSettings() { - for (ScriptConfigItemList::const_iterator it = this->GetConfigList()->begin(); it != this->GetConfigList()->end(); it++) { - if (((*it).flags & SCRIPTCONFIG_INGAME) == 0) { - this->SetSetting((*it).name, this->GetSetting((*it).name)); + for (const auto &item : *this->GetConfigList()) { + if ((item.flags & SCRIPTCONFIG_INGAME) == 0) { + this->SetSetting(item.name, this->GetSetting(item.name)); } } } int ScriptConfig::GetSetting(const char *name) const { - SettingValueList::const_iterator it = this->settings.find(name); + const auto it = this->settings.find(name); if (it == this->settings.end()) return this->info->GetSettingDefaultValue(name); return (*it).second; } @@ -111,7 +111,7 @@ void ScriptConfig::SetSetting(const char value = Clamp(value, config_item->min_value, config_item->max_value); - SettingValueList::iterator it = this->settings.find(name); + const auto it = this->settings.find(name); if (it != this->settings.end()) { (*it).second = value; } else { @@ -121,17 +121,17 @@ void ScriptConfig::SetSetting(const char void ScriptConfig::ResetSettings() { - for (SettingValueList::iterator it = this->settings.begin(); it != this->settings.end(); it++) { - free((*it).first); + for (const auto &item : this->settings) { + free(item.first); } this->settings.clear(); } void ScriptConfig::AddRandomDeviation() { - for (ScriptConfigItemList::const_iterator it = this->GetConfigList()->begin(); it != this->GetConfigList()->end(); it++) { - if ((*it).random_deviation != 0) { - this->SetSetting((*it).name, InteractiveRandomRange((*it).random_deviation * 2 + 1) - (*it).random_deviation + this->GetSetting((*it).name)); + for (const auto &item : *this->GetConfigList()) { + if (item.random_deviation != 0) { + this->SetSetting(item.name, InteractiveRandomRange(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name)); } } } @@ -186,16 +186,16 @@ void ScriptConfig::SettingsToString(char { char *s = string; *s = '\0'; - for (SettingValueList::const_iterator it = this->settings.begin(); it != this->settings.end(); it++) { + for (const auto &item : this->settings) { char no[10]; - seprintf(no, lastof(no), "%d", (*it).second); + seprintf(no, lastof(no), "%d", item.second); /* Check if the string would fit in the destination */ - size_t needed_size = strlen((*it).first) + 1 + strlen(no); + size_t needed_size = strlen(item.first) + 1 + strlen(no); /* If it doesn't fit, skip the next settings */ if (string + needed_size > last) break; - s = strecat(s, (*it).first, last); + s = strecat(s, item.first, last); s = strecat(s, "=", last); s = strecat(s, no, last); s = strecat(s, ",", last);