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

Add a suffocation gui overlay as a module - ticks left until death #1174

Merged
merged 9 commits into from
Jul 3, 2024
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Template for new versions:
## New Features
- `buildingplan`: dimension tooltip is now displayed for constructions and buildings that are designated over an area, like bridges and farm plots
- `gui/notify`: new notification type: injured citizens; click to zoom to injured units; also displays a warning if your hospital is not functional (or if you have no hospital)
- `gui/notify`: new notification type: drowning and suffocation progress bars for adventure mode
- `prioritize`: new info panel on under-construction buildings showing if the construction job has been taken and by whom. click to zoom to builder; toggle high priority status for job if it's not yet taken and you need it to be built ASAP
- `gui/pathable`: new "Depot" mode that shows whether wagons can path to your trade depot
- `advtools`: automatically add a conversation option to "ask whereabouts of" for all your relationships (before, you could only ask whereabouts of people involved in rumors)
Expand Down
61 changes: 61 additions & 0 deletions internal/notify/notifications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,51 @@ local function get_stranded_message()
end
end

local function get_blood()
return dfhack.world.getAdventurer().body.blood_count
end

local function get_max_blood()
return dfhack.world.getAdventurer().body.blood_max
end

local function get_max_breath()
local adventurer = dfhack.world.getAdventurer()
local toughness = dfhack.units.getPhysicalAttrValue(adventurer, df.physical_attribute_type.TOUGHNESS)
local endurance = dfhack.units.getPhysicalAttrValue(adventurer, df.physical_attribute_type.ENDURANCE)
local base_ticks = 200

return math.floor((endurance + toughness) / 4) + base_ticks
end

local function get_breath()
return get_max_breath() - dfhack.world.getAdventurer().counters.suffocation
end

local function get_bar(fn, text, color)
if fn() then
local label_text = {}
local suffocation_pen = color
table.insert(label_text, {text = text, pen = suffocation_pen, width = 14})

local bar_width = 16
local percentage = get_breath() / get_max_breath()
local barstop = math.floor((bar_width * percentage) + 0.5)
for idx = 0, bar_width-1 do
local color = color
local char = 219
if idx >= barstop then
-- offset it to the hollow graphic
color = COLOR_DARKGRAY
char = 177
end
table.insert(label_text, { width = 1, tile={ch=char, fg=color}})
end
return label_text
end
return nil
end

-- the order of this list controls the order the notifications will appear in the overlay
NOTIFICATIONS_BY_IDX = {
{
Expand Down Expand Up @@ -445,6 +490,22 @@ NOTIFICATIONS_BY_IDX = {
dwarf_fn=curry(injured_units, for_injured, 'injured citizen'),
on_click=curry(zoom_to_next, for_injured),
},
{
name='suffocation_adv',
desc='Shows a suffocation bar when you are drowning or breathless.',
default=true,
critical=true,
adv_fn=curry(get_bar, function() return get_breath() < get_max_breath() end, "Suffocation!", COLOR_LIGHTCYAN),
on_click=nil,
},
{
name='bleeding_adv',
desc='Shows a bleeding bar when you are losing blood.',
default=true,
critical=true,
adv_fn=curry(get_bar, function() return get_blood() < get_max_blood() end, "Bloodloss!", COLOR_RED),
on_click=nil,
},
}

NOTIFICATIONS_BY_NAME = {}
Expand Down