MCPcopy Create free account
hub / github.com/DFHack/dfhack / on_new_active_unit

Function on_new_active_unit

plugins/preserve-rooms.cpp:582–608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

580}
581
582static 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

Callers

nothing calls this directly

Calls 7

spouse_has_sharable_roomFunction · 0.85
containsMethod · 0.80
findFunction · 0.50
printMethod · 0.45
findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected