| 754 | |
| 755 | |
| 756 | static 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 | |
| 783 | static void manageItemCreationEvent(color_ostream& out) { |
| 784 | if (!df::global::world) |