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 56b94483b..83573b9fb 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" @@ -455,27 +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) { - // 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) - return false; - - auto shape = tileShape(*ttype); - auto shapeBasic = tileShapeBasic(shape); - if (tileShapeBasic(shape) != 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 ||