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>
This commit is contained in:
Forrest 2026-10-05 14:23:22 -04:00
parent aa50e97311
commit 1ab666e5e4
9 changed files with 178 additions and 37 deletions

View file

@ -111,6 +111,9 @@ var _hunt_cell: int = -1
var _hunt_wait: float = 0.0
var _rebuild_usec: int = 0
var _rebuild_ticks: int = 0
## Alien Goop's drop-on-kill roll (Decision 11): seeded like LootSystem's category RNG, for
## reproducible trials.
var _goop_rng := RandomNumberGenerator.new()
func _ready() -> void:
@ -178,6 +181,8 @@ func _ready() -> void:
push_warning("The pen holds %d animals but GameConfig.start_animals is %d" % [animals.count, config.start_animals])
enemies.enemy_removed.connect(loot.on_enemy_removed)
enemies.enemy_removed.connect(_count_removal)
_goop_rng.seed = 20261005
enemies.enemy_removed.connect(_drop_alien_goop)
projectiles = FarmProjectiles.new()
projectiles.name = "Shots"
add_child(projectiles)
@ -594,6 +599,22 @@ func _count_removal(handle: int, reason: EnemySystem.Removal, _x: float, _z: flo
campaign.state.record_event("escaped")
## Alien Goop (Decision 11): a killed Alien (the thief type, display-named "Alien") has a
## config-tunable chance to drop goop, credited like a gathered material straight into the
## pouch (respecting its capacity; a full pouch simply loses the drop, same as any overflow).
func _drop_alien_goop(handle: int, reason: EnemySystem.Removal, _x: float, _z: float, _carry: int, _target: int) -> void:
if reason != EnemySystem.Removal.KILLED:
return
var d := enemies.resolve_handle(handle)
if d < 0 or enemies.type[d] != EnemySystem.TYPE_THIEF:
return
if _goop_rng.randf() >= config.alien_goop_drop_chance:
return
var added := campaign.state.resources.add_to_pouch("alien_goop", config.alien_goop_drop_qty)
if added > 0:
campaign.state.record_event("gathered_alien_goop", added)
## Keeps the field toward the scarecrow fresh while anything is fighting it.
func _update_hunt(dt: float) -> void:
_hunt_wait = maxf(_hunt_wait - dt, 0.0)