Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[starvingdead] vanish the undead instead of marking them inactive #795

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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