Skip to content

Commit

Permalink
Units: range-for
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Mar 5, 2018
1 parent 019ca25 commit 61cd444
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
30 changes: 16 additions & 14 deletions src/units/abilities.cpp
Expand Up @@ -587,8 +587,8 @@ bool attack_type::get_special_bool(const std::string& special, bool simple_check
// If we make it to here, then either list.empty() or !simple_check.
// So if the list is not empty, then this is not a simple check and
// we need to check each special in the list to see if any are active.
for (std::vector<const config*>::iterator i = list.begin(), i_end = list.end(); i != i_end; ++i) {
if ( special_active(**i, AFFECT_SELF) ) {
for(const config* entry : list) {
if ( special_active(*entry, AFFECT_SELF) ) {
return true;
}
}
Expand All @@ -600,8 +600,8 @@ bool attack_type::get_special_bool(const std::string& special, bool simple_check

std::vector<const config*> list;
get_special_children(list, other_attack_->specials_, special);
for (std::vector<const config*>::iterator i = list.begin(), i_end = list.end(); i != i_end; ++i) {
if ( other_attack_->special_active(**i, AFFECT_OTHER) ) {
for(const config* entry : list) {
if ( other_attack_->special_active(*entry, AFFECT_OTHER) ) {
return true;
}
}
Expand Down Expand Up @@ -1208,19 +1208,21 @@ effect::effect(const unit_ability_list& list, int def, bool backstab) :
*/
double multiplier = 1.0;
double divisor = 1.0;
std::map<std::string,individual_effect>::const_iterator e, e_end;
for (e = values_mul.begin(), e_end = values_mul.end(); e != e_end; ++e) {
multiplier *= e->second.value/100.0;
effect_list_.push_back(e->second);

for(const auto& val : values_mul) {
multiplier *= val.second.value/100.0;
effect_list_.push_back(val.second);
}
for (e = values_div.begin(), e_end = values_div.end(); e != e_end; ++e) {
divisor *= e->second.value/100.0;
effect_list_.push_back(e->second);

for(const auto& val : values_div) {
divisor *= val.second.value/100.0;
effect_list_.push_back(val.second);
}

int addition = 0;
for (e = values_add.begin(), e_end = values_add.end(); e != e_end; ++e) {
addition += e->second.value;
effect_list_.push_back(e->second);
for(const auto& val : values_add) {
addition += val.second.value;
effect_list_.push_back(val.second);
}

composite_value_ = int((value_set + addition) * multiplier / divisor);
Expand Down
8 changes: 4 additions & 4 deletions src/units/animation_component.cpp
Expand Up @@ -31,14 +31,14 @@ const unit_animation* unit_animation_component::choose_animation(const display&
// Select one of the matching animations at random
std::vector<const unit_animation*> options;
int max_val = unit_animation::MATCH_FAIL;
for(std::vector<unit_animation>::const_iterator i = animations_.begin(); i != animations_.end(); ++i) {
int matching = i->matches(disp,loc,second_loc,&u_,event,value,hit,attack,second_attack,swing_num);
for(const unit_animation& anim : animations_) {
int matching = anim.matches(disp,loc,second_loc,&u_,event,value,hit,attack,second_attack,swing_num);
if(matching > unit_animation::MATCH_FAIL && matching == max_val) {
options.push_back(&*i);
options.push_back(&anim);
} else if(matching > max_val) {
max_val = matching;
options.clear();
options.push_back(&*i);
options.push_back(&anim);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/units/drawer.cpp
Expand Up @@ -308,8 +308,8 @@ void unit_drawer::redraw_unit (const unit & u) const
}
}

for(std::vector<std::string>::const_iterator ov = u.overlays().begin(); ov != u.overlays().end(); ++ov) {
const surface ov_img(image::get_image(*ov, image::SCALED_TO_ZOOM));
for(const std::string& ov : u.overlays()) {
const surface ov_img(image::get_image(ov, image::SCALED_TO_ZOOM));
if(ov_img != nullptr) {
disp.drawing_buffer_add(display::LAYER_UNIT_BAR,
loc, xsrc+xoff, ysrc+yoff+adjusted_params.y, ov_img);
Expand Down
4 changes: 2 additions & 2 deletions src/units/map.cpp
Expand Up @@ -38,8 +38,8 @@ unit_map::unit_map(const unit_map& that)
: umap_()
, lmap_()
{
for(const_unit_iterator i = that.begin(); i != that.end(); ++i) {
add(i->get_location(), *i);
for(const auto& u : that) {
add(u.get_location(), u);
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/units/types.cpp
Expand Up @@ -263,9 +263,8 @@ void unit_type::build_help_index(
// if num_traits is not defined, we use the num_traits from race
num_traits_ = cfg_["num_traits"].to_int(race_->num_traits());

const std::vector<std::string> genders = utils::split(cfg_["gender"]);
for(std::vector<std::string>::const_iterator g = genders.begin(); g != genders.end(); ++g) {
genders_.push_back(string_gender(*g));
for(const std::string& g : utils::split(cfg_["gender"])) {
genders_.push_back(string_gender(g));
}

// For simplicity in other parts of the code, we must have at least one gender.
Expand Down Expand Up @@ -645,9 +644,9 @@ void unit_type::add_advancement(const unit_type& to_unit, int xp)
// Since these are still a rare and special-purpose feature,
// we assume that the unit designer knows what they're doing,
// and don't block advancements that would remove a variation.
for(variations_map::iterator v = variations_.begin(); v != variations_.end(); ++v) {
for(auto& v : variations_) {
LOG_CONFIG << "variation advancement: ";
v->second.add_advancement(to_unit, xp);
v.second.add_advancement(to_unit, xp);
}
}
}
Expand Down Expand Up @@ -1328,8 +1327,8 @@ void unit_type_data::build_all(unit_type::BUILD_STATUS status)

assert(unit_cfg_ != nullptr);

for(unit_type_map::iterator u = types_.begin(), u_end = types_.end(); u != u_end; ++u) {
build_unit_type(u->second, status);
for(const auto& type : types_) {
build_unit_type(type.second, status);

gui2::dialogs::loading_screen::progress();
}
Expand All @@ -1338,8 +1337,8 @@ void unit_type_data::build_all(unit_type::BUILD_STATUS status)
// (Currently, this could be simply a test for build_status_ == NOT_BUILT,
// but to guard against future changes, use a more thorough test.)
if(build_status_ < unit_type::CREATED && unit_type::CREATED <= status) {
for(unit_type_map::iterator u = types_.begin(), u_end = types_.end(); u != u_end; ++u) {
add_advancement(u->second);
for(auto& type : types_) {
add_advancement(type.second);
}
}

Expand Down

0 comments on commit 61cd444

Please sign in to comment.