Skip to content

Commit 48c69be

Browse files
committed
Add event to vmethod interpose setTriggerState for lever/trap plate linking support
1 parent 1983589 commit 48c69be

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

plugins/building-hacks.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ struct workshop_hack_data
6363
typedef std::map<int32_t,workshop_hack_data> workshops_data_t;
6464
workshops_data_t hacked_workshops;
6565

66-
static void handle_update_action(color_ostream &out,df::building_workshopst*){};
66+
DEFINE_LUA_EVENT_NH_1(onUpdateAction,df::building_workshopst*);
67+
DEFINE_LUA_EVENT_NH_2(onSetTriggerState,df::building_workshopst*,int32_t);
6768

68-
DEFINE_LUA_EVENT_1(onUpdateAction,handle_update_action,df::building_workshopst*);
69-
DFHACK_PLUGIN_LUA_EVENTS {
69+
DFHACK_PLUGIN_LUA_EVENTS{
7070
DFHACK_LUA_EVENT(onUpdateAction),
71+
DFHACK_LUA_EVENT(onSetTriggerState),
7172
DFHACK_LUA_END
7273
};
7374

@@ -267,6 +268,13 @@ struct work_hook : df::building_workshopst{
267268
}
268269
INTERPOSE_NEXT(updateAction)();
269270
}
271+
DEFINE_VMETHOD_INTERPOSE(void, setTriggerState,(int32_t state))
272+
{
273+
CoreSuspendClaimer suspend;
274+
color_ostream_proxy out(Core::getInstance().getConsole());
275+
onSetTriggerState(out, this,state);
276+
INTERPOSE_NEXT(setTriggerState)(state); //pretty sure default workshop has nothing related to this, but to be future proof lets do it like this
277+
}
270278
DEFINE_VMETHOD_INTERPOSE(void, drawBuilding, (uint32_t curtick,df::building_drawbuffer *db, int16_t z_offset))
271279
{
272280
INTERPOSE_NEXT(drawBuilding)(curtick,db, z_offset);
@@ -329,6 +337,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(work_hook, canConnectToMachine);
329337
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, isUnpowered);
330338
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, canBeRoomSubset);
331339
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, updateAction);
340+
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, setTriggerState);
332341
IMPLEMENT_VMETHOD_INTERPOSE(work_hook, drawBuilding);
333342

334343

@@ -501,6 +510,7 @@ static void enable_hooks(bool enable)
501510
INTERPOSE_HOOK(work_hook,canBeRoomSubset).apply(enable);
502511
//update n render
503512
INTERPOSE_HOOK(work_hook,updateAction).apply(enable);
513+
INTERPOSE_HOOK(work_hook,setTriggerState).apply(enable);
504514
INTERPOSE_HOOK(work_hook,drawBuilding).apply(enable);
505515
}
506516
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)

plugins/lua/building-hacks.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ local function generateFrame(tiles,w,h)
7272
end
7373
return ret
7474
end
75+
--convert frames to flat arrays if needed
7576
local function processFrames(shop_def,frames)
7677
local w,h=shop_def.dim_x,shop_def.dim_y
7778
for frame_id,frame in ipairs(frames) do
@@ -81,6 +82,7 @@ local function processFrames(shop_def,frames)
8182
end
8283
return frames
8384
end
85+
--locate gears on the workshop from the raws definition
8486
local function findGears( shop_def ) --finds positions of all gears and inverted gears
8587
local w,h=shop_def.dim_x,shop_def.dim_y
8688
local stage=shop_def.build_stages
@@ -97,6 +99,7 @@ local function findGears( shop_def ) --finds positions of all gears and inverted
9799
end
98100
return ret
99101
end
102+
--helper for reading tile color info from raws
100103
local function lookup_color( shop_def,x,y,stage )
101104
return shop_def.tile_color[0][stage][x][y],shop_def.tile_color[1][stage][x][y],shop_def.tile_color[2][stage][x][y]
102105
end

0 commit comments

Comments
 (0)