@@ -343,17 +343,18 @@ <h1 class="title">DFHack Lua API</h1>
343343< li > < a class ="reference internal " href ="#items-module " id ="id17 "> Items module</ a > </ li >
344344< li > < a class ="reference internal " href ="#maps-module " id ="id18 "> Maps module</ a > </ li >
345345< li > < a class ="reference internal " href ="#burrows-module " id ="id19 "> Burrows module</ a > </ li >
346+ < li > < a class ="reference internal " href ="#buildings-module " id ="id20 "> Buildings module</ a > </ li >
346347</ ul >
347348</ li >
348- < li > < a class ="reference internal " href ="#core-interpreter-context " id ="id20 "> Core interpreter context</ a > < ul >
349- < li > < a class ="reference internal " href ="#event-type " id ="id21 "> Event type</ a > </ li >
349+ < li > < a class ="reference internal " href ="#core-interpreter-context " id ="id21 "> Core interpreter context</ a > < ul >
350+ < li > < a class ="reference internal " href ="#event-type " id ="id22 "> Event type</ a > </ li >
350351</ ul >
351352</ li >
352353</ ul >
353354</ li >
354- < li > < a class ="reference internal " href ="#plugins " id ="id22 "> Plugins</ a > < ul >
355- < li > < a class ="reference internal " href ="#burrows " id ="id23 "> burrows</ a > </ li >
356- < li > < a class ="reference internal " href ="#sort " id ="id24 "> sort</ a > </ li >
355+ < li > < a class ="reference internal " href ="#plugins " id ="id23 "> Plugins</ a > < ul >
356+ < li > < a class ="reference internal " href ="#burrows " id ="id24 "> burrows</ a > </ li >
357+ < li > < a class ="reference internal " href ="#sort " id ="id25 "> sort</ a > </ li >
357358</ ul >
358359</ li >
359360</ ul >
@@ -1061,9 +1062,65 @@ <h3><a class="toc-backref" href="#id19">Burrows module</a></h3>
10611062</ li >
10621063</ ul >
10631064</ div >
1065+ < div class ="section " id ="buildings-module ">
1066+ < h3 > < a class ="toc-backref " href ="#id20 "> Buildings module</ a > </ h3 >
1067+ < ul >
1068+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.getSize(building)</ tt > </ p >
1069+ < p > Returns < em > width, height, centerx, centery</ em > .</ p >
1070+ </ li >
1071+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.getCorrectSize(width, height, type, subtype, custom, direction)</ tt > </ p >
1072+ < p > Computes correct dimensions for the specified building type and orientation,
1073+ using width and height for flexible dimensions.
1074+ Returns < em > is_flexible, width, height, center_x, center_y</ em > .</ p >
1075+ </ li >
1076+ < li > < p class ="first "> < tt class ="docutils literal "> < span class ="pre "> dfhack.buildings.checkFreeTiles(pos,size[,extents,change_extents,allow_occupied])</ span > </ tt > </ p >
1077+ < p > Checks if the rectangle defined by < tt class ="docutils literal "> pos</ tt > and < tt class ="docutils literal "> size</ tt > , and possibly extents,
1078+ can be used for placing a building. If < tt class ="docutils literal "> change_extents</ tt > is true, bad tiles
1079+ are removed from extents. If < tt class ="docutils literal "> allow_occupied</ tt > , the occupancy test is skipped.</ p >
1080+ </ li >
1081+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.countExtentTiles(extents,defval)</ tt > </ p >
1082+ < p > Returns the number of tiles included by extents, or defval.</ p >
1083+ </ li >
1084+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.hasSupport(pos,size)</ tt > </ p >
1085+ < p > Checks if a bridge constructed at specified position would have
1086+ support from terrain, and thus won't collapse if retracted.</ p >
1087+ </ li >
1088+ </ ul >
1089+ < p > Low-level building creation functions;</ p >
1090+ < ul >
1091+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.allocInstance(pos, type, subtype, custom)</ tt > </ p >
1092+ < p > Creates a new building instance of given type, subtype and custom type,
1093+ at specified position. Returns the object, or < em > nil</ em > in case of an error.</ p >
1094+ </ li >
1095+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.setSize(building, width, height, direction)</ tt > </ p >
1096+ < p > Configures an object returned by < tt class ="docutils literal "> allocInstance</ tt > , using specified
1097+ parameters wherever appropriate. If the building has fixed size along
1098+ any dimension, the corresponding input parameter will be ignored.
1099+ Returns < em > nil</ em > if the building cannot be placed, or < em > true, width,
1100+ height, rect_area, true_area</ em > . Returned width and height are the
1101+ final values used by the building; true_area is less than rect_area
1102+ if any tiles were removed from designation.</ p >
1103+ </ li >
1104+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.constructWithItems(building, items)</ tt > </ p >
1105+ < p > Links a fully configured object created by < tt class ="docutils literal "> allocInstance</ tt > into the
1106+ world for construction, using a list of specific items as material.
1107+ Returns < em > true</ em > , or < em > false</ em > if impossible.</ p >
1108+ </ li >
1109+ < li > < p class ="first "> < tt class ="docutils literal "> dfhack.buildings.constructWithFilters(building, job_items)</ tt > </ p >
1110+ < p > Links a fully configured object created by < tt class ="docutils literal "> allocInstance</ tt > into the
1111+ world for construction, using a list of job_item filters as inputs.
1112+ Returns < em > true</ em > , or < em > false</ em > if impossible. Filter objects are claimed
1113+ and possibly destroyed in any case.
1114+ Use a negative < tt class ="docutils literal "> quantity</ tt > field value to auto-compute the amount
1115+ from the size of the building.</ p >
1116+ </ li >
1117+ </ ul >
1118+ < p > More high-level functions are implemented in lua and can be loaded by
1119+ < tt class ="docutils literal "> < span class ="pre "> require('dfhack.buildings')</ span > </ tt > . See < tt class ="docutils literal "> hack/lua/dfhack/buildings.lua</ tt > .</ p >
1120+ </ div >
10641121</ div >
10651122< div class ="section " id ="core-interpreter-context ">
1066- < h2 > < a class ="toc-backref " href ="#id20 "> Core interpreter context</ a > </ h2 >
1123+ < h2 > < a class ="toc-backref " href ="#id21 "> Core interpreter context</ a > </ h2 >
10671124< p > While plugins can create any number of interpreter instances,
10681125there is one special context managed by dfhack core. It is the
10691126only context that can receive events from DF and plugins.</ p >
@@ -1077,7 +1134,7 @@ <h2><a class="toc-backref" href="#id20">Core interpreter context</a></h2>
10771134</ li >
10781135</ ul >
10791136< div class ="section " id ="event-type ">
1080- < h3 > < a class ="toc-backref " href ="#id21 "> Event type</ a > </ h3 >
1137+ < h3 > < a class ="toc-backref " href ="#id22 "> Event type</ a > </ h3 >
10811138< p > An event is just a lua table with a predefined metatable that
10821139contains a __call metamethod. When it is invoked, it loops
10831140through the table with next and calls all contained values.
@@ -1103,14 +1160,14 @@ <h3><a class="toc-backref" href="#id21">Event type</a></h3>
11031160</ div >
11041161</ div >
11051162< div class ="section " id ="plugins ">
1106- < h1 > < a class ="toc-backref " href ="#id22 "> Plugins</ a > </ h1 >
1163+ < h1 > < a class ="toc-backref " href ="#id23 "> Plugins</ a > </ h1 >
11071164< p > DFHack plugins may export native functions and events
11081165to lua contexts. They are automatically imported by
11091166< tt class ="docutils literal "> < span class ="pre "> mkmodule('plugins.<name>')</ span > </ tt > ; this means that a lua
11101167module file is still necessary for < tt class ="docutils literal "> require</ tt > to read.</ p >
11111168< p > The following plugins have lua support.</ p >
11121169< div class ="section " id ="burrows ">
1113- < h2 > < a class ="toc-backref " href ="#id23 "> burrows</ a > </ h2 >
1170+ < h2 > < a class ="toc-backref " href ="#id24 "> burrows</ a > </ h2 >
11141171< p > Implements extended burrow manipulations.</ p >
11151172< p > Events:</ p >
11161173< ul >
@@ -1148,7 +1205,7 @@ <h2><a class="toc-backref" href="#id23">burrows</a></h2>
11481205< p > The lua module file also re-exports functions from < tt class ="docutils literal "> dfhack.burrows</ tt > .</ p >
11491206</ div >
11501207< div class ="section " id ="sort ">
1151- < h2 > < a class ="toc-backref " href ="#id24 "> sort</ a > </ h2 >
1208+ < h2 > < a class ="toc-backref " href ="#id25 "> sort</ a > </ h2 >
11521209< p > Does not export any native functions as of now. Instead, it
11531210calls lua code to perform the actual ordering of list items.</ p >
11541211</ div >
0 commit comments