A9: In-game HUD, with a FEED message for the kill feed and who stands

The HUD (src/client/hud) is drawn in the paper-and-ink motifs of the style
guide:
- top centre: the tide post, the most prominent thing on screen. It is a
  notched post with the sea filled in, the next level's rust notch and the
  player's own height. Beside it are the phase, the time to the rise, both
  levels and how far the player stands above or below the next line;
- top right: how many are standing, and the kill feed in words;
- bottom left: health and armour, each with a number, a word, quarter notches
  and its own hatching. Low health adds LOW;
- bottom centre: the boathook and five slots, with names on two lines, rounds
  and reserve or counts, and tier pips;
- bottom right: materials, and the build line ("NOT ENOUGH" when short).

Snapshots only carry nearby players, so the server now sends FEED (NetFeed,
reliable) when anyone is placed and at each phase change. It carries who is
standing, the match size and the newest 16 entries with names. Bots get crew
names (CrewNames). HudState works out what to show from the client, or from a
server's match for captures and tests, so the drawing never reaches into
either.

The project now stretches canvas items from a 1280x720 base, so the HUD scales
to any screen. make hud-captures renders it at 1280x720 and 3840x2160. The
parser fuzzer covers FEED.

Closes #49

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 09:01:36 -05:00
co-authored by Claude Opus 5.5
parent d7c8ed7e6e
commit 4993601616
20 changed files with 1009 additions and 9 deletions
+365
View File
@@ -0,0 +1,365 @@
## The in-game HUD (A9), in the paper-and-ink motifs of docs/STYLE.md: a painted tide
## post at top centre (the tide is the match's clock), who is standing and the kill feed
## at top right, health and armour at bottom left, the boathook and five slots at bottom
## centre, materials and build mode at bottom right.
##
## Laid out for a 1280x720 canvas; the project's canvas_items stretch scales it to any
## screen. Nothing relies on colour alone: health and armour carry numbers, words and
## different patterns, tiers are pips, and the tide's danger is a word and a notch.
## show_state() takes a HudState and draws only that.
class_name Hud
extends Control
const FONT_SMALL: int = 13
const FONT_BODY: int = 16
const FONT_TITLE: int = 22
const MARGIN: float = 18.0
var state: HudState = HudState.new()
var _tide: TidePost
var _standing: Label
var _feed: VBoxContainer
var _vitals: Vitals
var _hotbar: HBoxContainer
var _materials: VBoxContainer
var _build: Label
## When a feed line was first shown (msec), so lines fade after HudState.FEED_SECONDS.
var _feed_seen: Dictionary = {}
## Captures turn this off to keep every line of the feed.
var fade_feed: bool = true
func _init() -> void:
name = "Hud"
set_anchors_preset(Control.PRESET_FULL_RECT)
mouse_filter = Control.MOUSE_FILTER_IGNORE
_tide = TidePost.new()
_tide.set_anchors_preset(Control.PRESET_CENTER_TOP)
_tide.custom_minimum_size = Vector2(330.0, 104.0)
_tide.size = _tide.custom_minimum_size
_tide.position = Vector2(-165.0, MARGIN - 6.0)
add_child(_tide)
_standing = _label(FONT_TITLE, Palette.PAPER)
_standing.set_anchors_preset(Control.PRESET_TOP_RIGHT)
_standing.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
_standing.position = Vector2(-320.0 - MARGIN, MARGIN)
_standing.size = Vector2(320.0, 30.0)
add_child(_standing)
_feed = VBoxContainer.new()
_feed.set_anchors_preset(Control.PRESET_TOP_RIGHT)
_feed.position = Vector2(-380.0 - MARGIN, MARGIN + 36.0)
_feed.size = Vector2(380.0, 140.0)
_feed.alignment = BoxContainer.ALIGNMENT_BEGIN
_feed.add_theme_constant_override("separation", 2)
add_child(_feed)
_vitals = Vitals.new()
_vitals.set_anchors_preset(Control.PRESET_BOTTOM_LEFT)
_vitals.custom_minimum_size = Vector2(270.0, 76.0)
_vitals.size = _vitals.custom_minimum_size
_vitals.position = Vector2(MARGIN, -76.0 - MARGIN)
add_child(_vitals)
_hotbar = HBoxContainer.new()
_hotbar.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
_hotbar.add_theme_constant_override("separation", 6)
_hotbar.alignment = BoxContainer.ALIGNMENT_CENTER
_hotbar.size = Vector2(6.0 * 86.0 + 5.0 * 6.0, 84.0)
_hotbar.position = Vector2(-_hotbar.size.x * 0.5, -84.0 - MARGIN)
add_child(_hotbar)
_build = _label(FONT_BODY, Palette.PAPER)
_build.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
_build.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
_build.size = Vector2(520.0, 24.0)
_build.position = Vector2(-260.0, -84.0 - MARGIN - 30.0)
add_child(_build)
_materials = VBoxContainer.new()
_materials.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
_materials.size = Vector2(190.0, 84.0)
_materials.position = Vector2(-190.0 - MARGIN, -84.0 - MARGIN)
_materials.add_theme_constant_override("separation", 2)
add_child(_materials)
show_state(state)
## Shows `shown`, and nothing that isn't in it.
func show_state(shown: HudState) -> void:
state = shown
_tide.tide = shown.tide
_tide.visible = not shown.tide.is_empty()
_tide.queue_redraw()
_standing.visible = shown.total > 0
_standing.text = "%d of %d standing" % [shown.standing, shown.total]
var now: int = Time.get_ticks_msec()
var lines: Array[Dictionary] = []
for line: Dictionary in shown.feed:
var key: String = String(line["text"])
if not _feed_seen.has(key):
_feed_seen[key] = now
if fade_feed and now - int(_feed_seen[key]) > int(HudState.FEED_SECONDS * 1000.0):
continue
lines.append(line)
_fit_labels(_feed, lines.size(), HORIZONTAL_ALIGNMENT_RIGHT)
for index: int in lines.size():
var label: Label = _feed.get_child(index) as Label
label.text = String(lines[index]["text"])
label.add_theme_color_override("font_color", Palette.OILSKIN if lines[index]["you"] else Palette.PAPER)
if shown.feed.is_empty():
_feed_seen.clear()
_vitals.visible = shown.playing
_vitals.health = shown.health
_vitals.armor = shown.armor
_vitals.queue_redraw()
_hotbar.visible = shown.playing
while _hotbar.get_child_count() < shown.slots.size():
var box: SlotBox = SlotBox.new()
box.custom_minimum_size = Vector2(86.0, 84.0)
_hotbar.add_child(box)
for index: int in _hotbar.get_child_count():
var box: SlotBox = _hotbar.get_child(index) as SlotBox
box.visible = index < shown.slots.size()
if box.visible:
box.slot = shown.slots[index]
box.number = index
box.queue_redraw()
_materials.visible = shown.playing
_fit_labels(_materials, Materials.NAMES.size(), HORIZONTAL_ALIGNMENT_RIGHT)
for code: int in Materials.NAMES.size():
var count: int = shown.materials[code] if code < shown.materials.size() else 0
(_materials.get_child(code) as Label).text = "%s %d" % [Materials.NAMES[code].replace("_", " ").capitalize(), count]
_build.visible = shown.playing and not shown.build.is_empty()
if _build.visible:
var build: Dictionary = shown.build
_build.text = "BUILDING · %s in %s · costs %d%s" % [String(build["kind"]).capitalize(), String(build["material"]).replace("_", " "),
int(build["cost"]), "" if build["affordable"] else " · NOT ENOUGH"]
_build.add_theme_color_override("font_color", Palette.PAPER if build["affordable"] else Palette.WARNING)
## Keeps exactly `count` labels in `box`, adding or removing at the end.
func _fit_labels(box: BoxContainer, count: int, align: HorizontalAlignment) -> void:
while box.get_child_count() < count:
var label: Label = _label(FONT_BODY, Palette.PAPER)
label.horizontal_alignment = align
box.add_child(label)
while box.get_child_count() > count:
var last: Node = box.get_child(box.get_child_count() - 1)
box.remove_child(last)
last.free()
static func _label(font_size: int, colour: Color) -> Label:
var label: Label = Label.new()
label.add_theme_font_size_override("font_size", font_size)
label.add_theme_color_override("font_color", colour)
label.add_theme_color_override("font_outline_color", Palette.OUTLINE)
label.add_theme_constant_override("outline_size", 5)
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
return label
## A paper panel with an ink border and an offset ink shadow, like a printed card.
static func draw_card(item: CanvasItem, rect: Rect2, raised: bool = false) -> void:
item.draw_rect(Rect2(rect.position + Vector2(3.0, 3.0), rect.size), Color(Palette.INK, 0.55))
item.draw_rect(rect, Color(Palette.PAPER, 0.93))
item.draw_rect(rect, Palette.INK, false, 3.0 if raised else 1.5)
static func draw_text(item: CanvasItem, at: Vector2, text: String, font_size: int, colour: Color = Palette.INK,
width: float = -1.0, align: HorizontalAlignment = HORIZONTAL_ALIGNMENT_LEFT) -> void:
var font: Font = ThemeDB.fallback_font
item.draw_string(font, at, text, align, width, font_size, colour)
static func roman(value: int) -> String:
const NUMERALS: Array[String] = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"]
return NUMERALS[value] if value >= 0 and value < NUMERALS.size() else str(value)
## The tide post: a notched wooden post with the sea filled to its level, the next
## level's notch, and the player's own height, beside the phase and the time to the rise.
class TidePost:
extends Control
var tide: Dictionary = {}
func _init() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
func _draw() -> void:
if tide.is_empty():
return
var card: Rect2 = Rect2(Vector2.ZERO, size)
Hud.draw_card(self, card)
var sea: float = tide["sea"]
var next: float = tide["next"]
var feet: float = tide["feet"]
var low: float = floorf(sea - 3.0)
var high: float = maxf(next, sea) + 5.0
if not is_nan(feet):
high = maxf(high, minf(feet + 2.0, low + 40.0))
var post: Rect2 = Rect2(16.0, 10.0, 26.0, size.y - 20.0)
var to_y: Callable = func(level: float) -> float:
return post.end.y - clampf((level - low) / (high - low), 0.0, 1.0) * post.size.y
draw_rect(post, Palette.PLANK_BLEACHED)
# Water up to the sea, with a wave cut across its top.
var water_top: float = to_y.call(sea)
draw_rect(Rect2(post.position.x, water_top, post.size.x, post.end.y - water_top), Palette.SEA_INK)
var wave: PackedVector2Array = PackedVector2Array()
for step: int in 7:
wave.append(Vector2(post.position.x + post.size.x * step / 6.0, water_top + (2.5 if step % 2 == 0 else -2.5)))
draw_polyline(wave, Palette.PAPER, 1.5)
# Notches each metre, longer each five.
var metre: float = ceilf(low)
while metre <= high:
var y: float = to_y.call(metre)
var long: bool = int(metre) % 5 == 0
draw_line(Vector2(post.position.x, y), Vector2(post.position.x + (12.0 if long else 6.0), y), Palette.INK, 1.0)
metre += 1.0
draw_rect(post, Palette.INK, false, 1.5)
# The next level: a rust notch cut into both sides, with a dashed line across.
if next > sea + 0.05:
var next_y: float = to_y.call(next)
draw_dashed_line(Vector2(post.position.x - 6.0, next_y), Vector2(post.end.x + 6.0, next_y), Palette.WARNING, 2.0, 4.0)
draw_colored_polygon(PackedVector2Array([Vector2(post.position.x - 10.0, next_y - 5.0), Vector2(post.position.x - 2.0, next_y), Vector2(post.position.x - 10.0, next_y + 5.0)]), Palette.WARNING)
# The player's own height: a yellow pointer on the right of the post.
if not is_nan(feet):
var feet_y: float = to_y.call(feet)
draw_colored_polygon(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0)]), Palette.OILSKIN)
draw_polyline(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0), Vector2(post.end.x + 2.0, feet_y)]), Palette.INK, 1.0)
var x: float = post.end.x + 26.0
var width: float = size.x - x - 10.0
Hud.draw_text(self, Vector2(x, 30.0), "TIDE %s of %s" % [Hud.roman(int(tide["phase"])), Hud.roman(int(tide["phases"]))], Hud.FONT_TITLE)
var stage: int = tide["stage"]
var timing: String
match stage:
Tide.HOLD:
var seconds: int = ceili(float(tide["rise_in"]))
timing = "Rises in %d:%02d" % [seconds / 60, seconds % 60]
Tide.RISE:
timing = "RISING"
Tide.SUDDEN_DEATH:
timing = "HIGH WATER · last land"
_:
timing = "Slack water"
Hud.draw_text(self, Vector2(x, 54.0), timing, Hud.FONT_BODY, Palette.WARNING if stage != Tide.HOLD else Palette.INK, width)
Hud.draw_text(self, Vector2(x, 74.0), "Sea %.1f m · next %.1f m" % [sea, next], Hud.FONT_SMALL, Palette.INK, width)
if not is_nan(feet):
var above: float = feet - next
var line: String = "You: %.1f m above the next line" % above if above >= 0.0 else "You: %.1f m BELOW the next line" % -above
Hud.draw_text(self, Vector2(x, 92.0), line, Hud.FONT_SMALL, Palette.INK if above >= 0.0 else Palette.WARNING, width)
## Health and armour bars: each a number, a word, notches every quarter and its own
## pattern, so they read without colour. Low health adds LOW and rust hatching.
class Vitals:
extends Control
var health: int = 0
var armor: int = 0
func _init() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
func _draw() -> void:
Hud.draw_card(self, Rect2(Vector2.ZERO, size))
_bar(Rect2(76.0, 12.0, size.x - 88.0, 22.0), "HEALTH", health, Tuning.PLAYER_MAX_HEALTH, false)
_bar(Rect2(76.0, 44.0, size.x - 88.0, 18.0), "ARMOUR", armor, Tuning.PLAYER_MAX_ARMOR, true)
func _bar(rect: Rect2, word: String, value: int, most: int, striped: bool) -> void:
var low: bool = not striped and value <= most / 4
Hud.draw_text(self, Vector2(10.0, rect.position.y + rect.size.y * 0.5 + 5.0), word, Hud.FONT_SMALL)
draw_rect(rect, Color(Palette.INK, 0.15))
var filled: Rect2 = Rect2(rect.position, Vector2(rect.size.x * clampf(float(value) / most, 0.0, 1.0), rect.size.y))
var fill: Color = Palette.WARNING if low else (Palette.SEA_PAINT if striped else Palette.OCHRE_RED.lerp(Palette.TAR, 0.1))
draw_rect(filled, fill)
if striped or low:
# Armour is hatched one way; low health the other.
var step: float = 6.0
var x: float = filled.position.x - filled.size.y
while x < filled.end.x:
var a: Vector2 = Vector2(x, filled.end.y) if striped else Vector2(x, filled.position.y)
var b: Vector2 = Vector2(x + filled.size.y, filled.position.y) if striped else Vector2(x + filled.size.y, filled.end.y)
var clipped: PackedVector2Array = _clip(a, b, filled)
if clipped.size() == 2:
draw_line(clipped[0], clipped[1], Color(Palette.INK, 0.45), 1.5)
x += step
for quarter: int in range(1, 4):
var qx: float = rect.position.x + rect.size.x * quarter / 4.0
draw_line(Vector2(qx, rect.position.y), Vector2(qx, rect.position.y + 5.0), Palette.INK, 1.0)
draw_rect(rect, Palette.INK, false, 1.5)
var text: String = "%d%s" % [value, " LOW" if low else ""]
Hud.draw_text(self, Vector2(rect.position.x + 6.0, rect.position.y + rect.size.y * 0.5 + 5.0), text, Hud.FONT_BODY,
Palette.PAPER if value > most / 3 else Palette.INK)
static func _clip(a: Vector2, b: Vector2, rect: Rect2) -> PackedVector2Array:
# Clips the segment to the rect's x range (the y range always fits).
var from: Vector2 = a
var to: Vector2 = b
if to.x < rect.position.x or from.x > rect.end.x:
return PackedVector2Array()
if from.x < rect.position.x:
from = from.lerp(to, (rect.position.x - from.x) / (to.x - from.x))
if to.x > rect.end.x:
to = from.lerp(to, (rect.end.x - from.x) / (to.x - from.x))
return PackedVector2Array([from, to])
## One hotbar slot: its key number, the item's name, count or rounds, and tier pips.
## The held one is raised, has a heavier border and an oilskin band.
class SlotBox:
extends Control
var slot: Dictionary = {}
var number: int = 0
func _init() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
func _draw() -> void:
var selected: bool = bool(slot.get("selected", false))
var rect: Rect2 = Rect2(Vector2(0.0, 0.0 if selected else 8.0), size - Vector2(0.0, 8.0))
if bool(slot.get("empty", true)):
draw_rect(rect, Color(Palette.INK, 0.35))
draw_rect(rect, Color(Palette.PAPER_DIM, 0.8), false, 1.0)
Hud.draw_text(self, rect.position + Vector2(6.0, 16.0), str(number), Hud.FONT_SMALL, Palette.PAPER_DIM)
return
Hud.draw_card(self, rect, selected)
if selected:
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.OILSKIN)
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.INK, false, 1.0)
Hud.draw_text(self, rect.position + Vector2(5.0, 15.0), str(number), Hud.FONT_SMALL - 2, Palette.INK)
# The name on up to two lines, split between words, so nothing is cut off.
var words: PackedStringArray = String(slot.get("name", "")).split(" ")
var first: String = words[0] if words.size() > 0 else ""
var rest: String = " ".join(words.slice(1)) if words.size() > 1 else ""
var width: float = rect.size.x - 8.0
Hud.draw_text(self, rect.position + Vector2(4.0, 31.0), first, Hud.FONT_SMALL, Palette.INK, width, HORIZONTAL_ALIGNMENT_CENTER)
if not rest.is_empty():
Hud.draw_text(self, rect.position + Vector2(4.0, 45.0), rest, Hud.FONT_SMALL, Palette.INK, width, HORIZONTAL_ALIGNMENT_CENTER)
var amount: String = ""
if int(slot.get("rounds", -1)) >= 0:
amount = "%d | %d" % [int(slot["rounds"]), int(slot["reserve"])]
elif int(slot.get("count", 0)) > 1:
amount = "x%d" % int(slot["count"])
if not amount.is_empty():
Hud.draw_text(self, rect.position + Vector2(4.0, 60.0), amount, Hud.FONT_SMALL, Palette.INK, width, HORIZONTAL_ALIGNMENT_CENTER)
var tier: int = int(slot.get("tier", -1))
if tier >= 0:
# Pips: filled up to the tier, out of four, so tier reads without colour.
for pip: int in Tuning.WEAPON_TIERS.size():
var centre: Vector2 = rect.position + Vector2(rect.size.x * 0.5 + (pip - 1.5) * 11.0, rect.size.y - 7.0)
if pip <= tier:
draw_circle(centre, 3.5, Palette.GILT if tier >= 2 else Palette.INK)
draw_arc(centre, 3.5, 0.0, TAU, 12, Palette.INK, 1.0)
+1
View File
@@ -0,0 +1 @@
uid://cic0qgduge4io
+155
View File
@@ -0,0 +1,155 @@
## What the HUD shows, as plain data: worked out from the client's game and input
## (from_client) or from a server's simulation and match (from_match, for captures and
## tests), so the HUD's drawing never reaches into either. See Hud.
class_name HudState
extends RefCounted
## Seconds a kill feed entry stays on screen.
const FEED_SECONDS: float = 9.0
const FEED_LINES: int = 5
## True while the player is in the match: vitals, hotbar and materials are shown.
var playing: bool = false
var health: int = 0
var armor: int = 0
## The boathook, then one per inventory slot: {"name", "count", "rounds", "reserve",
## "magazine", "tier" (-1 for no tier), "selected", "empty"}.
var slots: Array[Dictionary] = []
var materials: PackedInt32Array = PackedInt32Array([0, 0, 0])
## {} when not building, else {"kind", "material", "cost", "affordable"}.
var build: Dictionary = {}
## {} before the tide starts, else {"phase" (1-based), "phases", "stage" (Tide.HOLD...),
## "sea", "next", "rise_in" (seconds), "feet" (NAN when not standing anywhere)}.
var tide: Dictionary = {}
var standing: int = 0
var total: int = 0
## Lines for the kill feed, oldest first: {"text", "you"}.
var feed: Array[Dictionary] = []
## The HUD for a client: its own predicted player, the world's tide and the server's feed.
static func from_client(game: ClientGame, input: ClientInput, own_handle: int, feed_ages: Dictionary = {}) -> HudState:
var state: HudState = HudState.new()
state.standing = game.standing
state.total = game.match_size
state.feed = feed_lines(game.feed, own_handle)
if game.world != null and game.world.tide != null and game.match_phase != Match.LOBBY and game.match_phase != Match.COUNTDOWN:
var feet: float = NAN
if game.playing():
feet = game.own_position().y
state.tide = tide_of(game.world.tide, game.world.tick, feet)
if game.playing():
var me: SimEntity = game.prediction.player
var drawn: SimEntity = game.world.entities.find(me.id) if game.world != null else null
state.playing = true
state.health = drawn.health if drawn != null else me.health
state.armor = drawn.armor if drawn != null else me.armor
_fill_carried(state, me)
state.build = build_of(input.build_mode, input.build_kind, input.material, me.materials)
return state
## The HUD for `handle` in a server's match, as a client of theirs would see it.
static func from_match(flow: Match, handle: int, build_mode: bool = false, build_kind: int = StructureSet.WALL, material: int = Materials.DRIFTWOOD) -> HudState:
var state: HudState = HudState.new()
var sim: Simulation = flow.sim
var started: bool = flow.in_match() or flow.phase == Match.RESULTS
state.standing = flow.alive().size()
state.total = flow.participants.size() if started else 0
var entries: Array[Dictionary] = []
for record: Dictionary in flow.kill_feed:
var entry: Dictionary = record.duplicate()
entry["victim"] = record["handle"]
entry["victim_name"] = CrewNames.for_bot(int(record["handle"])) if int(record["handle"]) < 0 else "Player %d" % int(record["handle"])
entry["by_name"] = "" if int(record["by"]) == 0 else (CrewNames.for_bot(int(record["by"])) if int(record["by"]) < 0 else "Player %d" % int(record["by"]))
entries.append(entry)
state.feed = feed_lines(entries, handle)
var me: SimEntity = sim.entities.find(int(flow.entity_of.get(handle, 0)))
if sim.tide != null and started:
state.tide = tide_of(sim.tide, sim.tick, me.position.y if me != null and not me.eliminated else NAN)
if me != null and not me.eliminated and flow.in_match():
state.playing = true
state.health = me.health
state.armor = me.armor
_fill_carried(state, me)
state.build = build_of(build_mode, build_kind, material, me.materials)
return state
static func tide_of(tide: Tide, tick: int, feet: float) -> Dictionary:
return {
"phase": tide.phase_at(tick) + 1, "phases": Tide.phase_count(), "stage": tide.stage_at(tick),
"sea": tide.level_at(tick), "next": tide.forecast_at(tick),
"rise_in": float(tide.ticks_until_rise(tick)) / Tuning.TICK_RATE_HZ, "feet": feet,
}
static func build_of(on: bool, kind: int, material: int, carried: PackedInt32Array) -> Dictionary:
if not on:
return {}
var kinds: Array = Tuning.BUILD_PIECES.keys()
var kind_name: String = String(kinds[kind]) if kind >= 0 and kind < kinds.size() else "piece"
var cost: int = int(Tuning.BUILD_PIECES.get(kind_name, {}).get("cost", 0))
return {"kind": kind_name, "material": Materials.NAMES[material], "cost": cost,
"affordable": material < carried.size() and carried[material] >= cost}
## Kill feed entries as lines of words, naming `own_handle` "You". Only the newest
## FEED_LINES.
static func feed_lines(entries: Array[Dictionary], own_handle: int) -> Array[Dictionary]:
var lines: Array[Dictionary] = []
for index: int in range(maxi(0, entries.size() - FEED_LINES), entries.size()):
var entry: Dictionary = entries[index]
var victim_is_you: bool = int(entry.get("victim", 0)) == own_handle and own_handle != 0
var by_is_you: bool = int(entry.get("by", 0)) == own_handle and own_handle != 0
var victim: String = "You" if victim_is_you else String(entry.get("victim_name", "Someone"))
var by: String = "You" if by_is_you else String(entry.get("by_name", ""))
lines.append({"text": feed_text(victim, by, String(entry.get("cause", "none")), int(entry.get("item", -1)), victim_is_you), "you": victim_is_you or by_is_you})
return lines
static func feed_text(victim: String, by: String, cause: String, item: int, victim_is_you: bool) -> String:
var weapon: String = ""
if item >= 0 and item < ItemCatalog.count():
weapon = " with %s" % item_name(ItemCatalog.get_def(item).id).to_lower()
match cause:
"weapon":
if not by.is_empty() and by != victim:
return "%s took %s%s" % [by, "you" if victim_is_you else victim, weapon]
return "%s went down" % victim
"fall":
return "%s fell" % victim
"drown":
return "%s drowned" % victim
"tide":
return "The tide took %s" % ("you" if victim_is_you else victim)
"left":
return "%s left" % victim
return "%s is out" % victim
## "flintlock_pistol" -> "Flintlock Pistol".
static func item_name(id: String) -> String:
return id.replace("_", " ").capitalize()
static func _fill_carried(state: HudState, me: SimEntity) -> void:
state.materials = me.materials.duplicate()
# The boathook is always carried, before the slots; `selected` 0 holds it.
state.slots.append({"selected": me.selected == 0, "empty": false, "name": item_name(ItemCatalog.BOATHOOK),
"count": 1, "rounds": -1, "reserve": -1, "magazine": 0, "tier": -1, "tool": true})
for slot: int in me.slot_items.size():
var code: int = me.slot_items[slot]
var entry: Dictionary = {"selected": me.selected == slot + 1, "empty": code == Inventory.EMPTY,
"name": "", "count": 0, "rounds": -1, "reserve": -1, "magazine": 0, "tier": 0}
if code != Inventory.EMPTY:
var def: ItemDef = ItemCatalog.get_def(code)
entry["name"] = item_name(def.id)
entry["count"] = me.slot_counts[slot]
entry["tier"] = me.slot_tiers[slot] if def.is_weapon() else -1
if def.uses_magazine():
entry["rounds"] = me.slot_rounds[slot]
entry["magazine"] = def.magazine
var ammo: int = Inventory.ammo_index(def.ammo_code)
entry["reserve"] = me.ammo[ammo] if ammo >= 0 and ammo < me.ammo.size() else 0
state.slots.append(entry)
+1
View File
@@ -0,0 +1 @@
uid://by20dltxfwshu