Merge pull request #867 from warmist/eventful-change

Change eventful to have sane(r) callback for produce
develop
expwnent 2016-03-13 07:34:17 -04:00
commit 91235ff806
3 changed files with 11 additions and 13 deletions

@ -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

@ -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<df::item*> *, std::vector<df::reaction_reagent*> *, std::vector<df::item*> *, bool *);
DEFINE_LUA_EVENT_NH_7(onReactionCompleting, df::reaction*, df::reaction_product_itemst*, df::unit *, std::vector<df::item*> *, std::vector<df::reaction_reagent*> *, std::vector<df::item*> *, bool *);
DEFINE_LUA_EVENT_NH_6(onReactionComplete, df::reaction*, df::reaction_product_itemst*, df::unit *, std::vector<df::item*> *, std::vector<df::reaction_reagent*> *, std::vector<df::item*> *);
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);
}
};

@ -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