EventManager: unload event for convenience.

develop
expwnent 2014-06-29 10:03:55 -04:00
parent f88c176dd3
commit 961d033ade
5 changed files with 20 additions and 4 deletions

@ -1,7 +1,9 @@
DFHack future
Internals:
EventManager: added ON_REPORT and UNIT_ATTACK events and exposed them to Lua.
EventManager:
added ON_REPORT and UNIT_ATTACK events and exposed them to Lua.
added UNLOAD event for convenience
New scripts:
add-syndrome.lua
add a syndrome to a unit. many configurable options

@ -30,6 +30,7 @@ namespace DFHack {
INVENTORY_CHANGE,
REPORT,
UNIT_ATTACK,
UNLOAD,
EVENT_MAX
};
}

@ -127,6 +127,7 @@ static void manageInvasionEvent(color_ostream& out);
static void manageEquipmentEvent(color_ostream& out);
static void manageReportEvent(color_ostream& out);
static void manageUnitAttackEvent(color_ostream& out);
static void manageUnloadEvent(color_ostream& out){};
typedef void (*eventManager_t)(color_ostream&);
@ -143,6 +144,7 @@ static const eventManager_t eventManager[] = {
manageEquipmentEvent,
manageReportEvent,
manageUnitAttackEvent,
manageUnloadEvent,
};
//job initiated
@ -208,6 +210,11 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event
lastReport = -1;
lastReportUnitAttack = -1;
gameLoaded = false;
multimap<Plugin*,EventHandler> copy(handlers[EventType::UNLOAD].begin(), handlers[EventType::UNLOAD].end());
for (auto a = copy.begin(); a != copy.end(); a++ ) {
(*a).second.eventHandler(out, NULL);
}
} else if ( event == DFHack::SC_MAP_LOADED ) {
/*
int32_t tick = df::global::world->frame_counter;

@ -122,6 +122,7 @@ static void handle_syndrome(color_ostream &out,int32_t,int32_t){};
static void handle_inventory_change(color_ostream& out,int32_t,int32_t,df::unit_inventory_item*,df::unit_inventory_item*){};
static void handle_report(color_ostream& out,int32_t){};
static void handle_unitAttack(color_ostream& out,int32_t,int32_t,int32_t){};
static void handle_unload(color_ostream& out){};
DEFINE_LUA_EVENT_1(onBuildingCreatedDestroyed, handle_int32t, int32_t);
DEFINE_LUA_EVENT_1(onJobInitiated,handle_job_init,df::job*);
DEFINE_LUA_EVENT_1(onJobCompleted,handle_job_complete,df::job*);
@ -132,7 +133,8 @@ DEFINE_LUA_EVENT_2(onSyndrome, handle_syndrome, int32_t,int32_t);
DEFINE_LUA_EVENT_1(onInvasion,handle_int32t,int32_t);
DEFINE_LUA_EVENT_4(onInventoryChange,handle_inventory_change,int32_t,int32_t,df::unit_inventory_item*,df::unit_inventory_item*);
DEFINE_LUA_EVENT_1(onReport,handle_report,int32_t);
DEFINE_LUA_EVENT_3(onUnitAttack,handle_unitAttack,int32_t,int32_t,int32_t)
DEFINE_LUA_EVENT_3(onUnitAttack,handle_unitAttack,int32_t,int32_t,int32_t);
DEFINE_LUA_EVENT_0(onUnload,handle_unload);
DFHACK_PLUGIN_LUA_EVENTS {
DFHACK_LUA_EVENT(onWorkshopFillSidebarMenu),
DFHACK_LUA_EVENT(postWorkshopFillSidebarMenu),
@ -154,6 +156,7 @@ DFHACK_PLUGIN_LUA_EVENTS {
DFHACK_LUA_EVENT(onInventoryChange),
DFHACK_LUA_EVENT(onReport),
DFHACK_LUA_EVENT(onUnitAttack),
DFHACK_LUA_EVENT(onUnload),
DFHACK_LUA_END
};
@ -221,6 +224,9 @@ static void ev_mng_unitAttack(color_ostream& out, void* ptr) {
EventManager::UnitAttackData* data = (EventManager::UnitAttackData*)ptr;
onUnitAttack(out,data->attacker,data->defender,data->wound);
}
static void ev_mng_unload(color_ostream& out, void* ptr) {
onUnload(out);
}
std::vector<int> enabledEventManagerEvents(EventManager::EventType::EVENT_MAX,-1);
typedef void (*handler_t) (color_ostream&,void*);
static const handler_t eventHandlers[] = {
@ -236,6 +242,7 @@ static const handler_t eventHandlers[] = {
ev_mng_inventory,
ev_mng_report,
ev_mng_unitAttack,
ev_mng_unload,
};
static void enableEvent(int evType,int freq)
{

@ -132,6 +132,5 @@ local function invertTable(tbl)
end
return ret
end
eventType=invertTable{[0]="TICK","JOB_INITIATED","JOB_COMPLETED","UNIT_DEATH","ITEM_CREATED",
"BUILDING","CONSTRUCTION","SYNDROME","INVASION","INVENTORY_CHANGE","REPORT","UNIT_ATTACK","EVENT_MAX"}
eventType=invertTable{[0]="TICK","JOB_INITIATED","JOB_COMPLETED","UNIT_DEATH","ITEM_CREATED", "BUILDING","CONSTRUCTION","SYNDROME","INVASION","INVENTORY_CHANGE","REPORT","UNIT_ATTACK","UNLOAD","EVENT_MAX"}
return _ENV