Skip to content

Commit

Permalink
Merge pull request #795 from myk002/myk_starvingdead
Browse files Browse the repository at this point in the history
[starvingdead] vanish the undead instead of marking them inactive
  • Loading branch information
myk002 authored Aug 12, 2023
2 parents c893121 + d1ed5b7 commit a8f23a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Template for new versions:
- `caravan`: Correct price adjustment values in trade agreement details screen
- `caravan`: Apply both import and export trade agreement price adjustments to items being both bought or sold to align with how vanilla DF calculates prices
- `suspendmanager`: Improve the detection on "T" and "+" shaped high walls
- `starvingdead`: ensure sieges end properly when undead siegers starve

## Misc Improvements
- `devel/lsmem`: added support for filtering by memory addresses and filenames
Expand Down
13 changes: 4 additions & 9 deletions starvingdead.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,30 @@ end
StarvingDead = defclass(StarvingDead)
StarvingDead.ATTRS{
decay_rate = 1,
death_threshold = 6
death_threshold = 6,
}

function StarvingDead:init()
self.timeout_id = nil
-- Percentage goal each attribute should reach before death.
self.attribute_goal = 10
self.attribute_decay = (self.attribute_goal ^ (1 / ((self.death_threshold * 28 / self.decay_rate)))) / 100
self.undead_count = 0
local attribute_goal = 10
self.attribute_decay = (attribute_goal ^ (1 / ((self.death_threshold * 28 / self.decay_rate)))) / 100

self:checkDecay()
print(([[StarvingDead started, checking every %s days and killing off at %s months]]):format(self.decay_rate, self.death_threshold))
end

function StarvingDead:checkDecay()
self.undead_count = 0
for _, unit in pairs(df.global.world.units.active) do
if (unit.enemy.undead and not unit.flags1.inactive) then
self.undead_count = self.undead_count + 1

-- time_on_site is measured in ticks, a month is 33600 ticks.
-- @see https://dwarffortresswiki.org/index.php/Time
for _, attribute in pairs(unit.body.physical_attrs) do
attribute.value = math.floor(attribute.value - (attribute.value * self.attribute_decay))
end

if unit.curse.time_on_site > (self.death_threshold * 33600) then
unit.flags1.inactive = true
unit.curse.rem_tags2.FIT_FOR_ANIMATION = true
unit.animal.vanish_countdown = 1
end
end
end
Expand Down

0 comments on commit a8f23a2

Please sign in to comment.