From d78a111f0251ef7127f167438f9882fdbf551adc Mon Sep 17 00:00:00 2001 From: expwnent Date: Sun, 20 Oct 2013 14:37:34 -0400 Subject: [PATCH] EventManager: Fixed the death event, fixed another problem with construction event, and made EventManager use world->frame_counter for scheduling event checking in order to make it work in arena mode. --- library/modules/EventManager.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/library/modules/EventManager.cpp b/library/modules/EventManager.cpp index 4ad3d89c0..3fd2ad48d 100644 --- a/library/modules/EventManager.cpp +++ b/library/modules/EventManager.cpp @@ -17,6 +17,7 @@ #include "df/job_list_link.h" #include "df/ui.h" #include "df/unit.h" +#include "df/unit_flags1.h" #include "df/unit_inventory_item.h" #include "df/unit_syndrome.h" #include "df/world.h" @@ -203,6 +204,11 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event lastTick = 0; nextInvasion = df::global::ui->invasions.next_id; gameLoaded = true; + + for ( auto i = df::global::world->constructions.begin(); i != df::global::world->constructions.end(); i++ ) { + df::construction* constr = *i; + constructions[constr->pos] = *constr; + } } } @@ -212,11 +218,14 @@ void DFHack::EventManager::manageEvents(color_ostream& out) { } CoreSuspender suspender; + /* uint32_t tick = DFHack::World::ReadCurrentYear()*ticksPerYear + DFHack::World::ReadCurrentTick(); + */ /*if ( tick - lastTick > 1 ) { out.print("EventManager missed tick: %d, %d, (%d)\n", lastTick, tick, tick - lastTick); }*/ + int32_t tick = df::global::world->frame_counter; for ( size_t a = 0; a < EventType::EVENT_MAX; a++ ) { if ( handlers[a].empty() ) @@ -418,7 +427,8 @@ static void manageUnitDeathEvent(color_ostream& out) { multimap copy(handlers[EventType::UNIT_DEATH].begin(), handlers[EventType::UNIT_DEATH].end()); for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) { df::unit* unit = df::global::world->units.all[a]; - if ( unit->counters.death_id == -1 ) { + //if ( unit->counters.death_id == -1 ) { + if ( ! unit->flags1.bits.dead ) { livingUnits.insert(unit->id); continue; } @@ -507,7 +517,7 @@ static void manageBuildingEvent(color_ostream& out) { } static void manageConstructionEvent(color_ostream& out) { - unordered_set constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end()); + //unordered_set constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end()); multimap copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end()); unordered_set toDelete; @@ -527,7 +537,8 @@ static void manageConstructionEvent(color_ostream& out) { constructions.erase(*a); } - for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); a++ ) { + //for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); a++ ) { + for ( auto a = df::global::world->constructions.begin(); a != df::global::world->constructions.end(); a++ ) { df::construction* construction = *a; bool b = constructions.find(construction->pos) != constructions.end(); constructions[construction->pos] = *construction;