harvest/game/scripts/resource_hud.gd
Forrest 1ab666e5e4 Task #4: Alien Goop resource and drop-on-kill from Aliens
Add alien_goop as a 4th ResourceStore material alongside wood/scrap/straw,
dropped only by killed Aliens (TYPE_THIEF) at a config-tunable rate/quantity
(GameConfig.alien_goop_drop_chance default 0.33, alien_goop_drop_qty default
1), credited straight into the pouch like a gathered material via a new
enemy_removed hook in FarmSim (seeded RNG for reproducible trials). It's
stealable from the shed through the existing most-stocked-material sack
mechanic once it outranks the others (ShedStock gets a placeholder front/
label spot for it, reusing the wood pile's proven-walkable spot; no new art).

ResourceStore.from_dict() now treats a shed/pouch entry missing a material
as 0 instead of rejecting it (old saves predate Alien Goop), and to_dict()
always fills in every material so round-trips are consistent regardless of
how the live dict was built; every method summing across MATERIALS reads
with get(m, 0) so a hand-built 3-key dict elsewhere doesn't error out.

New checks in test_economy.gd: _goop_persistence (retry discards goop
gained since the morning; the morning snapshot round-trips through JSON)
and _goop_drops (1000-kill statistical drop-rate check against config,
type restriction to Aliens only, pouch-capacity-respecting credit, and
shed-theft eligibility). Updated _state()'s and test_cycle.gd's hardcoded
3-key shed dicts for the new 4th material.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-05 14:23:22 -04:00

76 lines
2.3 KiB
GDScript

class_name ResourceHud
extends Control
## Top-right materials readout: what the supply shed holds, and what the scarecrow carries in
## its pouch (with its capacity). A line flashes when its numbers change.
var campaign: CampaignController
## Set by FarmSim: shows how many structures stand.
var structures: StructureSystem
var _shed: RichTextLabel
var _pouch: RichTextLabel
var _built: RichTextLabel
var _last_shed := ""
var _last_pouch := ""
var _flash_shed: float = 0.0
var _flash_pouch: float = 0.0
func setup(p_campaign: CampaignController) -> void:
campaign = p_campaign
func _ready() -> void:
set_anchors_preset(Control.PRESET_FULL_RECT)
mouse_filter = Control.MOUSE_FILTER_IGNORE
_shed = _line(20.0)
_pouch = _line(52.0)
_built = _line(84.0)
func _process(delta: float) -> void:
if campaign == null:
return
var r := campaign.state.resources
var shed := "Shed %s" % _amounts(r.shed)
var pouch := "Pouch %d/%d %s" % [r.pouch_total(), r.pouch_capacity, _amounts(r.pouch) if r.pouch_total() > 0 else "empty"]
if shed != _last_shed:
_last_shed = shed
_shed.text = shed
_flash_shed = 1.0
if pouch != _last_pouch:
_last_pouch = pouch
_pouch.text = pouch
_flash_pouch = 1.0
_flash_shed = maxf(_flash_shed - delta * 2.0, 0.0)
_flash_pouch = maxf(_flash_pouch - delta * 2.0, 0.0)
if structures != null:
_built.text = "Built %d structures [B] build" % structures.count()
_shed.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_shed)
_pouch.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_pouch)
func _amounts(d: Dictionary) -> String:
var parts: Array[String] = []
for m in ResourceStore.MATERIALS:
parts.append("[color=#%s]%s %d[/color]" % [GatherNode.COLORS[m].to_html(false), m.capitalize(), int(d.get(m, 0))])
return " ".join(parts)
func _line(y: float) -> RichTextLabel:
var l := RichTextLabel.new()
l.bbcode_enabled = true
l.fit_content = true
l.scroll_active = false
l.autowrap_mode = TextServer.AUTOWRAP_OFF
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
l.add_theme_font_size_override("normal_font_size", 22)
l.add_theme_color_override("font_outline_color", Color.BLACK)
l.add_theme_constant_override("outline_size", 6)
l.set_anchors_preset(Control.PRESET_TOP_RIGHT)
l.offset_left = -520.0
l.offset_right = -24.0
l.offset_top = y
add_child(l)
return l