Skip to content
Merged
Changes from 5 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
20 changes: 12 additions & 8 deletions deathcause.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- show death cause of a creature
--@ module = true
Comment thread
realSquidCoder marked this conversation as resolved.

local DEATH_TYPES = reqscript('gui/unit-info-viewer').DEATH_TYPES

Expand Down Expand Up @@ -29,8 +30,7 @@ function displayDeathUnit(unit)
str = str .. dfhack.units.getReadableName(unit)

if not dfhack.units.isDead(unit) then
print(dfhack.df2console(str) .. " is not dead yet!")
return
return str .. " is not dead yet!"
Comment thread
realSquidCoder marked this conversation as resolved.
end

str = str .. (" %s"):format(getDeathStringFromCause(unit.counters.death_cause))
Expand All @@ -50,7 +50,7 @@ function displayDeathUnit(unit)
end
end

print(dfhack.df2console(str) .. '.')
return str .. '.'
end

-- returns the item description if the item still exists; otherwise
Comment thread
realSquidCoder marked this conversation as resolved.
Expand Down Expand Up @@ -87,7 +87,7 @@ function displayDeathEventHistFigUnit(histfig_unit, event)
end
end

print(dfhack.df2console(str) .. '.')
return str .. '.'
end

-- Returns the death event for the given histfig or nil if not found
Expand All @@ -109,10 +109,10 @@ function displayDeathHistFig(histfig)
end

if not dfhack.units.isDead(histfig_unit) then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I would suggest not finding the unit at all, and testing histfig.died_year == -1 instead of not dfhack.units.isDead().

You would want to fold in the string formatting that is in getDeathEventHistFigUnit().

dfhack.units.getReadableName() accepts histfigs as well as units.

The only other use you have for a unit is to get the race, which is also in a histfig.

print(("%s is not dead yet!"):format(dfhack.df2console(dfhack.units.getReadableName(histfig_unit))))
return ("%s is not dead yet!"):format(dfhack.units.getReadableName(histfig_unit))
else
local death_event = getDeathEventForHistFig(histfig.id)
displayDeathEventHistFigUnit(histfig_unit, death_event)
return displayDeathEventHistFigUnit(histfig_unit, death_event)
end
end

Expand Down Expand Up @@ -147,6 +147,10 @@ local function get_target()
return selected_item.hist_figure_id, df.unit.find(selected_item.unit_id)
end

if dfhack_flags.module then
return
end

local hist_figure_id, selected_unit = get_target()

if not hist_figure_id then
Expand All @@ -155,7 +159,7 @@ elseif hist_figure_id == -1 then
if not selected_unit then
qerror("Cause of death not available")
end
displayDeathUnit(selected_unit)
print(dfhack.df2console(displayDeathUnit(selected_unit)))
else
displayDeathHistFig(df.historical_figure.find(hist_figure_id))
print(dfhack.df2console(displayDeathHistFig(df.historical_figure.find(hist_figure_id))))
end