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

Function manageUnitDeathEvent

library/modules/EventManager.cpp:756–781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

754
755
756static void manageUnitDeathEvent(color_ostream& out) {
757 if (!df::global::world)
758 return;
759 multimap<Plugin*,EventHandler> copy(handlers[EventType::UNIT_DEATH].begin(), handlers[EventType::UNIT_DEATH].end());
760 vector<int32_t> dead_unit_ids;
761 for (auto unit : df::global::world->units.all) {
762 //if ( unit->counters.death_id == -1 ) {
763 if ( Units::isActive(unit) ) {
764 livingUnits.insert(unit->id);
765 continue;
766 }
767 if (!Units::isDead(unit)) continue; // for units that have left the map but aren't dead
768 //dead: if dead since last check, trigger events
769 if ( livingUnits.find(unit->id) == livingUnits.end() )
770 continue;
771 livingUnits.erase(unit->id);
772 dead_unit_ids.emplace_back(unit->id);
773 }
774
775 for (int32_t unit_id : dead_unit_ids) {
776 for (auto &[_,handle] : copy) {
777 DEBUG(log,out).print("calling handler for unit death event\n");
778 run_handler(out, EventType::UNIT_DEATH, handle, (void*)intptr_t(unit_id));
779 }
780 }
781}
782
783static void manageItemCreationEvent(color_ostream& out) {
784 if (!df::global::world)

Callers

nothing calls this directly

Calls 7

run_handlerFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
findMethod · 0.45
eraseMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected