diff --git a/docs/changelog.txt b/docs/changelog.txt index 39d19c573..a3b350559 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -35,6 +35,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - Fixed an issue where scrollable text in Lua-based screens could prevent other widgets from scrolling +- Fixed an issue preventing some external scripts from creating zones and other abstract buildings (see note about room definitions under "Internals") - `buildingplan`: fixed an issue where planned constructions designated with DF's sizing keys (``umkh``) would sometimes be larger than requested - `buildingplan`: fixed an issue preventing other plugins like `automaterial` from planning constructions if the "enable all" buildingplan setting was turned on - `command-prompt`: fixed issues where overlays created by running certain commands (e.g. `gui/liquids`, `gui/teleport`) would not update the parent screen correctly @@ -81,6 +82,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - DFHack unit tests must now match any output expected to be printed via ``dfhack.printerr()`` - Fortress mode is now supported for unit tests (allowing tests that require a fortress map to be loaded) - note that these tests are skipped by continuous integration for now, pending a suitable test fortress - Unit tests can now use ``delay_until(predicate_fn, timeout_frames)`` to delay until a condition is met +- Room definitions and extents are now created for abstract buildings so callers don't have to initialize the room structure themselves # 0.47.05-r1 diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 3dab347d5..3d0d5a563 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -587,6 +587,18 @@ bool Buildings::getCorrectSize(df::coord2d &size, df::coord2d ¢er, } } +static void init_extents(df::building_extents *ext, const df::coord &pos, + const df::coord2d &size) +{ + ext->extents = new df::building_extents_type[size.x*size.y]; + ext->x = pos.x; + ext->y = pos.y; + ext->width = size.x; + ext->height = size.y; + + memset(ext->extents, 1, size.x*size.y); +} + bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size, df::building_extents *ext, bool create_ext, @@ -640,13 +652,7 @@ bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size, if (!ext->extents) { - ext->extents = new df::building_extents_type[size.x*size.y]; - ext->x = pos.x; - ext->y = pos.y; - ext->width = size.x; - ext->height = size.y; - - memset(ext->extents, 1, size.x*size.y); + init_extents(ext, pos, size); etile = getExtentTile(*ext, tile); } @@ -670,10 +676,17 @@ std::pair Buildings::getSize(df::building *bld) return std::pair(pos, df::coord2d(bld->x2+1,bld->y2+1) - pos); } -static bool checkBuildingTiles(df::building *bld, bool can_change) +static bool checkBuildingTiles(df::building *bld, bool can_change, + bool force_extents = false) { auto psize = Buildings::getSize(bld); + if (force_extents && !bld->room.extents) + { + // populate the room structure if it's not set already + init_extents(&bld->room, psize.first, psize.second); + } + return Buildings::checkFreeTiles(psize.first, psize.second, &bld->room, can_change && bld->isExtentShaped(), !bld->isSettingOccupancy(), @@ -978,7 +991,7 @@ bool Buildings::constructAbstract(df::building *bld) CHECK_INVALID_ARGUMENT(bld->id == -1); CHECK_INVALID_ARGUMENT(!bld->isActual()); - if (!checkBuildingTiles(bld, false)) + if (!checkBuildingTiles(bld, true, true)) return false; switch (bld->getType())