diff --git a/docs/plugins/burrow.rst b/docs/plugins/burrow.rst index 9fbd23dc4..24f1b72d4 100644 --- a/docs/plugins/burrow.rst +++ b/docs/plugins/burrow.rst @@ -110,3 +110,6 @@ select the entire volume instead of just the selected area on the z-level that you are currently looking at. In addition, double-clicking will start a flood fill from the target tile. + +The box and flood fill actions respect the UI setting for whether the burrow is +being added to or erased. diff --git a/plugins/burrow.cpp b/plugins/burrow.cpp index a4f96be46..59da9b929 100644 --- a/plugins/burrow.cpp +++ b/plugins/burrow.cpp @@ -221,13 +221,36 @@ static bool get_bounds(lua_State *L, int idx, df::coord &pos1, df::coord &pos2) get_int_field(L, idx, "z2", &pos2.z); } +static df::burrow* get_burrow(lua_State *L, int idx) { + df::burrow *burrow = NULL; + if (lua_isuserdata(L, idx)) + burrow = Lua::GetDFObject(L, idx); + else if (lua_isstring(L, idx)) + burrow = Burrows::findByName(luaL_checkstring(L, idx)); + else if (lua_isinteger(L, idx)) + burrow = df::burrow::find(luaL_checkinteger(L, idx)); + return burrow; +} + static int burrow_tiles_clear(lua_State *L) { color_ostream *out = Lua::GetOutput(L); if (!out) out = &Core::getInstance().getConsole(); DEBUG(status,*out).print("entering burrow_tiles_clear\n"); - // TODO - return 0; + + int32_t count = 0; + lua_pushnil(L); // first key + while (lua_next(L, 1)) { + df::burrow * burrow = get_burrow(L, -1); + if (burrow) { + count += burrow->block_x.size(); + Burrows::clearTiles(burrow); + } + lua_pop(L, 1); // remove value, leave key + } + + Lua::Push(L, count); + return 1; } static int burrow_tiles_set(lua_State *L) { @@ -257,17 +280,6 @@ static int burrow_tiles_remove(lua_State *L) { return 0; } -static df::burrow* get_burrow(lua_State *L, int idx) { - df::burrow *burrow = NULL; - if (lua_isuserdata(L, idx)) - burrow = Lua::GetDFObject(L, idx); - else if (lua_isstring(L, idx)) - burrow = Burrows::findByName(luaL_checkstring(L, idx)); - else if (lua_isinteger(L, idx)) - burrow = df::burrow::find(luaL_checkinteger(L, idx)); - return burrow; -} - static int box_fill(lua_State *L, bool enable) { df::coord pos_start, pos_end; bool dry_run = false, zlevel = false; diff --git a/plugins/lua/burrow.lua b/plugins/lua/burrow.lua index 2668cc5e7..9b7d8c63d 100644 --- a/plugins/lua/burrow.lua +++ b/plugins/lua/burrow.lua @@ -2,20 +2,11 @@ local _ENV = mkmodule('plugins.burrow') --[[ - Native events: + Provided events: * onBurrowRename(burrow) * onDigComplete(job_type,pos,old_tiletype,new_tiletype) - Native functions: - - * findByName(name) -> burrow - * copyUnits(dest,src,enable) - * copyTiles(dest,src,enable) - * setTilesByKeyword(dest,kwd,enable) -> success - - 'enable' selects between add and remove modes - --]] local overlay = require('plugins.overlay')