Skip to content

Commit b101452

Browse files
committed
Merge remote-tracking branch 'PatrikLundell/dead_misuse'
2 parents e580b16 + 506efce commit b101452

11 files changed

Lines changed: 50 additions & 37 deletions

adaptation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def usage(s)
5757

5858
set_adaptation_value = lambda { |u,v|
5959
next if !df.unit_iscitizen(u)
60-
next if u.flags1.dead
60+
next if u.flags2.killed
6161
u.status.misc_traits.each { |t|
6262
if t.id == :CaveAdapt
6363
# TBD: expose the color_ostream console and color values of

devel/export-dt-ini.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,12 @@ write_flags('valid_flags_2', {})
485485
write_flags('invalid_flags_1', {
486486
{ 'a skeleton', { df.unit_flags1.skeleton } },
487487
{ 'a merchant', { df.unit_flags1.merchant } },
488-
{ 'outpost liaison or diplomat', { df.unit_flags1.diplomat } },
488+
{ 'outpost liaison, diplomat, or artifact requesting visitor', { df.unit_flags1.diplomat } },
489489
{ 'an invader or hostile', { df.unit_flags1.active_invader } },
490490
{ 'an invader or hostile', { df.unit_flags1.invader_origin } },
491491
{ 'resident, invader or ambusher', { df.unit_flags1.hidden_ambusher, df.unit_flags1.invades } },
492492
{ 'part of a merchant caravan', { df.unit_flags1.forest } },
493-
{ 'Dead, Jim.', { df.unit_flags1.dead } },
493+
{ 'inactive, currently not in play', { df.unit_flags1.dead } },
494494
{ 'marauder', { df.unit_flags1.marauder } }
495495
});
496496
write_flags ('invalid_flags_2', {

emigration.lua

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,27 @@ function desert(u,method,civ)
5858
end
5959

6060
function canLeave(unit)
61+
if not unit.status.current_soul then
62+
return false
63+
end
64+
6165
for _, skill in pairs(unit.status.current_soul.skills) do
6266
if skill.rating > 14 then return false end
6367
end
64-
if unit.flags1.caged
65-
or unit.race ~= df.global.ui.race_id
66-
or unit.civ_id ~= df.global.ui.civ_id
67-
or dfhack.units.isDead(unit)
68-
or dfhack.units.isOpposedToLife(unit)
69-
or unit.flags1.merchant
70-
or unit.flags1.diplomat
71-
or unit.flags1.chained
72-
or dfhack.units.getNoblePositions(unit) ~= nil
73-
or unit.military.squad_id ~= -1
74-
or dfhack.units.isCitizen(unit)
75-
or dfhack.units.isSane(unit)
76-
or unit.profession ~= 103
77-
or not dfhack.units.isDead(unit)
78-
then return false end
79-
return true
68+
69+
return dfhack.units.isOwnRace(unit) and -- Doubtful check. naturalized citizens
70+
dfhack.units.isOwnCiv(unit) and -- might also want to leave.
71+
dfhack.units.isActive(unit) and
72+
not dfhack.units.isOpposedToLife(unit) and
73+
not unit.flags1.merchant and
74+
not unit.flags1.diplomat and
75+
not unit.flags1.chained and
76+
dfhack.units.getNoblePositions(unit) == nil and
77+
unit.military.squad_id == -1 and
78+
dfhack.units.isCitizen(unit) and
79+
dfhack.units.isSane(unit) and
80+
not dfhack.units.isBaby(unit) and
81+
not dfhack.units.isChild(unit)
8082
end
8183

8284
function checkForDeserters(method,civ_id)
@@ -96,7 +98,7 @@ function checkmigrationnow()
9698
for i=0, #allUnits-1 do
9799
local unit = allUnits[i]
98100
if dfhack.units.isSane(unit)
99-
and not dfhack.units.isDead(unit)
101+
and dfhack.units.isActive(unit)
100102
and not dfhack.units.isOpposedToLife(unit)
101103
and not unit.flags1.tame
102104
then

exterminate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
# it's getting hot around here
7777
# !!WARNING!! do not call on a magma-safe creature
7878
ouh = df.onupdate_register("exterminate ensure #{u.id}", 1) {
79-
if u.flags1.dead
79+
if u.flags2.killed
8080
df.onupdate_unregister(ouh)
8181
else
8282
x, y, z = u.pos.x, u.pos.y, u.pos.z

fix/dead-units.lua

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,35 @@ to around 3000 units, and this script reduces it back.
99
1010
]====]
1111
local units = df.global.world.units.active
12-
local dwarf_race = df.global.ui.race_id
13-
local dwarf_civ = df.global.ui.civ_id
1412
local count = 0
13+
local month = 1200 * 28
14+
local year = month * 12
1515

1616
for i=#units-1,0,-1 do
1717
local unit = units[i]
18-
local flags1 = unit.flags1
19-
local flags2 = unit.flags2
20-
if flags1.dead and flags2.killed and unit.race ~= dwarf_race then
18+
if dfhack.units.isDead(unit) and not dfhack.units.isOwnRace(unit) then
2119
local remove = false
22-
if flags2.slaughter then
20+
if dfhack.units.isMarkedForSlaughter(unit) then
2321
remove = true
24-
elseif not unit.name.has_name then
22+
elseif unit.hist_figure_id == -1 then
2523
remove = true
26-
elseif unit.civ_id ~= dwarf_civ and
27-
not (flags1.merchant or flags1.diplomat) then
24+
elseif not dfhack.units.isOwnCiv(unit) and
25+
not (dfhack.units.isMerchant(unit) or dfhack.units.isDiplomat(unit)) then
2826
remove = true
2927
end
28+
if remove and unit.counters.death_id ~= -1 then -- Keep recent deaths around for a month before culling them. It's annoying to have that
29+
-- rampaging FB just be gone from both the other and dead lists, and you may want to keep
30+
-- killed wildlife around for a while too.
31+
-- We don't have a time of death for slaughtered units, so they go the first time.
32+
local incident = df.incident.find(unit.counters.death_id)
33+
if incident then
34+
local incident_time = incident.event_year * year + incident.event_time
35+
local now = df.global.cur_year * year + df.global.cur_year_tick
36+
if now - incident_time < month then
37+
remove = false -- Wait a while before culling it.
38+
end
39+
end
40+
end
3041
if remove then
3142
count = count + 1
3243
units:erase(i)

fix/feeding-timers.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
local fixcount = 0
1919
for _,unit in ipairs(df.global.world.units.all) do
20-
if dfhack.units.isCitizen(unit) and not (unit.flags1.dead) then
20+
if dfhack.units.isCitizen(unit) and dfhack.units.isActive(unit) then
2121
for _,v in pairs(unit.status.misc_traits) do
2222
local didfix = 0
2323
if v.id == 0 then -- I think this should have additional conditions...

fix/stuck-merchants.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function dismissMerchants(args)
4545
end
4646
end
4747
for _,u in pairs(df.global.world.units.active) do
48-
if u.flags1.merchant and u.flags1.dead then
48+
if u.flags1.merchant and not dfhack.units.isActive (u) then
4949
print(('%s unit %d: %s (%s), civ %d (%s, %s)'):format(
5050
dry_run and 'Would remove' or 'Removing',
5151
u.id,

full-heal.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555

5656
if unit then
5757
if args.r then
58-
if unit.flags1.dead then
58+
if unit.flags2.killed then
5959
--print("Resurrecting...")
6060
unit.flags2.slaughter = false
6161
unit.flags3.scuttle = false
@@ -188,7 +188,7 @@ if unit then
188188
--print("Clearing historical wounds...")
189189
histFig.info.wounds = nil
190190
end
191-
191+
192192
local health = unit.health
193193
if health then
194194
for i = 0, #health.flags-1,1 do

gui/room-list.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ end
141141

142142
function can_modify(sel_item)
143143
return sel_item and sel_item.owner
144-
and sel_item.can_use and not sel_item.owner.flags1.dead
144+
and sel_item.can_use and not sel_item.owner.flags2.killed
145145
end
146146

147147
function RoomList:onRenderBody(dc)

gui/unit-info-viewer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ function Identity:init(args)
408408

409409

410410
------------ death ------------
411-
self.dead = u.flags1.dead
411+
self.dead = u.flags2.killed
412412
self.ghostly = u.flags3.ghostly
413413
self.undead = u.enemy.undead
414414

0 commit comments

Comments
 (0)