Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Template for new versions:

## Fixes

- `fix/loyaltycascade`: guard against citizens that are not historical figures and emit a warning.

## Misc Improvements
- `caravan`: the ``Bring goods to depot``, ``Trade``, and ``Assign items for display`` overlays now allow searching for items with non-ASCII characters in their description
- `caravan`: the ``Trade`` overlay will use the trader's appraisal skill instead of the broker's to round/obfuscate the value of items
Expand Down
11 changes: 10 additions & 1 deletion fix/loyaltycascade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
local makeown = reqscript('makeown')

-- Checks if a unit is a former member of a given entity as well as it's
-- current enemy.
-- current enemy (assumes valid historical figure with entity links).
local function getUnitRenegade(unit, entity_id)
local unit_entity_links = df.historical_figure.find(unit.hist_figure_id).entity_links
local former_index = nil
Expand All @@ -29,6 +29,8 @@ local function getUnitRenegade(unit, entity_id)
return former_index, enemy_index
end

-- convert unit to new entity
-- (assumes valid historical figure with entity links)
local function convertUnit(unit, entity_id, former_index, enemy_index)
local unit_entity_links = df.historical_figure.find(unit.hist_figure_id).entity_links

Expand All @@ -46,6 +48,13 @@ local function fixUnit(unit)
local fixed = false

local unit_name = dfhack.units.getReadableName(unit)

-- utility functions assume valid historical figure id
if not df.historical_figure.find(unit.hist_figure_id) then
print(('%s: skipping citizen without historical figure: %s'):format(dfhack.current_script_name(), unit_name))
return
end

local former_civ_index, enemy_civ_index = getUnitRenegade(unit, df.global.plotinfo.civ_id)
local former_group_index, enemy_group_index = getUnitRenegade(unit, df.global.plotinfo.group_id)

Expand Down
Loading