@@ -83,6 +83,23 @@ function clear_enemy_status(unit)
8383 end
8484end
8585
86+ local prof_map = {
87+ [df .profession .MERCHANT ]= df .profession .TRADER ,
88+ [df .profession .THIEF ]= df .profession .STANDARD ,
89+ [df .profession .MASTER_THIEF ]= df .profession .STANDARD ,
90+ [df .profession .CRIMINAL ]= df .profession .STANDARD ,
91+ [df .profession .DRUNK ]= df .profession .STANDARD ,
92+ [df .profession .MONSTER_SLAYER ]= df .profession .STANDARD ,
93+ [df .profession .SCOUT ]= df .profession .STANDARD ,
94+ [df .profession .BEAST_HUNTER ]= df .profession .STANDARD ,
95+ [df .profession .SNATCHER ]= df .profession .STANDARD ,
96+ [df .profession .MERCENARY ]= df .profession .STANDARD ,
97+ }
98+
99+ local function sanitize_profession (prof )
100+ return prof_map [prof ] or prof
101+ end
102+
86103local function fix_unit (unit )
87104 unit .flags1 .marauder = false ;
88105 unit .flags1 .merchant = false ;
@@ -104,8 +121,34 @@ local function fix_unit(unit)
104121
105122 unit .civ_id = df .global .plotinfo .civ_id ;
106123
107- if unit .profession == df .profession .MERCHANT then unit .profession = df .profession .TRADER end
108- if unit .profession2 == df .profession .MERCHANT then unit .profession2 = df .profession .TRADER end
124+ unit .profession = sanitize_profession (unit .profession )
125+ unit .profession2 = sanitize_profession (unit .profession2 )
126+
127+ unit .invasion_id = - 1
128+ unit .enemy .army_controller_id = - 1
129+ unit .enemy .army_controller = nil
130+
131+ unit .relationship_ids .GroupLeader = - 1
132+ for _ ,other in ipairs (df .global .world .units .active ) do
133+ if other .relationship_ids .GroupLeader == unit .id then
134+ other .relationship_ids .GroupLeader = - 1
135+ end
136+ end
137+
138+ -- remove unit from all current conflicts
139+ unit .activities :resize (0 )
140+ for _ ,act in ipairs (df .global .world .activities .all ) do
141+ if act .type ~= df .activity_entry_type .Conflict then goto continue end
142+ for _ ,ev in ipairs (act .events ) do
143+ if ev :getType () ~= df .activity_event_type .Conflict then goto next_ev end
144+ for _ ,side in ipairs (ev .sides ) do
145+ utils .erase_sorted (side .histfig_ids , unit .hist_figure_id )
146+ utils .erase_sorted (side .unit_ids , unit .id )
147+ end
148+ :: next_ev::
149+ end
150+ :: continue::
151+ end
109152
110153 clear_enemy_status (unit )
111154end
@@ -228,6 +271,8 @@ local function fix_histfig(unit)
228271 -- add them to our civ/site if they aren't already
229272 if not found_civlink then entity_link (hf , civ_id ) end
230273 if not found_fortlink then entity_link (hf , group_id ) end
274+
275+ hf .profession = sanitize_profession (unit .profession )
231276end
232277
233278--- @param unit df.unit
0 commit comments