diff --git a/docs/changelog.txt b/docs/changelog.txt index 194bcd289b..0b048102fa 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -55,6 +55,7 @@ Template for new versions: ## New Features - `sort`: search and sort for the "choose unit to elevate to the barony" screen. units are sorted by the number of item preferences they have and the units are annotated with the items that they have preferences for +- `zone`: add button to location details page for retiring unused locations - `gui/mass-remove`: new global keybinding: Ctrl-M while on the fort map ## Fixes diff --git a/plugins/lua/zone.lua b/plugins/lua/zone.lua index d886a33d99..b82ac72e77 100644 --- a/plugins/lua/zone.lua +++ b/plugins/lua/zone.lua @@ -1168,12 +1168,19 @@ end function RetireLocationOverlay:confirm_retire() local details = mi.location_details local location = details.selected_ab - local num_occupations, num_zones = 0, #location.contents.building_ids + local num_occupations, num_zones = 0, 0 for _, occupation in ipairs(location.occupations) do if occupation.histfig_id ~= -1 then num_occupations = num_occupations + 1 end end + for _, zone_id in ipairs(location.contents.building_ids) do + -- there can be dangling references in this list; only count + -- "attached" zones that actually exist + if df.building.find(zone_id) then + num_zones = num_zones + 1 + end + end if num_occupations + num_zones > 0 then local messages = {'Cannot retire location! Please:', ''} if num_occupations > 0 then