Skip to content

Commit e608d2f

Browse files
authored
Fixed mothers attempting to seek their units that were babies
Fixed mothers attempting to seek their units that were babies by removing the unit id from the ANY_BABY table. Also made those grown babies act like adults by updating some flags.
1 parent 90365d3 commit e608d2f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

rejuvenate.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,36 @@ function rejuvenate(unit, force, dry_run, age)
2424
unit.old_year = new_birth_year + 160
2525
end
2626
if unit.profession == df.profession.BABY or unit.profession == df.profession.CHILD then
27+
if unit.profession == df.profession.BABY then
28+
local leftoverUnits = {}
29+
local shiftedLeftoverUnits = {}
30+
-- create a copy
31+
local babyUnits = df.global.world.units.other.ANY_BABY
32+
-- create a new table with the units that aren't being removed in this iteration
33+
for _, v in ipairs(babyUnits) do
34+
if not v.id == unit.id then
35+
table.insert(leftoverUnits, v)
36+
end
37+
end
38+
-- create a shifted table of the leftover units to make up for lua tables starting with index 1 and the game starting with index 0
39+
for i = 0, #leftoverUnits - 1, 1 do
40+
local x = i+1
41+
shiftedLeftoverUnits[i] = leftoverUnits[x]
42+
end
43+
-- copy the leftover units back to the game table
44+
df.global.world.units.other.ANY_BABY = shiftedLeftoverUnits
45+
-- set extra flags to defaults
46+
unit.flags1.rider = false
47+
unit.relationship_ids.RiderMount = -1
48+
unit.mount_type = 0
49+
unit.profession2 = df.profession.STANDARD
50+
unit.idle_area_type = 26
51+
unit.mood = -1
52+
53+
-- let the mom know she isn't carrying anyone anymore
54+
local motherUnitId = unit.relationship_ids.Mother
55+
df.unit.find(motherUnitId).flags1.ridden = false
56+
end
2757
unit.profession = df.profession.STANDARD
2858
end
2959
print(name .. ' is now ' .. age .. ' years old and will live to at least 160')

0 commit comments

Comments
 (0)