From 5895621eec26032da42ff2adbdda6d2e0b85f3f6 Mon Sep 17 00:00:00 2001 From: Warmist Date: Mon, 21 Dec 2015 19:53:02 +0200 Subject: [PATCH 1/2] Change eventful to have sane(r) callback for produce --- plugins/eventful.cpp | 8 +++++--- scripts/modtools/reaction-product-trigger.lua | 12 ++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/plugins/eventful.cpp b/plugins/eventful.cpp index e12d2eca2..57bd0ed7f 100644 --- a/plugins/eventful.cpp +++ b/plugins/eventful.cpp @@ -96,7 +96,8 @@ static bool is_lua_hook(const std::string &name) 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_7(onReactionCompleting, df::reaction*, df::reaction_product_itemst*, df::unit *, std::vector *, std::vector *, std::vector *, bool *); +DEFINE_LUA_EVENT_NH_6(onReactionComplete, df::reaction*, df::reaction_product_itemst*, df::unit *, std::vector *, std::vector *, std::vector *); DEFINE_LUA_EVENT_NH_5(onItemContaminateWound, df::item_actual*, df::unit*, df::unit_wound*, uint8_t, int16_t); //projectiles DEFINE_LUA_EVENT_NH_2(onProjItemCheckImpact, df::proj_itemst*, bool); @@ -121,6 +122,7 @@ DEFINE_LUA_EVENT_NH_6(onInteraction, std::string, std::string, int32_t, int32_t, DFHACK_PLUGIN_LUA_EVENTS { DFHACK_LUA_EVENT(onWorkshopFillSidebarMenu), DFHACK_LUA_EVENT(postWorkshopFillSidebarMenu), + DFHACK_LUA_EVENT(onReactionCompleting), DFHACK_LUA_EVENT(onReactionComplete), DFHACK_LUA_EVENT(onItemContaminateWound), DFHACK_LUA_EVENT(onProjItemCheckImpact), @@ -307,7 +309,7 @@ struct product_hook : item_product { df::reaction* this_reaction=product->react; CoreSuspendClaimer suspend; bool call_native=true; - onReactionComplete(out,this_reaction,(df::reaction_product_itemst*)this,unit,in_items,in_reag,out_items,&call_native); + onReactionCompleting(out,this_reaction,(df::reaction_product_itemst*)this,unit,in_items,in_reag,out_items,&call_native); if(!call_native) return; @@ -316,7 +318,7 @@ struct product_hook : item_product { if ( out_items->size() == out_item_count ) return; //if it produced something, call the scripts - onReactionComplete(out,this_reaction,(df::reaction_product_itemst*)this,unit,in_items,in_reag,out_items,NULL); + onReactionComplete(out,this_reaction,(df::reaction_product_itemst*)this,unit,in_items,in_reag,out_items); } }; diff --git a/scripts/modtools/reaction-product-trigger.lua b/scripts/modtools/reaction-product-trigger.lua index fb6ba3029..7f423e020 100644 --- a/scripts/modtools/reaction-product-trigger.lua +++ b/scripts/modtools/reaction-product-trigger.lua @@ -72,17 +72,9 @@ local function afterProduce(reaction,reaction_product,unit,input_items,input_rea end end -eventful.onReactionComplete.reactionProductTrigger = function(reaction,reaction_product,unit,input_items,input_reagents,output_items,call_native) +eventful.onReactionComplete.reactionProductTrigger = function(reaction,reaction_product,unit,input_items,input_reagents,output_items) reactionInputItems = input_items - --print(reaction.code) - --print(#output_items) - --print('call_native exists? ' .. tostring(not not call_native)) - --print('\n') - if call_native then - --beforeProduce(reaction,unit,input_items,input_reagents,output_items,call_native) - else - afterProduce(reaction,reaction_product,unit,input_items,input_reagents,output_items) - end + afterProduce(reaction,reaction_product,unit,input_items,input_reagents,output_items) reactionInputItems = nil end From 45643ef2e3631dccaa9136652c1319e2eb3c0bfc Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 13 Mar 2016 13:25:10 +0200 Subject: [PATCH 2/2] Update NEWS.rst --- NEWS.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 54b986e73..545bd88ef 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -43,6 +43,10 @@ Internals - Prevented plugins with active viewscreens from being unloaded and causing a crash +Lua +--- +- Changed how `eventful` triggers reaction complete. Now it has ``onReactionComplete`` and ``onReactionCompleting``. Second one can be canceled + New Plugins ----------- - `autogems`: Creates a new Workshop Order setting, automatically cutting rough gems