Skip to content
Open
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 @@ -15,6 +15,7 @@ Template for new versions:
## New Tools

## New Features
- `fix/exploding-trees`: periodically kill trees which have been removed from the map but still exist in the internal list of plants; this prevents them from collapsing once a year.

## Fixes

Expand Down
31 changes: 31 additions & 0 deletions docs/fix/exploding-trees.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
fix/exploding-trees
===================

.. dfhack-tool::
:summary: Removes "phantom" trees before they can explode.
:tags: fort bugfix

By default, this script runs once a month by the Control Panel's Bug Fixes tab.

This script mitigates a longstanding Dwarf Fortress bug.

Once a year, trees check if they should grow. The exact day and time of this
growth is different for every tree.

Occasionally, when a tree is cut down or otherwise removed from the game, the
game engine doesn't remove the tree's data from the list of plants. The exact
details of this are not currently understood.

For some reason, these "phantom" trees will sometimes collapse during this
growth. This can stun, injure, or kill units which happen to be near this
collapse.

This script finds those trees and sets their dead flag, preventing them from
growing and collapsing.

Usage
-----

::

fix/exploding-trees
45 changes: 45 additions & 0 deletions fix/exploding-trees.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- removes "phantom" trees before they can explode.
--[====[
fix/exploding-trees
===================

By default, this script runs once a month by the Control Panel's Bug Fixes tab.

This script mitigates a longstanding Dwarf Fortress bug.

Once a year, trees check if they should grow. The exact day and time of this
growth is different for every tree.

Occasionally, when a tree is cut down or otherwise removed from the game, the
game engine doesn't remove the tree's data from the list of plants. The exact
details of this are not currently understood.

For some reason, these "phantom" trees will sometimes collapse during this
growth. This can stun, injure, or kill units which happen to be near this
collapse.

This script finds those trees and sets their dead flag, preventing them from
growing and collapsing.
--]====]

function suppress_phantom_exploding_trees()
for idx, tree in ipairs(df.global.world.plants.all) do
if not tree.damage_flags.dead
and tree.tree_info ~= nil
and (tree.type == df.plant_type.DRY_TREE
or tree.type == df.plant_type.WET_TREE)
then
local tt = dfhack.maps.getTileType(tree.pos)
local is_trunk = df.tiletype.attrs[tt].material == df.tiletype_material.TREE
if not is_trunk then
tree.damage_flags.dead = true
local announcement = string.format(
"DFHack %s: phantom tree %d at location (%d,%d,%d) suppressed.",
dfhack.current_script_name(), idx, tree.pos.x, tree.pos.y, tree.pos.z)
dfhack.printerr(announcement)
end
end
end
end

suppress_phantom_exploding_trees()
3 changes: 3 additions & 0 deletions internal/control-panel/registry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ COMMANDS_BY_IDX = {
{command='fix/general-strike', group='bugfix', mode='repeat', default=true,
desc='Prevent dwarves from getting stuck and refusing to work.',
params={'--time', '1', '--timeUnits', 'days', '--command', '[', 'fix/general-strike', '-q', ']'}},
{command='fix/kill-exploding-trees', group='bugfix', mode='repeat', default=true,
desc='Removes "phantom" trees before they can explode.',
params={'--time', '1', '--timeUnits', 'months', '--command', '[', 'fix/exploding-trees', ']'}},
{command='fix/ownership', group='bugfix', mode='repeat', default=true,
desc='Fixes instances of units claiming the same item or an item they don\'t own.',
params={'--time', '1', '--timeUnits', 'days', '--command', '[', 'fix/ownership', ']'}},
Expand Down
Loading