Skip to content

Commit

Permalink
implement clear tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Oct 30, 2023
1 parent c98da94 commit 8ca0398
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
3 changes: 3 additions & 0 deletions docs/plugins/burrow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
38 changes: 25 additions & 13 deletions plugins/burrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<df::burrow>(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) {
Expand Down Expand Up @@ -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<df::burrow>(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;
Expand Down
11 changes: 1 addition & 10 deletions plugins/lua/burrow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 8ca0398

Please sign in to comment.