|
|
@ -10,6 +10,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "df/block_burrow.h"
|
|
|
|
#include "df/block_burrow.h"
|
|
|
|
#include "df/burrow.h"
|
|
|
|
#include "df/burrow.h"
|
|
|
|
|
|
|
|
#include "df/map_block.h"
|
|
|
|
#include "df/tile_designation.h"
|
|
|
|
#include "df/tile_designation.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/world.h"
|
|
|
@ -196,10 +197,9 @@ static void get_bool_field(lua_State *L, int idx, const char *name, bool *dest)
|
|
|
|
lua_pop(L, 1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void get_opts(lua_State *L, int idx, bool &dry_run, bool &zlevel) {
|
|
|
|
static void get_opts(lua_State *L, int idx, bool &zlevel) {
|
|
|
|
if (lua_gettop(L) < idx)
|
|
|
|
if (lua_gettop(L) < idx)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
get_bool_field(L, idx, "dry_run", &dry_run);
|
|
|
|
|
|
|
|
get_bool_field(L, idx, "zlevel", &zlevel);
|
|
|
|
get_bool_field(L, idx, "zlevel", &zlevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -234,29 +234,7 @@ static df::burrow* get_burrow(lua_State *L, int idx) {
|
|
|
|
return burrow;
|
|
|
|
return burrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int burrow_tiles_clear(lua_State *L) {
|
|
|
|
static void copyTiles(df::burrow *target, df::burrow *source, bool enable) {
|
|
|
|
color_ostream *out = Lua::GetOutput(L);
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_clear\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 void copyTiles(df::burrow *target, df::burrow *source, bool enable)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
CHECK_NULL_POINTER(source);
|
|
|
|
CHECK_NULL_POINTER(source);
|
|
|
|
|
|
|
|
|
|
|
@ -291,12 +269,124 @@ static void copyTiles(df::burrow *target, df::burrow *source, bool enable)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void setTilesByDesignation(df::burrow *target, df::tile_designation d_mask,
|
|
|
|
|
|
|
|
df::tile_designation d_value, bool enable) {
|
|
|
|
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto &blocks = world->map.map_blocks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto block : blocks) {
|
|
|
|
|
|
|
|
df::block_burrow *mask = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int x = 0; x < 16; x++) {
|
|
|
|
|
|
|
|
for (int y = 0; y < 16; y++) {
|
|
|
|
|
|
|
|
if ((block->designation[x][y].whole & d_mask.whole) != d_value.whole)
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
|
|
|
|
mask = Burrows::getBlockMask(target, block, enable);
|
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
|
|
|
|
goto next_block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mask->setassignment(x, y, enable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mask && !enable && !mask->has_assignments())
|
|
|
|
|
|
|
|
Burrows::deleteBlockMask(target, block, mask);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_block:;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool setTilesByKeyword(df::burrow *target, std::string name, bool enable) {
|
|
|
|
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df::tile_designation mask;
|
|
|
|
|
|
|
|
df::tile_designation value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name == "ABOVE_GROUND")
|
|
|
|
|
|
|
|
mask.bits.subterranean = true;
|
|
|
|
|
|
|
|
else if (name == "SUBTERRANEAN")
|
|
|
|
|
|
|
|
mask.bits.subterranean = value.bits.subterranean = true;
|
|
|
|
|
|
|
|
else if (name == "LIGHT")
|
|
|
|
|
|
|
|
mask.bits.light = value.bits.light = true;
|
|
|
|
|
|
|
|
else if (name == "DARK")
|
|
|
|
|
|
|
|
mask.bits.light = true;
|
|
|
|
|
|
|
|
else if (name == "OUTSIDE")
|
|
|
|
|
|
|
|
mask.bits.outside = value.bits.outside = true;
|
|
|
|
|
|
|
|
else if (name == "INSIDE")
|
|
|
|
|
|
|
|
mask.bits.outside = true;
|
|
|
|
|
|
|
|
else if (name == "HIDDEN")
|
|
|
|
|
|
|
|
mask.bits.hidden = value.bits.hidden = true;
|
|
|
|
|
|
|
|
else if (name == "REVEALED")
|
|
|
|
|
|
|
|
mask.bits.hidden = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTilesByDesignation(target, mask, value, enable);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void copyUnits(df::burrow *target, df::burrow *source, bool enable) {
|
|
|
|
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
|
|
|
|
CHECK_NULL_POINTER(source);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (source == target) {
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
|
|
|
|
Burrows::clearUnits(target);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < source->units.size(); i++) {
|
|
|
|
|
|
|
|
if (auto unit = df::unit::find(source->units[i]))
|
|
|
|
|
|
|
|
Burrows::setAssignedUnit(target, unit, enable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lua_pushnil(L); // first key
|
|
|
|
|
|
|
|
while (lua_next(L, 1)) {
|
|
|
|
|
|
|
|
df::burrow * burrow = get_burrow(L, -1);
|
|
|
|
|
|
|
|
if (burrow)
|
|
|
|
|
|
|
|
Burrows::clearTiles(burrow);
|
|
|
|
|
|
|
|
lua_pop(L, 1); // remove value, leave key
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void tiles_set_add_remove(lua_State *L, bool do_set, bool enable) {
|
|
|
|
|
|
|
|
df::burrow *target = get_burrow(L, 1);
|
|
|
|
|
|
|
|
if (!target) {
|
|
|
|
|
|
|
|
luaL_argerror(L, 1, "invalid burrow specifier or burrow not found");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (do_set)
|
|
|
|
|
|
|
|
Burrows::clearTiles(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lua_pushnil(L); // first key
|
|
|
|
|
|
|
|
while (lua_next(L, 2)) {
|
|
|
|
|
|
|
|
if (!lua_isstring(L, -1) || !setTilesByKeyword(target, luaL_checkstring(L, -1), enable)) {
|
|
|
|
|
|
|
|
if (auto burrow = get_burrow(L, -1))
|
|
|
|
|
|
|
|
copyTiles(target, burrow, enable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pop(L, 1); // remove value, leave key
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int burrow_tiles_set(lua_State *L) {
|
|
|
|
static int burrow_tiles_set(lua_State *L) {
|
|
|
|
color_ostream *out = Lua::GetOutput(L);
|
|
|
|
color_ostream *out = Lua::GetOutput(L);
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_set\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_set\n");
|
|
|
|
// TODO
|
|
|
|
tiles_set_add_remove(L, true, true);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -305,7 +395,7 @@ static int burrow_tiles_add(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_add\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_add\n");
|
|
|
|
// TODO
|
|
|
|
tiles_set_add_remove(L, false, true);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -314,46 +404,31 @@ static int burrow_tiles_remove(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_remove\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_remove\n");
|
|
|
|
// TODO
|
|
|
|
tiles_set_add_remove(L, false, false);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int box_fill(lua_State *L, bool enable) {
|
|
|
|
static void box_fill(lua_State *L, bool enable) {
|
|
|
|
df::coord pos_start, pos_end;
|
|
|
|
|
|
|
|
bool dry_run = false, zlevel = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df::burrow *burrow = get_burrow(L, 1);
|
|
|
|
df::burrow *burrow = get_burrow(L, 1);
|
|
|
|
if (!burrow) {
|
|
|
|
if (!burrow) {
|
|
|
|
luaL_argerror(L, 1, "invalid burrow specifier or burrow not found");
|
|
|
|
luaL_argerror(L, 1, "invalid burrow specifier or burrow not found");
|
|
|
|
return 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df::coord pos_start, pos_end;
|
|
|
|
if (!get_bounds(L, 2, pos_start, pos_end)) {
|
|
|
|
if (!get_bounds(L, 2, pos_start, pos_end)) {
|
|
|
|
luaL_argerror(L, 2, "invalid box bounds");
|
|
|
|
luaL_argerror(L, 2, "invalid box bounds");
|
|
|
|
return 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_opts(L, 3, dry_run, zlevel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (zlevel) {
|
|
|
|
|
|
|
|
pos_start.z = *window_z;
|
|
|
|
|
|
|
|
pos_end.z = *window_z;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t count = 0;
|
|
|
|
|
|
|
|
for (int32_t z = pos_start.z; z <= pos_end.z; ++z) {
|
|
|
|
for (int32_t z = pos_start.z; z <= pos_end.z; ++z) {
|
|
|
|
for (int32_t y = pos_start.y; y <= pos_end.y; ++y) {
|
|
|
|
for (int32_t y = pos_start.y; y <= pos_end.y; ++y) {
|
|
|
|
for (int32_t x = pos_start.x; x <= pos_end.x; ++x) {
|
|
|
|
for (int32_t x = pos_start.x; x <= pos_end.x; ++x) {
|
|
|
|
df::coord pos(x, y, z);
|
|
|
|
df::coord pos(x, y, z);
|
|
|
|
if (enable != Burrows::isAssignedTile(burrow, pos))
|
|
|
|
Burrows::setAssignedTile(burrow, pos, enable);
|
|
|
|
++count;
|
|
|
|
|
|
|
|
if (!dry_run)
|
|
|
|
|
|
|
|
Burrows::setAssignedTile(burrow, pos, enable);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Lua::Push(L, count);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int burrow_tiles_box_add(lua_State *L) {
|
|
|
|
static int burrow_tiles_box_add(lua_State *L) {
|
|
|
@ -361,7 +436,8 @@ static int burrow_tiles_box_add(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_box_add\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_box_add\n");
|
|
|
|
return box_fill(L, true);
|
|
|
|
box_fill(L, true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int burrow_tiles_box_remove(lua_State *L) {
|
|
|
|
static int burrow_tiles_box_remove(lua_State *L) {
|
|
|
@ -369,32 +445,30 @@ static int burrow_tiles_box_remove(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_box_remove\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_box_remove\n");
|
|
|
|
return box_fill(L, false);
|
|
|
|
box_fill(L, false);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int flood_fill(lua_State *L, bool enable) {
|
|
|
|
static void flood_fill(lua_State *L, bool enable) {
|
|
|
|
df::coord start_pos;
|
|
|
|
df::coord start_pos;
|
|
|
|
bool dry_run = false, zlevel = false;
|
|
|
|
bool zlevel = false;
|
|
|
|
|
|
|
|
|
|
|
|
df::burrow *burrow = get_burrow(L, 1);
|
|
|
|
df::burrow *burrow = get_burrow(L, 1);
|
|
|
|
if (!burrow) {
|
|
|
|
if (!burrow) {
|
|
|
|
luaL_argerror(L, 1, "invalid burrow specifier or burrow not found");
|
|
|
|
luaL_argerror(L, 1, "invalid burrow specifier or burrow not found");
|
|
|
|
return 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Lua::CheckDFAssign(L, &start_pos, 2);
|
|
|
|
Lua::CheckDFAssign(L, &start_pos, 2);
|
|
|
|
get_opts(L, 3, dry_run, zlevel);
|
|
|
|
get_opts(L, 3, zlevel);
|
|
|
|
|
|
|
|
|
|
|
|
// record properties to match
|
|
|
|
|
|
|
|
df::tile_designation *start_des = Maps::getTileDesignation(start_pos);
|
|
|
|
df::tile_designation *start_des = Maps::getTileDesignation(start_pos);
|
|
|
|
if (!start_des) {
|
|
|
|
if (!start_des) {
|
|
|
|
luaL_argerror(L, 2, "invalid starting coordinates");
|
|
|
|
luaL_argerror(L, 2, "invalid starting coordinates");
|
|
|
|
return 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint16_t start_walk = Maps::getWalkableGroup(start_pos);
|
|
|
|
uint16_t start_walk = Maps::getWalkableGroup(start_pos);
|
|
|
|
|
|
|
|
|
|
|
|
int32_t count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::stack<df::coord> flood;
|
|
|
|
std::stack<df::coord> flood;
|
|
|
|
flood.emplace(start_pos);
|
|
|
|
flood.emplace(start_pos);
|
|
|
|
|
|
|
|
|
|
|
@ -416,9 +490,7 @@ static int flood_fill(lua_State *L, bool enable) {
|
|
|
|
if (pos != start_pos && enable == Burrows::isAssignedTile(burrow, pos))
|
|
|
|
if (pos != start_pos && enable == Burrows::isAssignedTile(burrow, pos))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
++count;
|
|
|
|
Burrows::setAssignedTile(burrow, pos, enable);
|
|
|
|
if (!dry_run)
|
|
|
|
|
|
|
|
Burrows::setAssignedTile(burrow, pos, enable);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// only go one tile outside of a walkability group
|
|
|
|
// only go one tile outside of a walkability group
|
|
|
|
if (start_walk && start_walk != Maps::getWalkableGroup(pos))
|
|
|
|
if (start_walk && start_walk != Maps::getWalkableGroup(pos))
|
|
|
@ -444,9 +516,6 @@ static int flood_fill(lua_State *L, bool enable) {
|
|
|
|
flood.emplace(pos.x, pos.y, pos.z-1);
|
|
|
|
flood.emplace(pos.x, pos.y, pos.z-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Lua::Push(L, count);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int burrow_tiles_flood_add(lua_State *L) {
|
|
|
|
static int burrow_tiles_flood_add(lua_State *L) {
|
|
|
@ -454,7 +523,8 @@ static int burrow_tiles_flood_add(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_flood_add\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_flood_add\n");
|
|
|
|
return flood_fill(L, true);
|
|
|
|
flood_fill(L, true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int burrow_tiles_flood_remove(lua_State *L) {
|
|
|
|
static int burrow_tiles_flood_remove(lua_State *L) {
|
|
|
@ -462,7 +532,8 @@ static int burrow_tiles_flood_remove(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_flood_remove\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_tiles_flood_remove\n");
|
|
|
|
return flood_fill(L, false);
|
|
|
|
flood_fill(L, false);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int burrow_units_clear(lua_State *L) {
|
|
|
|
static int burrow_units_clear(lua_State *L) {
|
|
|
@ -470,29 +541,37 @@ static int burrow_units_clear(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_clear\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_clear\n");
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void copyUnits(df::burrow *target, df::burrow *source, bool enable)
|
|
|
|
int32_t count = 0;
|
|
|
|
{
|
|
|
|
lua_pushnil(L); // first key
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
while (lua_next(L, 1)) {
|
|
|
|
CHECK_NULL_POINTER(source);
|
|
|
|
df::burrow * burrow = get_burrow(L, -1);
|
|
|
|
|
|
|
|
if (burrow) {
|
|
|
|
|
|
|
|
count += burrow->units.size();
|
|
|
|
|
|
|
|
Burrows::clearUnits(burrow);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pop(L, 1); // remove value, leave key
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (source == target)
|
|
|
|
Lua::Push(L, count);
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
if (!enable)
|
|
|
|
}
|
|
|
|
Burrows::clearUnits(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void units_set_add_remove(lua_State *L, bool do_set, bool enable) {
|
|
|
|
|
|
|
|
df::burrow *target = get_burrow(L, 1);
|
|
|
|
|
|
|
|
if (!target) {
|
|
|
|
|
|
|
|
luaL_argerror(L, 1, "invalid burrow specifier or burrow not found");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < source->units.size(); i++)
|
|
|
|
if (do_set)
|
|
|
|
{
|
|
|
|
Burrows::clearUnits(target);
|
|
|
|
auto unit = df::unit::find(source->units[i]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (unit)
|
|
|
|
lua_pushnil(L); // first key
|
|
|
|
Burrows::setAssignedUnit(target, unit, enable);
|
|
|
|
while (lua_next(L, 2)) {
|
|
|
|
|
|
|
|
if (auto burrow = get_burrow(L, -1))
|
|
|
|
|
|
|
|
copyUnits(target, burrow, enable);
|
|
|
|
|
|
|
|
lua_pop(L, 1); // remove value, leave key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -501,7 +580,7 @@ static int burrow_units_set(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_set\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_set\n");
|
|
|
|
// TODO
|
|
|
|
units_set_add_remove(L, true, true);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -510,7 +589,7 @@ static int burrow_units_add(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_add\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_add\n");
|
|
|
|
// TODO
|
|
|
|
units_set_add_remove(L, false, true);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -519,7 +598,7 @@ static int burrow_units_remove(lua_State *L) {
|
|
|
|
if (!out)
|
|
|
|
if (!out)
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_remove\n");
|
|
|
|
DEBUG(status,*out).print("entering burrow_units_remove\n");
|
|
|
|
// TODO
|
|
|
|
units_set_add_remove(L, false, false);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -540,17 +619,7 @@ DFHACK_PLUGIN_LUA_COMMANDS {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "Export.h"
|
|
|
@ -952,72 +1021,6 @@ static df::burrow *findByName(color_ostream &out, std::string name, bool silent
|
|
|
|
return rv;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void setTilesByDesignation(df::burrow *target, df::tile_designation d_mask,
|
|
|
|
|
|
|
|
df::tile_designation d_value, bool enable)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto &blocks = world->map.map_blocks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < blocks.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto block = blocks[i];
|
|
|
|
|
|
|
|
df::block_burrow *mask = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int x = 0; x < 16; x++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int y = 0; y < 16; y++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((block->designation[x][y].whole & d_mask.whole) != d_value.whole)
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
|
|
|
|
mask = Burrows::getBlockMask(target, block, enable);
|
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
|
|
|
|
goto next_block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mask->setassignment(x, y, enable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mask && !enable && !mask->has_assignments())
|
|
|
|
|
|
|
|
Burrows::deleteBlockMask(target, block, mask);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_block:;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool setTilesByKeyword(df::burrow *target, std::string name, bool enable)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CHECK_NULL_POINTER(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df::tile_designation mask;
|
|
|
|
|
|
|
|
df::tile_designation value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name == "ABOVE_GROUND")
|
|
|
|
|
|
|
|
mask.bits.subterranean = true;
|
|
|
|
|
|
|
|
else if (name == "SUBTERRANEAN")
|
|
|
|
|
|
|
|
mask.bits.subterranean = value.bits.subterranean = true;
|
|
|
|
|
|
|
|
else if (name == "LIGHT")
|
|
|
|
|
|
|
|
mask.bits.light = value.bits.light = true;
|
|
|
|
|
|
|
|
else if (name == "DARK")
|
|
|
|
|
|
|
|
mask.bits.light = true;
|
|
|
|
|
|
|
|
else if (name == "OUTSIDE")
|
|
|
|
|
|
|
|
mask.bits.outside = value.bits.outside = true;
|
|
|
|
|
|
|
|
else if (name == "INSIDE")
|
|
|
|
|
|
|
|
mask.bits.outside = true;
|
|
|
|
|
|
|
|
else if (name == "HIDDEN")
|
|
|
|
|
|
|
|
mask.bits.hidden = value.bits.hidden = true;
|
|
|
|
|
|
|
|
else if (name == "REVEALED")
|
|
|
|
|
|
|
|
mask.bits.hidden = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTilesByDesignation(target, mask, value, enable);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
DFHACK_LUA_FUNCTION(renameBurrow),
|
|
|
|
DFHACK_LUA_FUNCTION(renameBurrow),
|
|
|
|
DFHACK_LUA_FUNCTION(findByName),
|
|
|
|
DFHACK_LUA_FUNCTION(findByName),
|
|
|
@ -1033,121 +1036,4 @@ DFHACK_PLUGIN_LUA_EVENTS {
|
|
|
|
DFHACK_LUA_END
|
|
|
|
DFHACK_LUA_END
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static command_result burrow(color_ostream &out, vector <string> ¶meters)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CoreSuspender suspend;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out.printerr("The plugin cannot be used without map.\n");
|
|
|
|
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string cmd;
|
|
|
|
|
|
|
|
if (!parameters.empty())
|
|
|
|
|
|
|
|
cmd = parameters[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmd == "enable" || cmd == "disable")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (parameters.size() < 2)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool state = (cmd == "enable");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 1; i < parameters.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string &option = parameters[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (option == "auto-grow")
|
|
|
|
|
|
|
|
enable_auto_grow(out, state);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (cmd == "clear-units")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (parameters.size() < 2)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 1; i < parameters.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto target = findByName(out, parameters[i]);
|
|
|
|
|
|
|
|
if (!target)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Burrows::clearUnits(target);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (cmd == "set-units" || cmd == "add-units" || cmd == "remove-units")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (parameters.size() < 3)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto target = findByName(out, parameters[1]);
|
|
|
|
|
|
|
|
if (!target)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmd == "set-units")
|
|
|
|
|
|
|
|
Burrows::clearUnits(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool enable = (cmd != "remove-units");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 2; i < parameters.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto source = findByName(out, parameters[i]);
|
|
|
|
|
|
|
|
if (!source)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
copyUnits(target, source, enable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (cmd == "clear-tiles")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (parameters.size() < 2)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 1; i < parameters.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto target = findByName(out, parameters[i]);
|
|
|
|
|
|
|
|
if (!target)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Burrows::clearTiles(target);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (cmd == "set-tiles" || cmd == "add-tiles" || cmd == "remove-tiles")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (parameters.size() < 3)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto target = findByName(out, parameters[1]);
|
|
|
|
|
|
|
|
if (!target)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmd == "set-tiles")
|
|
|
|
|
|
|
|
Burrows::clearTiles(target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool enable = (cmd != "remove-tiles");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 2; i < parameters.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (setTilesByKeyword(target, parameters[i], enable))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto source = findByName(out, parameters[i]);
|
|
|
|
|
|
|
|
if (!source)
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
copyTiles(target, source, enable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!parameters.empty() && cmd != "?")
|
|
|
|
|
|
|
|
out.printerr("Invalid command: %s\n", cmd.c_str());
|
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|