Any files with the .lua extension placed into hack/scripts/*
are automatically used by the DFHack core as commands. The
matching command name consists of the name of the file sans
@@ -3312,7 +3368,7 @@ The name argument should be the name stem, as
Note that this function lets errors propagate to the caller.
-
+
If a save directory contains a file called raw/init.lua, it is
automatically loaded and executed every time the save is loaded.
The same applies to any files called raw/init.d/*.lua. Every
diff --git a/Lua API.rst b/Lua API.rst
index 9afbb1e78..013e8f18d 100644
--- a/Lua API.rst
+++ b/Lua API.rst
@@ -3179,6 +3179,10 @@ Functions
Enable event checking for EventManager events. For event types use ``eventType`` table. Note that different types of events require different frequencies to be effective. The frequency is how many ticks EventManager will wait before checking if that type of event has happened. If multiple scripts or plugins use the same event type, the smallest frequency is the one that is used, so you might get events triggered more often than the frequency you use here.
+5. ``registerSidebar(shop_name,callback)``
+
+ Enable callback when sidebar for ``shop_name`` is drawn. Usefull for custom workshop views e.g. using gui.dwarfmode lib.
+
Examples
--------
Spawn dragon breath on each item attempt to contaminate wound::
@@ -3192,13 +3196,13 @@ Reaction complete example::
b=require "plugins.eventful"
- b.onReactionComplete.one=function(reaction,unit,in_items,in_reag,out_items,call_native)
+ b.registerReaction("LUA_HOOK_LAY_BOMB",function(reaction,unit,in_items,in_reag,out_items,call_native)
local pos=copyall(unit.pos)
-- spawn dragonbreath after 100 ticks
dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end)
--do not call real item creation code
call_native.value=false
- end
+ end)
Grenade example::
@@ -3212,6 +3216,48 @@ Integrated tannery::
b=require "plugins.eventful"
b.addReactionToShop("TAN_A_HIDE","LEATHERWORKS")
+
+Building-hacks
+==============
+
+This plugin overwrites some methods in workshop df class so that mechanical workshops are possible. Although
+plugin export a function it's recommended to use lua decorated function.
+
+Functions
+---------
+
+``registerBuilding(table)`` where table must contain name, as a workshop raw name, the rest are optional:
+ 1. name -- custom workshop id e.g. ``SOAPMAKER``
+ 2. fix_impassible -- if true make impassible tiles impassible to liquids too
+ 3. consume -- how much machine power is needed to work. Disables reactions if not supplied enough
+ 4. produce -- how much machine power is produced. Use discouraged as there is no way to change this at runtime
+ 5. gears -- a table or ``{x=?,y=?}`` of connection points for machines
+ 6. action -- a table of number (how much ticks to skip) and a function which gets called on shop update
+ 7. animate -- a table of frames which can be a table of:
+
+ a. tables of 4 numbers ``{tile,fore,back,bright}`` OR
+ b. empty table (tile not modified) OR
+ c. ``{x= y= + 4 numbers like in first case}``, this generates full frame useful for animations that change little (1-2 tiles)
+
+Animate table also might contain:
+ 1. frameLenght -- how many ticks does one frame take OR
+ 2. isMechanical -- a bool that says to try to match to mechanical system (i.e. how gears are turning)
+
+Examples
+--------
+
+Simple mechanical workshop::
+
+ require('plugins.building-hacks').registerBuilding{name="BONE_GRINDER",
+ consume=15,
+ gears={x=0,y=0}, --connection point
+ animate={
+ isMechanical=true, --animate the same connection point as vanilla gear
+ frames={
+ {{x=0,y=0,42,7,0,0}}, --first frame, 1 changed tile
+ {{x=0,y=0,15,7,0,0}} -- second frame, same
+ }
+ }
=======
Scripts
diff --git a/NEWS b/NEWS
index 180877984..db889b4ae 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ DFHack future
- Lua API for listing files in directory. Needed for mod-manager.
- Lua API for creating unit combat reports and writing to gamelog.
- support for multiple raw/init.d/*.lua init scripts in one save.
+ - eventful now has a more friendly way of making custom sidebars
+ - new plugin: building-hacks. Allows to add custom functionality and/or animations to buildings.
New scripts:
- gui/mod-manager: allows installing/uninstalling mods into df from df/mods directory.
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 6e1425b9c..e13284274 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -164,6 +164,7 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(3dveins 3dveins.cpp)
DFHACK_PLUGIN(strangemood strangemood.cpp)
DFHACK_PLUGIN(command-prompt command-prompt.cpp)
+ DFHACK_PLUGIN(building-hacks building-hacks.cpp LINK_LIBRARIES lua)
endif()
# this is the skeleton plugin. If you want to make your own, make a copy and then change it
diff --git a/plugins/building-hacks.cpp b/plugins/building-hacks.cpp
new file mode 100644
index 000000000..b9c9ea3c9
--- /dev/null
+++ b/plugins/building-hacks.cpp
@@ -0,0 +1,389 @@
+//most of the code is shamelessly stolen from steam-engine.cpp
+#include "Core.h"
+#include "Error.h"
+#include
+#include
+#include
+
+#include "LuaTools.h"
+#include
+#include "MiscUtils.h"
+
+#include "df/building_doorst.h"
+#include "df/building_workshopst.h"
+#include "df/machine.h"
+#include "df/machine_tile_set.h"
+#include "df/power_info.h"
+#include "df/world.h"
+#include "df/buildings_other_id.h"
+#include "df/coord.h"
+#include "df/tile_building_occ.h"
+#include "df/building_drawbuffer.h"
+
+#include