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

Function manageNewUnitActiveEvent

library/modules/EventManager.cpp:732–753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

730}
731
732static void manageNewUnitActiveEvent(color_ostream& out) {
733 if (!df::global::world)
734 return;
735
736 multimap<Plugin*,EventHandler> copy(handlers[EventType::UNIT_NEW_ACTIVE].begin(), handlers[EventType::UNIT_NEW_ACTIVE].end());
737 unordered_set<int32_t> next_activeUnits;
738 vector<int32_t> newly_active_unit_ids;
739 for (df::unit* unit : df::global::world->units.active) {
740 if (!Units::isActive(unit))
741 continue;
742 next_activeUnits.emplace(unit->id);
743 if (!activeUnits.count(unit->id))
744 newly_active_unit_ids.emplace_back(unit->id);
745 }
746 for (int32_t unit_id : newly_active_unit_ids) {
747 for (auto &[_,handle] : copy) {
748 DEBUG(log,out).print("calling handler for new unit event\n");
749 run_handler(out, EventType::UNIT_NEW_ACTIVE, handle, (void*) intptr_t(unit_id)); // intptr_t() avoids cast from smaller type warning
750 }
751 }
752 activeUnits = std::move(next_activeUnits);
753}
754
755
756static void manageUnitDeathEvent(color_ostream& out) {

Callers

nothing calls this directly

Calls 5

run_handlerFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
countMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected