stop reserving zones for dead units or units that are no longer in an army
| 390 | |
| 391 | // stop reserving zones for dead units or units that are no longer in an army |
| 392 | static void scrub_reservations(color_ostream &out) { |
| 393 | vector<int32_t> hfids_to_scrub; |
| 394 | for (auto &[hfid, zone_ids] : pending_reassignment) { |
| 395 | auto hf = df::historical_figure::find(hfid); |
| 396 | if (hf) { |
| 397 | // don't scrub alive units that are still in traveling armies |
| 398 | if (hf->died_year == -1 && hf->info && hf->info->whereabouts && hf->info->whereabouts->army_id > -1) |
| 399 | continue; |
| 400 | // don't scrub units that have returned but are not yet active |
| 401 | if (auto unit = df::unit::find(hf->unit_id)) { |
| 402 | if (unit->flags1.bits.incoming) |
| 403 | continue; |
| 404 | } |
| 405 | } |
| 406 | DEBUG(cycle,out).print("removed reservation for dead, culled, or non-army hfid {}: {}\n", hfid, |
| 407 | hf ? DF2CONSOLE(Units::getReadableName(hf)) : "culled"); |
| 408 | hfids_to_scrub.push_back(hfid); |
| 409 | for (int32_t zone_id : zone_ids) { |
| 410 | if (scrub_id_from_entries(hfid, zone_id, reserved_zones)) { |
| 411 | if (auto zone = virtual_cast<df::building_civzonest>(df::building::find(zone_id))) |
| 412 | zone->spec_sub_flag.bits.active = true; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | for (int32_t hfid : hfids_to_scrub) |
| 417 | pending_reassignment.erase(hfid); |
| 418 | } |
| 419 | |
| 420 | static bool was_expelled(df::historical_figure *hf) { |
| 421 | if (!hf || !hf->info || !hf->info->whereabouts) |
no test coverage detected