using std::erase_if instead of iterator loop

develop
Najeeb Al-Shabibi 2023-09-29 14:30:01 +01:00
parent 579fe6ee76
commit 028fbc34ad
1 changed files with 9 additions and 10 deletions

@ -222,28 +222,27 @@ static void update_tomb_assignments(color_ostream &out) {
}
// now check our civzones for unassignment / deleted zone /
for (auto it = tomb_assignments.begin(); it != tomb_assignments.end(); ++it){
auto &[unit_id, building_id] = *it;
// now check our civzones for unassignment / deleted zone
std::erase_if(tomb_assignments,[&](const auto& p){
auto &[unit_id, building_id] = p;
const int tomb_idx = binsearch_index(world->buildings.other.ZONE_TOMB, building_id);
if (tomb_idx == -1) {
out.print("%s tomb missing: %d - removing\n", plugin_name, building_id);
it = tomb_assignments.erase(it);
continue;
return true;
}
const auto tomb = virtual_cast<df::building_civzonest>(world->buildings.other.ZONE_TOMB[tomb_idx]);
if (!tomb || !tomb->flags.bits.exists) {
out.print("%s tomb missing: %d - removing\n", plugin_name, building_id);
it = tomb_assignments.erase(it);
continue;
return true;
}
if (tomb->assigned_unit_id != unit_id) {
out.print("%s unassigned unit %d from tomb %d - removing\n", plugin_name, unit_id, building_id);
it = tomb_assignments.erase(it);
continue;
return true;
}
}
return false;
});
}