| 580 | } |
| 581 | |
| 582 | static void on_new_active_unit(color_ostream& out, void* data) { |
| 583 | int32_t unit_id = reinterpret_cast<std::intptr_t>(data); |
| 584 | auto unit = df::unit::find(unit_id); |
| 585 | if (!unit || unit->hist_figure_id < 0) |
| 586 | return; |
| 587 | TRACE(event,out).print("unit {} ({}) arrived on map (hfid: {}, in pending: {})\n", |
| 588 | unit->id, DF2CONSOLE(Units::getReadableName(unit)), unit->hist_figure_id, |
| 589 | pending_reassignment.contains(unit->hist_figure_id)); |
| 590 | auto hfid = unit->hist_figure_id; |
| 591 | auto it = pending_reassignment.find(hfid); |
| 592 | if (it == pending_reassignment.end()) |
| 593 | return; |
| 594 | INFO(event,out).print("preserve-rooms: restoring room ownership for {}\n", |
| 595 | DF2CONSOLE(Units::getReadableName(unit))); |
| 596 | for (auto zone_id : it->second) { |
| 597 | reserved_zones.erase(zone_id); |
| 598 | auto zone = virtual_cast<df::building_civzonest>(df::building::find(zone_id)); |
| 599 | if (!zone) |
| 600 | continue; |
| 601 | zone->spec_sub_flag.bits.active = true; |
| 602 | if (zone->assigned_unit_id != -1 || spouse_has_sharable_room(out, hfid, zone->type)) |
| 603 | continue; |
| 604 | DEBUG(event,out).print("reassigning zone {}\n", zone->id); |
| 605 | Buildings::setOwner(zone, unit); |
| 606 | } |
| 607 | pending_reassignment.erase(it); |
| 608 | } |
| 609 | |
| 610 | ///////////////////////////////////////////////////// |
| 611 | // Lua API |