diff --git a/docs/changelog.txt b/docs/changelog.txt index 78e8a56cc3..f4e467c2be 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -63,6 +63,7 @@ Template for new versions: ## Fixes - Fix broken weather lookup in ``World::ReadCurrentWeather`` +- `buildingplan`: link planned gem and glass windows to existing rooms and zones - Fixed a possible hang or assertion failure when pressing a hotkey while a DFHack GUI window was open but unfocused - In ``Screen`` module, Fix out-of-bounds color table access when Lua pens use ``COLOR_RESET`` - `3dveins`: fix failure on embarks that cross midmap tiles diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index ddedbbc1b6..52513530cb 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -195,7 +195,14 @@ static void zone_into_building_unidir(df::building* bld, df::building_civzonest* static bool is_suitable_building_for_zoning(df::building* bld) { - return bld->canMakeRoom(); + switch (bld->getType()) + { + case building_type::WindowGlass: + case building_type::WindowGem: + return true; + default: + return bld->canMakeRoom(); + } } static void add_building_to_zone(df::building* bld, df::building_civzonest* zone) diff --git a/test/modules/buildings_fortress.lua b/test/modules/buildings_fortress.lua new file mode 100644 index 0000000000..f932a8098b --- /dev/null +++ b/test/modules/buildings_fortress.lua @@ -0,0 +1,50 @@ +config.target = 'core' +config.mode = 'fortress' + +local function contains(vec, value) + for _,entry in ipairs(vec) do + if entry == value then return true end + end + return false +end + +local function construct_window_in_zone(window_type) + for _,zone in ipairs(df.global.world.buildings.other.ANY_ZONE) do + if zone.room.extents then + for y = zone.y1, zone.y2 do + for x = zone.x1, zone.x2 do + local pos = xyz2pos(x, y, zone.z) + if not dfhack.buildings.findAtTile(pos) then + local bld = dfhack.buildings.constructBuilding{ + pos=pos, + type=window_type, + filters=dfhack.buildings.getFiltersByType( + {}, window_type, -1, -1), + } + if bld then return bld, zone end + end + end + end + end + end +end + +local function expect_window_linked(window_type) + local bld, zone = construct_window_in_zone(window_type) + expect.ne(nil, bld, 'could not find a zone tile suitable for a window') + if not bld then return end + dfhack.with_finalize( + function() dfhack.buildings.deconstruct(bld) end, + function() + expect.true_(contains(bld.relations, zone)) + expect.true_(contains(zone.contained_buildings, bld)) + end) +end + +function test.constructed_gem_window_is_linked_to_zone() + expect_window_linked(df.building_type.WindowGem) +end + +function test.constructed_glass_window_is_linked_to_zone() + expect_window_linked(df.building_type.WindowGlass) +end