Skip to content

Commit

Permalink
Merge pull request #931 from myk002/myk_bad_squad
Browse files Browse the repository at this point in the history
[uniform-unstick] warn if unit's squad is from another site
  • Loading branch information
myk002 authored Jan 7, 2024
2 parents b1d1e7d + 41f1c4a commit 5c0545f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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

Expand Down
26 changes: 23 additions & 3 deletions uniform-unstick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit 5c0545f

Please sign in to comment.