Skip to content

Commit b86f9f0

Browse files
Update deathcause.lua
localize some more functions and then rename the APIs and add comments
1 parent d8203e4 commit b86f9f0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

deathcause.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ local function getDeathStringFromCause(cause)
2525
end
2626
end
2727

28-
function getDeathUnit(unit)
28+
-- Returns a cause of death given a unit
29+
function getDeathCauseFromUnit(unit)
2930
local str = unit.name.has_name and '' or 'The '
3031
str = str .. dfhack.units.getReadableName(unit)
3132

@@ -55,15 +56,15 @@ end
5556

5657
-- returns the item description if the item still exists; otherwise
5758
-- returns the weapon name
58-
function getWeaponName(item_id, subtype)
59+
local function getWeaponName(item_id, subtype)
5960
local item = df.item.find(item_id)
6061
if not item then
6162
return df.global.world.raws.itemdefs.weapons[subtype].name
6263
end
6364
return dfhack.items.getDescription(item, 0, false)
6465
end
6566

66-
function getDeathEventHistFigUnit(histfig_unit, event)
67+
local function getDeathEventHistFigUnit(histfig_unit, event)
6768
local str = ("The %s %s %s in year %d"):format(
6869
getRaceNameSingular(histfig_unit.race),
6970
dfhack.translation.translateName(dfhack.units.getVisibleName(histfig_unit)),
@@ -91,7 +92,7 @@ function getDeathEventHistFigUnit(histfig_unit, event)
9192
end
9293

9394
-- Returns the death event for the given histfig or nil if not found
94-
function getDeathEventForHistFig(histfig_id)
95+
local function getDeathEventForHistFig(histfig_id)
9596
for i = #df.global.world.history.events - 1, 0, -1 do
9697
local event = df.global.world.history.events[i]
9798
if event:getType() == df.history_event_type.HIST_FIGURE_DIED then
@@ -102,7 +103,8 @@ function getDeathEventForHistFig(histfig_id)
102103
end
103104
end
104105

105-
function getDeathHistFig(histfig)
106+
-- Returns the cause of death given a histfig
107+
function getDeathCauseFromHistFig(histfig)
106108
local histfig_unit = df.unit.find(histfig.unit_id)
107109
if not histfig_unit then
108110
qerror("Cause of death not available")
@@ -159,7 +161,7 @@ elseif hist_figure_id == -1 then
159161
if not selected_unit then
160162
qerror("Cause of death not available")
161163
end
162-
print(dfhack.df2console(getDeathUnit(selected_unit)))
164+
print(dfhack.df2console(getDeathCauseFromUnit(selected_unit)))
163165
else
164-
print(dfhack.df2console(getDeathHistFig(df.historical_figure.find(hist_figure_id))))
166+
print(dfhack.df2console(getDeathCauseFromHistFig(df.historical_figure.find(hist_figure_id))))
165167
end

0 commit comments

Comments
 (0)