From 9e8ca0e961f3c4c8101260ada1b9c5599ddb3c84 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 6 Jan 2024 15:57:11 -0800 Subject: [PATCH 1/2] warn (and skip) if unit squad is from another site --- uniform-unstick.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/uniform-unstick.lua b/uniform-unstick.lua index aedd747e67..8ba40d6b82 100644 --- a/uniform-unstick.lua +++ b/uniform-unstick.lua @@ -30,9 +30,29 @@ local function get_item_pos(item) end end -local function get_squad_position(unit) +local function get_site_id() + local fort = df.global.world.world_data.active_site[0] + for _, el in ipairs(fort.entity_links) do + local he = df.historical_entity.find(el.entity_id) + if he and he.type == df.historical_entity_type.SiteGovernment then + return el.entity_id + end + end +end + +local site_id = get_site_id() + +local function get_squad_position(unit, unit_name) local squad = df.squad.find(unit.military.squad_id) - if not squad then return end + if squad then + if squad.entity_id ~= site_id then + print("WARNING: Unit " .. unit_name .. " is a member of a squad in another site!" .. + " You can fix this by assigning them to a local squad and then unassigning them.") + return + end + else + return + end if #squad.positions > unit.military.squad_position then return squad.positions[unit.military.squad_position] end @@ -97,7 +117,7 @@ local function process(unit, args) local to_drop = {} -- item id to item object -- First get squad position for an early-out for non-military dwarves - local squad_position = get_squad_position(unit) + local squad_position = get_squad_position(unit, unit_name) if not squad_position then if not silent then print("Unit " .. unit_name .. " does not have a military uniform.") From 41f1c4a398221a1b04a6239d50ede73ac6a81a47 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 6 Jan 2024 15:58:53 -0800 Subject: [PATCH 2/2] update changelog --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 439ad2ec69..959d30902b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -55,6 +55,7 @@ Template for new versions: - `gui/autobutcher`: interface redesigned to better support mouse control - `gui/launcher`: now persists the most recent 32KB of command output even if you close it and bring it back up - `gui/quickcmd`: clickable buttons for command add/remove/edit operations +- `uniform-unstick`: warn if a unit belongs to a squad from a different site (can happen with migrants from previous forts) - `gui/mass-remove`: can now differentiate planned constructions, stockpiles, and regular buildings - `gui/mass-remove`: can now remove zones