From 1a016a0ff36988869046255ab9bc8a02f11ff744 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 7 Jun 2021 07:02:46 -0700 Subject: [PATCH 1/2] force creation of extents for abstract buildings --- library/modules/Buildings.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) 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()) From 473b8245b20826ebeef5550d194e4aba856148a7 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 7 Jun 2021 07:04:23 -0700 Subject: [PATCH 2/2] update changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 668328f22..5ecfd486e 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -63,6 +63,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - The ``test/main`` command to invoke the test harness has been renamed to just ``test`` - 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 +- 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