From e4ae1c11f5a662bd8abea4a25e711a0799713b29 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 20 Dec 2015 01:14:13 +0200 Subject: [PATCH] Update eventful's produce hook to new vmethod. Also make all events use no-handler version thus removing lot of unused functions (and empty function calls). --- plugins/eventful.cpp | 68 ++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/plugins/eventful.cpp b/plugins/eventful.cpp index 7ad10a3ba..639a43915 100644 --- a/plugins/eventful.cpp +++ b/plugins/eventful.cpp @@ -95,48 +95,31 @@ static bool is_lua_hook(const std::string &name) static void handle_fillsidebar(color_ostream &out,df::building_actual*,bool *call_native){}; static void handle_postfillsidebar(color_ostream &out,df::building_actual*){}; -static void handle_reaction_done(color_ostream &out,df::reaction*, df::reaction_product_itemst*, df::unit *unit, std::vector *in_items,std::vector *in_reag - , std::vector *out_items,bool *call_native){}; -static void handle_contaminate_wound(color_ostream &out,df::item_actual*,df::unit* unit, df::unit_wound* wound, uint8_t a1, int16_t a2){}; -static void handle_projitem_ci(color_ostream &out,df::proj_itemst*,bool){}; -static void handle_projitem_cm(color_ostream &out,df::proj_itemst*){}; -static void handle_projunit_ci(color_ostream &out,df::proj_unitst*,bool){}; -static void handle_projunit_cm(color_ostream &out,df::proj_unitst*){}; - -DEFINE_LUA_EVENT_2(onWorkshopFillSidebarMenu, handle_fillsidebar, df::building_actual*,bool* ); -DEFINE_LUA_EVENT_1(postWorkshopFillSidebarMenu, handle_postfillsidebar, df::building_actual*); - -DEFINE_LUA_EVENT_7(onReactionComplete, handle_reaction_done,df::reaction*, df::reaction_product_itemst*, df::unit *, std::vector *,std::vector *,std::vector *,bool *); -DEFINE_LUA_EVENT_5(onItemContaminateWound, handle_contaminate_wound, df::item_actual*,df::unit* , df::unit_wound* , uint8_t , int16_t ); +DEFINE_LUA_EVENT_NH_2(onWorkshopFillSidebarMenu, df::building_actual*, bool*); +DEFINE_LUA_EVENT_NH_1(postWorkshopFillSidebarMenu, df::building_actual*); + +DEFINE_LUA_EVENT_NH_7(onReactionComplete, df::reaction*, df::reaction_product_itemst*, df::unit *, std::vector *, std::vector *, std::vector *, bool *); +DEFINE_LUA_EVENT_NH_5(onItemContaminateWound, df::item_actual*, df::unit*, df::unit_wound*, uint8_t, int16_t); //projectiles -DEFINE_LUA_EVENT_2(onProjItemCheckImpact, handle_projitem_ci, df::proj_itemst*,bool ); -DEFINE_LUA_EVENT_1(onProjItemCheckMovement, handle_projitem_cm, df::proj_itemst*); -DEFINE_LUA_EVENT_2(onProjUnitCheckImpact, handle_projunit_ci, df::proj_unitst*,bool ); -DEFINE_LUA_EVENT_1(onProjUnitCheckMovement, handle_projunit_cm, df::proj_unitst* ); +DEFINE_LUA_EVENT_NH_2(onProjItemCheckImpact, df::proj_itemst*, bool); +DEFINE_LUA_EVENT_NH_1(onProjItemCheckMovement, df::proj_itemst*); +DEFINE_LUA_EVENT_NH_2(onProjUnitCheckImpact, df::proj_unitst*, bool); +DEFINE_LUA_EVENT_NH_1(onProjUnitCheckMovement, df::proj_unitst*); //event manager -static void handle_int32t(color_ostream &out,int32_t){}; //we don't use this so why not use it everywhere -static void handle_job_init(color_ostream &out,df::job*){}; -static void handle_job_complete(color_ostream &out,df::job*){}; -static void handle_constructions(color_ostream &out,df::construction*){}; -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){}; -static void handle_interaction(color_ostream& out, std::string, std::string, int32_t, int32_t, int32_t, int32_t){}; -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*); -DEFINE_LUA_EVENT_1(onUnitDeath,handle_int32t,int32_t); -DEFINE_LUA_EVENT_1(onItemCreated,handle_int32t,int32_t); -DEFINE_LUA_EVENT_1(onConstructionCreatedDestroyed, handle_constructions, df::construction*); -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_0(onUnload,handle_unload); -DEFINE_LUA_EVENT_6(onInteraction,handle_interaction, std::string, std::string, int32_t, int32_t, int32_t, int32_t); +DEFINE_LUA_EVENT_NH_1(onBuildingCreatedDestroyed, int32_t); +DEFINE_LUA_EVENT_NH_1(onJobInitiated, df::job*); +DEFINE_LUA_EVENT_NH_1(onJobCompleted, df::job*); +DEFINE_LUA_EVENT_NH_1(onUnitDeath, int32_t); +DEFINE_LUA_EVENT_NH_1(onItemCreated, int32_t); +DEFINE_LUA_EVENT_NH_1(onConstructionCreatedDestroyed, df::construction*); +DEFINE_LUA_EVENT_NH_2(onSyndrome, int32_t, int32_t); +DEFINE_LUA_EVENT_NH_1(onInvasion, int32_t); +DEFINE_LUA_EVENT_NH_4(onInventoryChange, int32_t, int32_t, df::unit_inventory_item*, df::unit_inventory_item*); +DEFINE_LUA_EVENT_NH_1(onReport, int32_t); +DEFINE_LUA_EVENT_NH_3(onUnitAttack, int32_t, int32_t, int32_t); +DEFINE_LUA_EVENT_NH_0(onUnload, std::string, std::string, int32_t, int32_t, int32_t, int32_t); +DEFINE_LUA_EVENT_NH_6(onInteraction, std::string, std::string, int32_t, int32_t, int32_t, int32_t); + DFHACK_PLUGIN_LUA_EVENTS { DFHACK_LUA_EVENT(onWorkshopFillSidebarMenu), DFHACK_LUA_EVENT(postWorkshopFillSidebarMenu), @@ -306,7 +289,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(furnace_hook, fillSidebarMenu); struct product_hook : item_product { typedef item_product interpose_base; - + DEFINE_VMETHOD_INTERPOSE( void, produce, (df::unit *unit, @@ -417,8 +400,6 @@ static bool find_reactions(color_ostream &out) for (size_t i = 0; i < rlist.size(); i++) { - //if (!is_lua_hook(rlist[i]->code)) - // continue; reactions[rlist[i]->code].react = rlist[i]; } @@ -460,7 +441,6 @@ static void world_specific_hooks(color_ostream &out,bool enable) { if(enable && find_reactions(out)) { - //out.print("Detected reaction hooks - enabling plugin.\n"); INTERPOSE_HOOK(product_hook, produce).apply(true); } else