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

@ -27,7 +27,8 @@ const EVENTS: Array[String] = [
"killed_crow", "killed_thief", "killed_breaker", "escaped",
"scarecrow_damage", "patches",
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
"gathered_wood", "gathered_scrap", "gathered_straw", "spent_wood", "spent_scrap", "spent_straw",
"gathered_wood", "gathered_scrap", "gathered_straw", "gathered_alien_goop",
"spent_wood", "spent_scrap", "spent_straw", "spent_alien_goop",
]
## The keys of a night_log entry: the night, crops and animals lost, then every EVENTS key.
const LOG_KEYS: Array[String] = [
@ -37,7 +38,8 @@ const LOG_KEYS: Array[String] = [
"killed_crow", "killed_thief", "killed_breaker", "escaped",
"scarecrow_damage", "patches",
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
"gathered_wood", "gathered_scrap", "gathered_straw", "spent_wood", "spent_scrap", "spent_straw",
"gathered_wood", "gathered_scrap", "gathered_straw", "gathered_alien_goop",
"spent_wood", "spent_scrap", "spent_straw", "spent_alien_goop",
]
## Current night (1-based). The morning, day, dusk, night, and dawn of a cycle all belong to it.
@ -119,7 +121,8 @@ static func create(cfg: GameConfig) -> FarmState:
s.crops_total = cfg.start_crops
s.animals_total = cfg.start_animals
s.resources.pouch_capacity = cfg.pouch_capacity
s.resources.shed = {"wood": cfg.start_wood, "scrap": cfg.start_scrap, "straw": cfg.start_straw}
s.resources.shed = {"wood": cfg.start_wood, "scrap": cfg.start_scrap, "straw": cfg.start_straw,
"alien_goop": cfg.start_alien_goop}
s.supplies_total = s.resources.shed_total()
for e in cfg.start_structures:
var t := String(e["type"])