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 ||