From 59d0da8c5a8ddd1b7b7c47b330840ee26c94d014 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 4 Oct 2024 22:33:57 -0700 Subject: [PATCH] remove converted units from current conflicts --- changelog.txt | 2 +- makeown.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 90278e713..6f889e816 100644 --- a/changelog.txt +++ b/changelog.txt @@ -34,7 +34,7 @@ Template for new versions: ## Fixes - `gui/quickfort`: only print a help blueprint's text once even if the repeat setting is enabled -- `makeown`: quell any active enemy relationships with the converted creature +- `makeown`: quell any active enemy or conflict relationships with converted creatures - `fix/loyaltycascade`: allow the fix to work on non-dwarven citizens - `control-panel`: fix setting numeric preferences from the commandline diff --git a/makeown.lua b/makeown.lua index 73054f6ed..5ffc4bf7c 100644 --- a/makeown.lua +++ b/makeown.lua @@ -83,6 +83,23 @@ function clear_enemy_status(unit) end end +local prof_map = { + [df.profession.MERCHANT]=df.profession.TRADER, + [df.profession.THIEF]=df.profession.STANDARD, + [df.profession.MASTER_THIEF]=df.profession.STANDARD, + [df.profession.CRIMINAL]=df.profession.STANDARD, + [df.profession.DRUNK]=df.profession.STANDARD, + [df.profession.MONSTER_SLAYER]=df.profession.STANDARD, + [df.profession.SCOUT]=df.profession.STANDARD, + [df.profession.BEAST_HUNTER]=df.profession.STANDARD, + [df.profession.SNATCHER]=df.profession.STANDARD, + [df.profession.MERCENARY]=df.profession.STANDARD, +} + +local function sanitize_profession(prof) + return prof_map[prof] or prof +end + local function fix_unit(unit) unit.flags1.marauder = false; unit.flags1.merchant = false; @@ -104,8 +121,34 @@ local function fix_unit(unit) unit.civ_id = df.global.plotinfo.civ_id; - if unit.profession == df.profession.MERCHANT then unit.profession = df.profession.TRADER end - if unit.profession2 == df.profession.MERCHANT then unit.profession2 = df.profession.TRADER end + unit.profession = sanitize_profession(unit.profession) + unit.profession2 = sanitize_profession(unit.profession2) + + unit.invasion_id = -1 + unit.enemy.army_controller_id = -1 + unit.enemy.army_controller = nil + + unit.relationship_ids.GroupLeader = -1 + for _,other in ipairs(df.global.world.units.active) do + if other.relationship_ids.GroupLeader == unit.id then + other.relationship_ids.GroupLeader = -1 + end + end + + -- remove unit from all current conflicts + unit.activities:resize(0) + for _,act in ipairs(df.global.world.activities.all) do + if act.type ~= df.activity_entry_type.Conflict then goto continue end + for _,ev in ipairs(act.events) do + if ev:getType() ~= df.activity_event_type.Conflict then goto next_ev end + for _,side in ipairs(ev.sides) do + utils.erase_sorted(side.histfig_ids, unit.hist_figure_id) + utils.erase_sorted(side.unit_ids, unit.id) + end + ::next_ev:: + end + ::continue:: + end clear_enemy_status(unit) end @@ -228,6 +271,8 @@ local function fix_histfig(unit) -- add them to our civ/site if they aren't already if not found_civlink then entity_link(hf, civ_id) end if not found_fortlink then entity_link(hf, group_id) end + + hf.profession = sanitize_profession(unit.profession) end ---@param unit df.unit