Skip to content

Commit

Permalink
Add warn-stuck-trees.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed Jul 1, 2017
1 parent 5832de6 commit 5bc372d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions warn-stuck-trees.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Detects citizens stuck in trees

--[====[
warn-stuck-trees
================
Displays an announcement for any civilians detected stuck in trees. Intended to
be run with `repeat`.
By default, the game pauses and recenters when an announcement is made. This
behavior can be changed with the following flags:
- ``-no-recenter``: Do not recenter on stuck dwarves.
- ``-no-pause``: Do not pause the game. This flag is not recommended unless
``-no-recenter`` is used as well.
]====]

args = require("utils").processArgs{...}

announcement_flags = {
D_DISPLAY = true,
PAUSE = not args["no-pause"],
RECENTER = not args["no-recenter"],
}

function getName(unit)
local name = dfhack.TranslateName(dfhack.units.getVisibleName(unit))
if name == '' then
name = dfhack.units.getProfessionName(unit)
end
return name
end

for _, unit in pairs(df.global.world.units.all) do
if dfhack.units.isCitizen(unit) then
if df.tiletype.attrs[dfhack.maps.getTileType(unit.pos)].material == df.tiletype_material.TREE then
dfhack.gui.makeAnnouncement(0, announcement_flags, unit.pos,
getName(unit) .. ' is stuck in a tree', COLOR_LIGHTMAGENTA)
end
end
end

0 comments on commit 5bc372d

Please sign in to comment.