Team: range-for

This commit is contained in:
Charles Dang 2017-10-25 07:05:30 +11:00
parent d587ad36ec
commit f878433847

View file

@ -412,8 +412,8 @@ void team::write(config& cfg) const
cfg["gold"] = gold_; cfg["gold"] = gold_;
// Write village locations // Write village locations
for(std::set<map_location>::const_iterator t = villages_.begin(); t != villages_.end(); ++t) { for(const map_location& loc : villages_) {
t->write(cfg.add_child("village")); loc.write(cfg.add_child("village"));
} }
cfg["shroud_data"] = shroud_.write(); cfg["shroud_data"] = shroud_.write();
@ -520,13 +520,13 @@ bool team::calculate_is_enemy(size_t index) const
<< info_.team_name << "], their team_name is [" << resources::gameboard->teams()[index].info_.team_name << info_.team_name << "], their team_name is [" << resources::gameboard->teams()[index].info_.team_name
<< "]" << std::endl; << "]" << std::endl;
for(std::vector<std::string>::const_iterator t = our_teams.begin(); t != our_teams.end(); ++t) { for(const std::string& t : our_teams) {
if(std::find(their_teams.begin(), their_teams.end(), *t) != their_teams.end()) { if(std::find(their_teams.begin(), their_teams.end(), t) != their_teams.end()) {
LOG_NGE << "team " << info_.side << " found same team name [" << *t << "] in team " << index + 1 LOG_NGE << "team " << info_.side << " found same team name [" << t << "] in team " << index + 1
<< std::endl; << std::endl;
return false; return false;
} else { } else {
LOG_NGE << "team " << info_.side << " not found same team name [" << *t << "] in team " << index + 1 LOG_NGE << "team " << info_.side << " not found same team name [" << t << "] in team " << index + 1
<< std::endl; << std::endl;
} }
} }
@ -794,8 +794,8 @@ void team::shroud_map::reset()
return; return;
} }
for(std::vector<std::vector<bool>>::iterator i = data_.begin(); i != data_.end(); ++i) { for(auto& i : data_) {
std::fill(i->begin(), i->end(), false); std::fill(i.begin(), i.end(), false);
} }
} }
@ -843,11 +843,11 @@ bool team::shroud_map::shared_value(const std::vector<const shroud_map*>& maps,
std::string team::shroud_map::write() const std::string team::shroud_map::write() const
{ {
std::stringstream shroud_str; std::stringstream shroud_str;
for(std::vector<std::vector<bool>>::const_iterator sh = data_.begin(); sh != data_.end(); ++sh) { for(const auto& sh : data_) {
shroud_str << '|'; shroud_str << '|';
for(std::vector<bool>::const_iterator i = sh->begin(); i != sh->end(); ++i) { for(bool i : sh) {
shroud_str << (*i ? '1' : '0'); shroud_str << (i ? '1' : '0');
} }
shroud_str << '\n'; shroud_str << '\n';
@ -860,15 +860,15 @@ void team::shroud_map::read(const std::string& str)
{ {
data_.clear(); data_.clear();
for(std::string::const_iterator sh = str.begin(); sh != str.end(); ++sh) { for(const char sh : str) {
if(*sh == '|') { if(sh == '|') {
data_.resize(data_.size() + 1); data_.resize(data_.size() + 1);
} }
if(data_.empty() == false) { if(data_.empty() == false) {
if(*sh == '1') { if(sh == '1') {
data_.back().push_back(true); data_.back().push_back(true);
} else if(*sh == '0') { } else if(sh == '0') {
data_.back().push_back(false); data_.back().push_back(false);
} }
} }
@ -878,14 +878,14 @@ void team::shroud_map::read(const std::string& str)
void team::shroud_map::merge(const std::string& str) void team::shroud_map::merge(const std::string& str)
{ {
int x = 0, y = 0; int x = 0, y = 0;
for(std::string::const_iterator sh = str.begin(); sh != str.end(); ++sh) { for(const char sh : str) {
if(*sh == '|' && sh != str.begin()) { if(sh == '|' && sh != str.front()) {
y = 0; y = 0;
x++; x++;
} else if(*sh == '1') { } else if(sh == '1') {
clear(x, y); clear(x, y);
y++; y++;
} else if(*sh == '0') { } else if(sh == '0') {
y++; y++;
} }
} }
@ -898,12 +898,12 @@ bool team::shroud_map::copy_from(const std::vector<const shroud_map*>& maps)
} }
bool cleared = false; bool cleared = false;
for(std::vector<const shroud_map*>::const_iterator i = maps.begin(); i != maps.end(); ++i) { for(const shroud_map* m : maps) {
if((*i)->enabled_ == false) { if(m->enabled_ == false) {
continue; continue;
} }
const std::vector<std::vector<bool>>& v = (*i)->data_; const std::vector<std::vector<bool>>& v = m->data_;
for(size_t x = 0; x != v.size(); ++x) { for(size_t x = 0; x != v.size(); ++x) {
for(size_t y = 0; y != v[x].size(); ++y) { for(size_t y = 0; y != v[x].size(); ++y) {
if(v[x][y]) { if(v[x][y]) {
@ -962,8 +962,8 @@ std::string team::get_side_highlight_pango(int side)
void team::log_recruitable() const void team::log_recruitable() const
{ {
LOG_NG << "Adding recruitable units: \n"; LOG_NG << "Adding recruitable units: \n";
for(std::set<std::string>::const_iterator it = info_.can_recruit.begin(); it != info_.can_recruit.end(); ++it) { for(const std::string& recruit : info_.can_recruit) {
LOG_NG << *it << std::endl; LOG_NG << recruit << std::endl;
} }
LOG_NG << "Added all recruitable units\n"; LOG_NG << "Added all recruitable units\n";