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.

develop
expwnent 2013-10-20 14:37:34 -04:00
parent 39553cfb6d
commit d78a111f02
1 changed files with 14 additions and 3 deletions

@ -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<Plugin*,EventHandler> 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<df::construction*> constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end());
//unordered_set<df::construction*> constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end());
multimap<Plugin*,EventHandler> copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end());
unordered_set<df::coord> 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;