From ae872e812fe6e50407eae4a6ce5368f9f373c76d Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 15 Aug 2020 17:24:12 -0700 Subject: [PATCH 1/3] properly detect valid tiles for civzones --- library/include/modules/Buildings.h | 4 +++- library/modules/Buildings.cpp | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/library/include/modules/Buildings.h b/library/include/modules/Buildings.h index 50cbc898f..256e3b7e6 100644 --- a/library/include/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -141,7 +141,9 @@ DFHACK_EXPORT bool getCorrectSize(df::coord2d &size, df::coord2d ¢er, */ DFHACK_EXPORT bool checkFreeTiles(df::coord pos, df::coord2d size, df::building_extents *ext = NULL, - bool create_ext = false, bool allow_occupied = false); + bool create_ext = false, + bool allow_occupied = false, + bool is_civzone = false); /** * Returns the number of tiles included by the extent, or defval. diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 5219395c1..3d708dc92 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -574,7 +574,9 @@ bool Buildings::getCorrectSize(df::coord2d &size, df::coord2d ¢er, bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size, df::building_extents *ext, - bool create_ext, bool allow_occupied) + bool create_ext, + bool allow_occupied, + bool is_civzone) { bool found_any = false; @@ -609,7 +611,7 @@ bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size, else { auto tile = block->tiletype[btile.x][btile.y]; - if (!HighPassable(tile)) + if (!is_civzone && !HighPassable(tile)) allowed = false; } @@ -659,7 +661,9 @@ static bool checkBuildingTiles(df::building *bld, bool can_change) return Buildings::checkFreeTiles(psize.first, psize.second, &bld->room, can_change && bld->isExtentShaped(), - !bld->isSettingOccupancy()); + !bld->isSettingOccupancy(), + bld->getType() == + df::building_type::Civzone); } int Buildings::countExtentTiles(df::building_extents *ext, int defval) From dd3ff7252d39e1bf3376d7bf3f5610be5e58a05f Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 15 Aug 2020 17:26:38 -0700 Subject: [PATCH 2/3] document additional parameter to checkFreeTiles --- docs/Lua API.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 45ccd46a9..28b90f0d0 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -1617,11 +1617,12 @@ General using width and height for flexible dimensions. Returns *is_flexible, width, height, center_x, center_y*. -* ``dfhack.buildings.checkFreeTiles(pos,size[,extents,change_extents,allow_occupied])`` +* ``dfhack.buildings.checkFreeTiles(pos,size[,extents,change_extents,allow_occupied,is_civzone])`` Checks if the rectangle defined by ``pos`` and ``size``, and possibly extents, can be used for placing a building. If ``change_extents`` is true, bad tiles are removed from extents. If ``allow_occupied``, the occupancy test is skipped. + Set ``is_civzone`` to true if the building is a civzone (like an activity zone). * ``dfhack.buildings.countExtentTiles(extents,defval)`` From e546d3eec3758670d66d7bb1ab5d9cfa9f052a85 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 15 Aug 2020 20:13:48 -0700 Subject: [PATCH 3/3] rename is_civzone to the more general allow_wall --- docs/Lua API.rst | 5 +++-- library/include/modules/Buildings.h | 2 +- library/modules/Buildings.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 28b90f0d0..f9c6c1e60 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -1617,12 +1617,13 @@ General using width and height for flexible dimensions. Returns *is_flexible, width, height, center_x, center_y*. -* ``dfhack.buildings.checkFreeTiles(pos,size[,extents,change_extents,allow_occupied,is_civzone])`` +* ``dfhack.buildings.checkFreeTiles(pos,size[,extents,change_extents,allow_occupied,allow_wall])`` Checks if the rectangle defined by ``pos`` and ``size``, and possibly extents, can be used for placing a building. If ``change_extents`` is true, bad tiles are removed from extents. If ``allow_occupied``, the occupancy test is skipped. - Set ``is_civzone`` to true if the building is a civzone (like an activity zone). + Set ``allow_wall`` to true if the building is unhindered by walls (such as an + activity zone). * ``dfhack.buildings.countExtentTiles(extents,defval)`` diff --git a/library/include/modules/Buildings.h b/library/include/modules/Buildings.h index 256e3b7e6..94bf75499 100644 --- a/library/include/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -143,7 +143,7 @@ DFHACK_EXPORT bool checkFreeTiles(df::coord pos, df::coord2d size, df::building_extents *ext = NULL, bool create_ext = false, bool allow_occupied = false, - bool is_civzone = false); + bool allow_wall = false); /** * Returns the number of tiles included by the extent, or defval. diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 3d708dc92..976ade441 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -576,7 +576,7 @@ bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size, df::building_extents *ext, bool create_ext, bool allow_occupied, - bool is_civzone) + bool allow_wall) { bool found_any = false; @@ -611,7 +611,7 @@ bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size, else { auto tile = block->tiletype[btile.x][btile.y]; - if (!is_civzone && !HighPassable(tile)) + if (!allow_wall && !HighPassable(tile)) allowed = false; }