From 092979f3624d9029c14d77688a85746aa1a245ad Mon Sep 17 00:00:00 2001 From: DoctorVanGogh Date: Mon, 2 Nov 2015 02:51:52 +0100 Subject: [PATCH 1/4] Prevent building floor on top of constructed floor (mostly) --- plugins/automaterial.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index 56b94483b..508831b77 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -32,6 +32,7 @@ #include "modules/Constructions.h" #include "modules/Buildings.h" #include "modules/Maps.h" +#include "modules/MapCache.h" #include "TileTypes.h" #include "df/job_item.h" @@ -459,20 +460,28 @@ static bool is_valid_building_site(building_site &site, bool orthogonal_check, b return false; if (material == tiletype_material::CONSTRUCTION) - { - // Can build on top of a wall, but not on a constructed floor + { + // Check this is not a 'constructed floor over X': + // those have something else than open space as *basic* tile types: stonefloor, smoothstonefloor, ... + MapExtras::MapCache mc; + auto btt = mc.baseTiletypeAt(site.pos); + auto bshape = tileShape(btt); + if (bshape != tiletype_shape_basic::Open) + return false; + + // Can build on top of a wall, but not on a constructed floor df::coord pos_below = site.pos; pos_below.z--; if (!Maps::isValidTilePos(pos_below)) return false; - auto ttype = Maps::getTileType(pos_below); - if (!ttype) + auto ttype_below = Maps::getTileType(pos_below); + if (!ttype_below) return false; - auto shape = tileShape(*ttype); - auto shapeBasic = tileShapeBasic(shape); - if (tileShapeBasic(shape) != tiletype_shape_basic::Wall) + auto shape_below = tileShape(*ttype_below); + auto shapeBasic_below = tileShapeBasic(shape_below); + if (tileShapeBasic(shape_below) != tiletype_shape_basic::Wall) return false; } From a7fe1d9d731d23f7d57c9c9068748c3f66c6b545 Mon Sep 17 00:00:00 2001 From: DoctorVanGogh Date: Mon, 2 Nov 2015 05:05:17 +0100 Subject: [PATCH 2/4] Formatting --- plugins/automaterial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index 508831b77..01b275eaf 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -460,7 +460,7 @@ static bool is_valid_building_site(building_site &site, bool orthogonal_check, b return false; if (material == tiletype_material::CONSTRUCTION) - { + { // Check this is not a 'constructed floor over X': // those have something else than open space as *basic* tile types: stonefloor, smoothstonefloor, ... MapExtras::MapCache mc; From d692458038b75564434a6fc32d80b2a4e1f1b8c6 Mon Sep 17 00:00:00 2001 From: DoctorVanGogh Date: Tue, 3 Nov 2015 10:07:27 +0100 Subject: [PATCH 3/4] Formatting --- plugins/automaterial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index 01b275eaf..cc38dc763 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -469,7 +469,7 @@ static bool is_valid_building_site(building_site &site, bool orthogonal_check, b if (bshape != tiletype_shape_basic::Open) return false; - // Can build on top of a wall, but not on a constructed floor + // Can build on top of a wall, but not on a constructed floor df::coord pos_below = site.pos; pos_below.z--; if (!Maps::isValidTilePos(pos_below)) From e9be1aa657596ea8bab31b89700ca0fc5a7f8d1a Mon Sep 17 00:00:00 2001 From: DoctorVanGogh Date: Fri, 6 Nov 2015 19:00:43 +0100 Subject: [PATCH 4/4] Fix for construction over existing construction & on top of walls Fix to allow constructions on top of (natural) down stairs --- library/include/modules/Constructions.h | 1 + library/modules/Constructions.cpp | 9 ++++++++ plugins/automaterial.cpp | 30 +++++-------------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/library/include/modules/Constructions.h b/library/include/modules/Constructions.h index 41959b2d7..3831d4bb1 100644 --- a/library/include/modules/Constructions.h +++ b/library/include/modules/Constructions.h @@ -59,6 +59,7 @@ DFHACK_EXPORT bool isValid(); DFHACK_EXPORT uint32_t getCount(); DFHACK_EXPORT bool copyConstruction (const int32_t index, t_construction &out); DFHACK_EXPORT df::construction * getConstruction (const int32_t index); +DFHACK_EXPORT df::construction * findAtTile(df::coord pos); DFHACK_EXPORT bool designateNew(df::coord pos, df::construction_type type, df::item_type item = df::item_type::NONE, int mat_index = -1); diff --git a/library/modules/Constructions.cpp b/library/modules/Constructions.cpp index 16c1f1b89..a60059b5c 100644 --- a/library/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -68,6 +68,15 @@ df::construction * Constructions::getConstruction(const int32_t index) return world->constructions[index]; } +df::construction * Constructions::findAtTile(df::coord pos) +{ + for (auto it = begin (world->constructions); it != end (world->constructions); ++it) { + if ((*it)->pos == pos) + return *it; + } + return NULL; +} + bool Constructions::copyConstruction(const int32_t index, t_construction &out) { if (uint32_t(index) >= getCount()) diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index cc38dc763..83573b9fb 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -456,35 +456,17 @@ static bool is_valid_building_site(building_site &site, bool orthogonal_check, b } else { - if (shape_basic != tiletype_shape_basic::Floor) + if (shape != tiletype_shape::STAIR_DOWN && shape_basic != tiletype_shape_basic::Floor) return false; - if (material == tiletype_material::CONSTRUCTION) + // Can build on top of a wall, but not on other construction + auto construction = Constructions::findAtTile(site.pos); + if (construction) { - // Check this is not a 'constructed floor over X': - // those have something else than open space as *basic* tile types: stonefloor, smoothstonefloor, ... - MapExtras::MapCache mc; - auto btt = mc.baseTiletypeAt(site.pos); - auto bshape = tileShape(btt); - if (bshape != tiletype_shape_basic::Open) - return false; - - // Can build on top of a wall, but not on a constructed floor - df::coord pos_below = site.pos; - pos_below.z--; - if (!Maps::isValidTilePos(pos_below)) - return false; - - auto ttype_below = Maps::getTileType(pos_below); - if (!ttype_below) - return false; - - auto shape_below = tileShape(*ttype_below); - auto shapeBasic_below = tileShapeBasic(shape_below); - if (tileShapeBasic(shape_below) != tiletype_shape_basic::Wall) + if (construction->flags.bits.top_of_wall==0) return false; } - + if (material == tiletype_material::FIRE || material == tiletype_material::POOL || material == tiletype_material::BROOK ||