harvest/game/tests/test_economy.gd
Forrest 962c7b0b93 #46: sprint becomes a permanent speed upgrade
Owning the Sprint upgrade now multiplies the scarecrow's speed by
sprint_speed_mult (1.25) all the time, walking and running, on every
platform; the run clip speeds up to match. The hold-to-sprint burst is
gone: sprint_time, sprint_cooldown, the stamina state in PlayerCharacter
(can_sprint is now has_sprint), and the HUD's stamina bar. The upgrade
keeps its id, cost, and name; its text is "Run 25% faster, always".
The sprint input action stays in project.godot, unused.

Tests: test_scarecrow's sprint checks cover 1x without it, x1.25 with it
(run and walk, clip speed, network strength), 30 s with no time limit,
no cooldown, the next morning, and no platform dependence; test_nights
checks it after the retry and a loaded save; test_economy checks the
text matches the multiplier, the menu row, and that an old save's
{"sprint": 1} still owns it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 14:32:39 -04:00

849 lines
47 KiB
GDScript

extends RefCounted
## The resource economy: ResourceStore rules (pouch capacity, deposit, paying pouch first then
## shed, all-or-nothing, validation), FarmState keeping materials, gather points, and upgrades
## through JSON, and on the real farm (FarmSim stepped by hand): the gather points' layout,
## gathering by day only (charges, rooted, cancelled by letting go / a hit / fear, a full pouch,
## nightfall), the shed drop-off, overnight regrowth, retry restoring the morning's materials,
## patching's straw cost, buying the Straw Stuffing upgrade from the workbench's menu, Alien
## Goop (#4): dropped only by killed Aliens (thieves) at a config-tunable rate, credited like a
## gathered material, stealable from the shed once it's the stock on top, and surviving retry,
## and hidden/reveal shop items (#5): an item flagged "hidden" shows only "?" and can't be bought
## until enough Alien Goop has been collected in total, then shows and buys normally; and the
## supply shed's own shop (#6): weapons (corn_shooter, pumpkin_bomb) bought at its counter
## (ShedCounter), not the workbench, with the walk-in pouch deposit unaffected. And a pouch per
## scarecrow (#16): filled, deposited, and spent from by its own avatar slot, one shared capacity.
## And upgrade levels and timed shed stock (#26, _tiers and _stock). And the HUD's backpack and
## pouch panel (ResourceHud).
const P := CampaignController.Phase
const DT := 1.0 / 60.0
const TIERS_SAVE := "user://test_economy_tiers.json"
func run(r: GameTestRunner) -> void:
_store(r)
_pouches(r)
_state(r)
_goop_persistence(r)
_pouch_upgrade(r)
await _hidden_items(r)
await _tiers(r)
await _stock(r)
await _unlock_all(r)
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
r.root.add_child(farm)
await r.process_frame
await r.physics_frame
var sim := farm.get_node("FarmSim") as FarmSim
sim.set_physics_process(false)
sim.waves.enabled = false
var player := farm.get_node("Player") as PlayerCharacter
_layout(r, sim)
_pouch_hud(r, farm, sim)
_gathering(r, sim, player)
_deposit_and_night(r, sim, player)
_patch_cost(r, sim)
_stuffing(r, sim, player)
_shed_shop(r, sim, player)
_goop_drops(r, sim)
farm.queue_free()
await r.process_frame
func _store(r: GameTestRunner) -> void:
var s := ResourceStore.new()
r.check(s.add_to_pouch("wood", 10) == 10 and s.add_to_pouch("straw", 10) == 5 and s.pouch_total() == 15 and s.pouch_room() == 0,
"the pouch takes only what fits (15 units across materials)")
var moved := s.deposit()
r.check(moved == {"wood": 10, "straw": 5} and s.pouch_total() == 0 and s.shed["wood"] == 10, "deposit moves the whole pouch into the shed")
s = ResourceStore.new()
s.shed["wood"] = 3
s.pouch["wood"] = 2
r.check(s.available("wood") == 5 and s.pay({"wood": 4}) and s.pouch["wood"] == 0 and s.shed["wood"] == 1,
"costs are paid from the pouch first, then the shed")
r.check(not s.pay({"wood": 2}) and s.shed["wood"] == 1 and s.missing({"wood": 2}) == {"wood": 1},
"a cost that can't be met pays nothing and says what's missing")
s.shed["straw"] = 5
r.check(not s.pay({"straw": 1, "scrap": 3}) and s.shed["straw"] == 5, "a cost is all-or-nothing across materials")
r.check(ResourceStore.describe({"straw": 2, "wood": 6}) == "6 wood, 2 straw", "costs read in material order")
s.pouch["scrap"] = 4
var back := ResourceStore.from_dict(JSON.parse_string(JSON.stringify(s.to_dict())))
r.check(back != null and back.to_dict() == s.to_dict(), "the store round-trips through JSON")
var bad := {
"a negative amount": func(d: Dictionary) -> void: d["shed"]["wood"] = -1,
"an unknown material": func(d: Dictionary) -> void: d["pouch"]["gold"] = 1,
"an overfull pouch": func(d: Dictionary) -> void: d["pouch"]["wood"] = 99,
"an overfull partner pouch": func(d: Dictionary) -> void: d["partner_pouch"]["wood"] = 99,
"a missing part": func(d: Dictionary) -> void: d.erase("shed"),
"a missing partner pouch": func(d: Dictionary) -> void: d.erase("partner_pouch"),
}
for label: String in bad:
var d := s.to_dict()
d["shed"] = (d["shed"] as Dictionary).duplicate()
d["pouch"] = (d["pouch"] as Dictionary).duplicate()
(bad[label] as Callable).call(d)
r.check(ResourceStore.from_dict(d) == null, "the store rejects %s" % label)
## #16: a pouch per scarecrow (avatar slot; 0 is player 1, the default), sharing one capacity.
## Each fills, deposits, and pays from its own; the shed is shared.
func _pouches(r: GameTestRunner) -> void:
var s := ResourceStore.new()
s.pouch_capacity = 10
r.check(s.add_to_pouch("wood", 6, 1) == 6 and s.pouch_total(1) == 6 and s.pouch_total() == 0
and s.pouch_room(1) == 4 and s.pouch_room() == 10, "player 2's pouch fills on its own; player 1's (the default) stays empty")
r.check(s.add_to_pouch("straw", 9, 1) == 4 and s.add_to_pouch("straw", 9) == 9,
"each pouch takes what fits in it, the same capacity for both")
var moved := s.deposit()
r.check(moved == {"straw": 9} and s.pouch_total() == 0 and s.pouch_total(1) == 10 and s.shed["straw"] == 9,
"depositing player 1's pouch leaves player 2's alone")
r.check(s.deposit(1) == {"wood": 6, "straw": 4} and s.pouch_total(1) == 0 and s.shed["wood"] == 6 and s.shed["straw"] == 13,
"player 2 deposits their own")
s.shed = {"wood": 1, "scrap": 0, "straw": 0, "alien_goop": 0}
s.pouch["wood"] = 3
s.pouch_of(1)["wood"] = 2
r.check(s.available("wood") == 4 and s.available("wood", 1) == 3 and s.missing({"wood": 4}, 1) == {"wood": 1}
and s.can_afford({"wood": 4}) and not s.can_afford({"wood": 4}, 1), "each can spend their own pouch and the shed, never the other's pouch")
r.check(not s.pay({"wood": 4}, 1) and s.pouch["wood"] == 3 and s.pouch_of(1)["wood"] == 2 and s.shed["wood"] == 1,
"a cost player 2 can't meet pays nothing (player 1's wood isn't touched)")
r.check(s.pay({"wood": 3}, 1) and s.pouch_of(1)["wood"] == 0 and s.shed["wood"] == 0 and s.pouch["wood"] == 3,
"player 2 pays from their own pouch first, then the shed")
r.check(is_same(s.pouch_of(5), s.pouch_of(1)) and is_same(s.pouch_of(-1), s.pouch), "an out-of-range slot reads as the nearest pouch")
s.pouch_of(1)["alien_goop"] = 2
var d := s.to_dict()
r.check(d["pouch"]["wood"] == 3 and d["partner_pouch"]["alien_goop"] == 2, "to_dict() keeps player 1's as pouch and player 2's as partner_pouch")
var back := ResourceStore.from_dict(JSON.parse_string(JSON.stringify(d)))
r.check(back != null and back.to_dict() == d and back.pouch_total(1) == 2, "both pouches round-trip through JSON")
func _state(r: GameTestRunner) -> void:
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
var s := FarmState.create(cfg)
r.check(s.resources.shed == {"wood": cfg.start_wood, "scrap": cfg.start_scrap, "straw": cfg.start_straw, "alien_goop": cfg.start_alien_goop}
and s.resources.pouch_capacity == cfg.pouch_capacity, "a new farm starts with the configured stock and pouch size (Alien Goop a 4th material, starting at 0)")
s.resources.add_to_pouch("scrap", 3)
s.resources.add_to_pouch("alien_goop", 2)
s.gather_charges = {"Snag": 1, "Wreck": 0}
s.upgrades = {"straw_stuffing": 1}
var d := s.to_dict()
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(d)))
r.check(back != null and back.to_dict() == d, "FarmState keeps materials (including Alien Goop), used gather points, and upgrades through JSON")
d["gather_charges"] = {"Snag": -2}
r.check(FarmState.from_dict(d) == null, "FarmState rejects negative gather charges")
## Alien Goop round-trips like the other materials: a retry discards what was gained since the
## morning (same mechanic _deposit_and_night checks for wood/scrap below), and the morning
## snapshot itself (what SaveGame writes) survives a JSON round-trip.
func _goop_persistence(r: GameTestRunner) -> void:
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
var c := r.make_campaign(cfg)
var morning := c.state.to_dict()
c.begin_day()
c.state.resources.add_to_pouch("alien_goop", 5)
c.state.resources.shed["alien_goop"] = 3
c.advance_phase() # DAY -> DUSK
c.advance_phase() # DUSK -> NIGHT
c.retry_night()
r.check(c.state.phase == P.MORNING and c.state.resources.to_dict() == morning["resources"],
"a retry discards Alien Goop gained since the morning, same as the other materials")
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(morning)))
r.check(back != null and back.resources.shed.get("alien_goop", -1) == 0, "the morning snapshot (what's saved) round-trips Alien Goop through JSON")
## Pouch capacity (#3): a flat 16 is now a base of 8, raised to 16 by the Bigger pouch upgrade
## (bought once at the workbench, like straw_stuffing raises scarecrow_max_hp). The upgrade writes
## straight to the live ResourceStore value (FarmState.create() only seeds it from GameConfig at
## the start of a vacation), so like scarecrow_max_hp it carries into the next morning (FarmState's
## "resources" field round-trips through JSON) and survives a save and a retry from a morning on
## or after the day it was bought.
func _pouch_upgrade(r: GameTestRunner) -> void:
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig
var c := r.make_campaign(cfg)
var s := c.state
r.check(cfg.pouch_capacity == 8 and s.resources.pouch_capacity == 8, "the pouch starts at the base 8 units")
c.begin_day()
s.resources.shed = cfg.costs["pouch_upgrade"].duplicate()
var msg := Upgrades.buy(c, "pouch_upgrade")
r.check(Upgrades.owned(s, "pouch_upgrade") and msg.contains("done:") and s.resources.pouch_capacity == 16,
"Bigger pouch raises capacity from 8 to 16 (%s)" % msg)
r.check(s.resources.pouch_room(0) == 16 and s.resources.pouch_room(1) == 16, "for both scarecrows' pouches (#16: one shared capacity)")
r.check(s.resources.shed_total() == 0, "it costs the configured materials")
r.check(Upgrades.buy(c, "pouch_upgrade").contains("level 2 opens on day 8") and s.resources.pouch_capacity == 16,
"its next level waits for day 8")
# It carries into the next morning (same mechanic as straw_stuffing/scarecrow_max_hp).
while s.phase != P.MORNING:
c.advance_phase()
r.check(s.resources.pouch_capacity == 16, "the bigger pouch carries into the next morning")
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(s.to_dict())))
r.check(back != null and back.resources.pouch_capacity == 16, "and through a save")
# And a retry from that (later) morning keeps it, same as the upgrades dict itself.
c.begin_day()
c.advance_phase() # DAY -> DUSK
c.advance_phase() # DUSK -> NIGHT
r.check(c.retry_night() and c.state.resources.pouch_capacity == 16, "a retry from that morning keeps the bigger pouch")
## Hidden shop items (#5): an item definition can set "hidden": true (optionally its own
## "reveal_goop", else GameConfig.hidden_reveal_goop) so the workbench shows only a bare "?" (no
## name, text, or cost) and refuses the purchase (blocker()/buy(), so this also covers the co-op
## buy-request path) until Upgrades.goop_collected() reaches the threshold; then it shows and buys
## normally for its defined cost. No real upgrade ships hidden yet (#7/#8 will add Alien Ray and
## Radar), so this flags a duplicated long_range/sticky_tar to exercise the mechanism.
func _hidden_items(r: GameTestRunner) -> void:
var seed_cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig
var c := r.make_campaign(seed_cfg)
var cfg := c.config # what blocker()/buy()/refresh() actually read (CampaignController._ready duplicates it)
cfg.upgrades = cfg.upgrades.duplicate(true)
cfg.upgrades["long_range"] = cfg.upgrades["long_range"].duplicate(true)
cfg.upgrades["long_range"]["hidden"] = true
cfg.hidden_reveal_goop = 5
var s := c.state
c.begin_day()
s.resources.shed = cfg.costs["long_range"].duplicate()
r.check(Upgrades.goop_collected(s) == 0 and not Upgrades.revealed(s, cfg, "long_range"),
"a hidden item starts undiscovered (0 Alien Goop collected)")
r.check(Upgrades.blocker(c, "long_range") == "Not discovered yet", "its blocker reason doesn't describe it")
r.check(Upgrades.buy(c, "long_range") == "Long-range defenses: not discovered yet" and not Upgrades.owned(s, "long_range"),
"buy() refuses a hidden item below threshold too (also covers the co-op buy-request path)")
var panel := UpgradePanel.new()
r.root.add_child(panel)
await r.process_frame
panel.setup(c, null, null)
panel.refresh()
var row := panel._rows["long_range"] as Button
r.check(row.text == "?" and row.disabled, "the panel shows a bare '?' for a hidden item, disabled")
s.record_event("gathered_alien_goop", 4)
r.check(Upgrades.goop_collected(s) == 4 and not Upgrades.revealed(s, cfg, "long_range"), "still hidden one goop short of the threshold")
panel.refresh()
r.check(row.text == "?", "still just '?' one goop short")
s.record_event("gathered_alien_goop", 1)
r.check(Upgrades.goop_collected(s) == 5 and Upgrades.revealed(s, cfg, "long_range"), "revealed once goop collected reaches the threshold")
r.check(Upgrades.blocker(c, "long_range") == "", "no longer blocked once revealed (affordable, daytime)")
panel.refresh()
r.check(row.text.contains("Long-range defenses") and row.text.contains("Turrets reach 30% farther") and not row.disabled,
"the panel shows the normal name/text/cost once revealed: '%s'" % row.text)
var msg := Upgrades.buy(c, "long_range")
r.check(Upgrades.owned(s, "long_range") and msg.contains("done:"), "revealed, it buys normally for its defined cost")
panel.queue_free()
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(s.to_dict())))
r.check(back != null and Upgrades.revealed(back, cfg, "long_range") and Upgrades.owned(back, "long_range"),
"reveal and ownership both survive a save (JSON) round-trip")
# A second item, with its own reveal_goop: a completed night's goop (night_log, via totals())
# and the current cycle's own (night_events) both count toward it, and a retry (which restores
# the morning snapshot) drops only the failed night's own, keeping the completed night's.
cfg.upgrades["sticky_tar"] = cfg.upgrades["sticky_tar"].duplicate(true)
cfg.upgrades["sticky_tar"]["hidden"] = true
cfg.upgrades["sticky_tar"]["reveal_goop"] = 3
s.night_events.clear() # isolate night 1's remaining goop from the 5 already recorded above
s.record_event("gathered_alien_goop", 2)
c.advance_phase() # DAY -> DUSK
c.advance_phase() # DUSK -> NIGHT
c.advance_phase() # NIGHT -> DAWN
c.advance_phase() # DAWN -> MORNING of night 2 (closes night 1's log; night_events clears)
r.check(Upgrades.goop_collected(s) == 2 and not Upgrades.revealed(s, cfg, "sticky_tar"),
"a completed night's goop (night_log, via totals()) counts toward a different item's own reveal_goop threshold")
s.record_event("gathered_alien_goop", 1)
r.check(Upgrades.revealed(s, cfg, "sticky_tar"), "the current cycle's own goop (night_events) also counts, revealing it")
var retry_ok := c.retry_night()
r.check(retry_ok and not Upgrades.revealed(c.state, cfg, "sticky_tar") and Upgrades.goop_collected(c.state) == 2,
"a retry (restoring the morning snapshot) drops the failed night's own goop, un-revealing it, but keeps the earlier completed night's")
## Upgrade levels (#26): the workbench's stat upgrades have 3 levels; Sprint, the weapons, and
## Radar one. Level L costs costs[id] x upgrade_cost_growth^(L - 1), each material rounded up,
## and opens on day upgrade_level_days[L - 1] (8 for level 2, 16 for level 3). Each buy() takes
## one level, and every owned level's effect applies (heavy seeds: 2, 3, 4 damage; rapid fire's
## multipliers multiply). upgrades_bought counts every level. The menu names the next level
## ("Heavy seeds II") with its text and cost, says when it opens, and shows "Max" at the end.
## Levels survive a save, the next morning, and a retry, and an old save's {"rapid_fire": 1}
## loads as level 1. Sprint (#46) is a speed upgrade now: its text names sprint_speed_mult, the
## menu offers it as that, and an old save's {"sprint": 1} still owns it (the id is unchanged).
func _tiers(r: GameTestRunner) -> void:
var c := r.make_campaign((load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig)
var cfg := c.config
var s := c.state
var tiered := 0
for id: String in cfg.upgrades:
if Upgrades.max_level(cfg, id) == 3:
tiered += 1
r.check(tiered == 9 and Upgrades.max_level(cfg, "sprint") == 1 and Upgrades.max_level(cfg, "corn_shooter") == 1
and Upgrades.max_level(cfg, "alien_ray") == 1 and Upgrades.max_level(cfg, "radar") == 1,
"the nine stat upgrades have 3 levels; Sprint, the weapons, and Radar one (%d with 3)" % tiered)
var defaults := GameConfig.new()
var says := "Run %d%% faster, always"
r.check(Upgrades.text_at(cfg, "sprint", 1) == says % roundi((cfg.sprint_speed_mult - 1.0) * 100.0)
and Upgrades.text_at(defaults, "sprint", 1) == says % roundi((defaults.sprint_speed_mult - 1.0) * 100.0),
"Sprint says what it does: '%s' (x%.2f; game_config.gd's defaults agree)" % [Upgrades.text_at(cfg, "sprint", 1), cfg.sprint_speed_mult])
# Costs grow.
var grows := true
for id: String in cfg.upgrades:
var base := Upgrades.cost(cfg, id, 1)
grows = grows and base == cfg.costs.get(id, {})
for m in base:
var l2 := int(Upgrades.cost(cfg, id, 2)[m])
var l3 := int(Upgrades.cost(cfg, id, 3)[m])
grows = grows and l2 == ceili(int(base[m]) * cfg.upgrade_cost_growth - 0.0001) and l3 == ceili(int(base[m]) * pow(cfg.upgrade_cost_growth, 2) - 0.0001)
grows = grows and int(base[m]) < l2 and l2 < l3
r.check(grows, "level 1 costs costs[id]; each next level %.1fx the one before, each material rounded up" % cfg.upgrade_cost_growth)
var keep: Dictionary = cfg.costs["heavy_seeds"]
cfg.costs["heavy_seeds"] = {"scrap": 10, "straw": 25}
r.check(Upgrades.cost(cfg, "heavy_seeds", 2) == {"scrap": 18, "straw": 45} and Upgrades.cost(cfg, "heavy_seeds", 3) == {"scrap": 33, "straw": 81},
"e.g. 10 scrap, 25 straw: then 18, 45; then 33 (32.4 rounded up), 81 (not 82 from 25 x 3.24's float error)")
cfg.costs["heavy_seeds"] = keep
# Day gates and stacking effects, in the menu too.
var panel := UpgradePanel.new()
r.root.add_child(panel)
await r.process_frame
panel.setup(c, null, null)
c.begin_day()
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999, "alien_goop": 0}
s.upgrades["corn_shooter"] = 1
panel.refresh()
var row := panel._rows["heavy_seeds"] as Button
r.check(row.text == "Heavy seeds I — Each kernel does 2 damage (%s)" % ResourceStore.describe(Upgrades.cost(cfg, "heavy_seeds", 1)) and not row.disabled,
"the menu offers level I: '%s'" % row.text)
var sprint_row := panel._rows["sprint"] as Button
r.check(sprint_row.text == "Sprint — %s (%s)" % [Upgrades.text_at(cfg, "sprint", 1), ResourceStore.describe(Upgrades.cost(cfg, "sprint", 1))]
and not sprint_row.disabled, "the menu offers Sprint as the speed upgrade: '%s'" % sprint_row.text)
var damage := cfg.shot_damage
r.check(Upgrades.buy(c, "heavy_seeds").contains("done:") and Upgrades.level(s, "heavy_seeds") == 1
and roundi(Upgrades.value(cfg, s, "shot_damage")) == damage + 1, "level 1 on day 1: kernels do %d damage" % (damage + 1))
r.check(Upgrades.blocker(c, "heavy_seeds") == "Level 2 opens on day 8" and Upgrades.buy(c, "heavy_seeds") == "Heavy seeds: level 2 opens on day 8"
and Upgrades.level(s, "heavy_seeds") == 1, "level 2 can't be bought before day 8")
panel.refresh()
r.check(row.disabled and row.text.begins_with("Heavy seeds II — Each kernel does 3 damage (%s)" % ResourceStore.describe(Upgrades.cost(cfg, "heavy_seeds", 2)))
and row.text.ends_with("Level 2 opens on day 8"), "the menu shows level II, its cost, and when it opens: '%s'" % row.text)
s.night = 7
r.check(Upgrades.blocker(c, "heavy_seeds") == "Level 2 opens on day 8", "(not on day 7 either)")
s.night = 8
var shed := s.resources.shed.duplicate()
var l2 := Upgrades.cost(cfg, "heavy_seeds", 2)
var msg := Upgrades.buy(c, "heavy_seeds")
var paid := true
for m in l2:
paid = paid and int(shed[m]) - int(s.resources.shed[m]) == int(l2[m])
r.check(msg == "Heavy seeds II done: each kernel does 3 damage" and Upgrades.level(s, "heavy_seeds") == 2 and paid
and roundi(Upgrades.value(cfg, s, "shot_damage")) == damage + 2, "on day 8, level 2 for %s: kernels do %d ('%s')" % [ResourceStore.describe(l2), damage + 2, msg])
r.check(Upgrades.blocker(c, "heavy_seeds") == "Level 3 opens on day 16", "level 3 waits for day 16")
s.night = 16
r.check(Upgrades.buy(c, "heavy_seeds").contains("done:") and Upgrades.level(s, "heavy_seeds") == 3
and roundi(Upgrades.value(cfg, s, "shot_damage")) == damage + 3, "on day 16, level 3: kernels do %d" % (damage + 3))
r.check(Upgrades.blocker(c, "heavy_seeds") == "Done" and Upgrades.buy(c, "heavy_seeds") == "Heavy seeds: already done"
and Upgrades.level(s, "heavy_seeds") == 3, "and that's the last")
panel.refresh()
r.check(row.disabled and row.text == "Heavy seeds III — Each kernel does 4 damage (Max)", "the menu says Max: '%s'" % row.text)
var mult: Variant = cfg.upgrades["rapid_fire"]["mult"]
Upgrades.buy(c, "rapid_fire")
Upgrades.buy(c, "rapid_fire")
var rate := cfg.fire_rate * Upgrades.per_level(mult, 1) * Upgrades.per_level(mult, 2)
r.check(Upgrades.level(s, "rapid_fire") == 2 and is_equal_approx(Upgrades.value(cfg, s, "fire_rate"), rate),
"rapid fire's levels multiply: level 2 fires %.2f a second (%.2f x %.2f x %.2f)" % [Upgrades.value(cfg, s, "fire_rate"), cfg.fire_rate,
Upgrades.per_level(mult, 1), Upgrades.per_level(mult, 2)])
var hp := s.scarecrow_max_hp
var cap := s.resources.pouch_capacity
var stuffing := 0
var pouch := 0
for lvl in [1, 2, 3]:
Upgrades.buy(c, "straw_stuffing")
Upgrades.buy(c, "pouch_upgrade")
stuffing += roundi(Upgrades.per_level(cfg.upgrades["straw_stuffing"]["add"], lvl))
pouch += roundi(Upgrades.per_level(cfg.upgrades["pouch_upgrade"]["add"], lvl))
r.check(Upgrades.level(s, "straw_stuffing") == 3 and s.scarecrow_max_hp == hp + stuffing and s.scarecrow_hp == s.scarecrow_max_hp,
"three levels of straw stuffing: +%d max health" % stuffing)
r.check(Upgrades.level(s, "pouch_upgrade") == 3 and s.resources.pouch_capacity == cap + pouch, "three levels of the bigger pouch: %d units" % s.resources.pouch_capacity)
r.check(int(s.night_events.get("upgrades_bought", 0)) == 11, "upgrades bought counts every level (%d)" % int(s.night_events.get("upgrades_bought", 0)))
var done := 0
for id: String in panel._rows:
done += 1 if Upgrades.maxed(cfg, s, id) else 0
panel.refresh()
r.check(done == 3 and panel._title.text.ends_with("(3 of %d done)" % panel._rows.size()), "the title counts the ones at their last level: '%s'" % panel._title.text)
panel.queue_free()
# Levels persist: through a save, into the next morning, and in a retry from that morning.
var levels := s.upgrades.duplicate()
s.night = 1 # (back to the first day, so the vacation doesn't end below)
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(s.to_dict(), "", true, true)))
r.check(back != null and back.upgrades == levels and Upgrades.level(back, "heavy_seeds") == 3, "levels survive a save (JSON)")
while s.phase != P.MORNING:
c.advance_phase()
r.check(c.state.upgrades == levels, "and carry into the next morning")
c.begin_day()
c.advance_phase() # DAY -> DUSK
c.advance_phase() # DUSK -> NIGHT
r.check(c.retry_night() and c.state != s and c.state.upgrades == levels and c.state.resources.pouch_capacity == cap + pouch,
"and a retry from that morning keeps them")
# A save from before levels: {"rapid_fire": 1} is level 1.
var old := c.state.to_dict()
old["upgrades"] = {"corn_shooter": 1, "rapid_fire": 1, "sprint": 1}
var was := SaveGame.read(TIERS_SAVE).state if SaveGame.write(old, TIERS_SAVE) == OK else null
SaveGame.delete(TIERS_SAVE)
r.check(was != null and Upgrades.level(was, "rapid_fire") == 1 and Upgrades.owned(was, "rapid_fire")
and is_equal_approx(Upgrades.value(cfg, was, "fire_rate"), cfg.fire_rate * Upgrades.per_level(mult, 1))
and Upgrades.next_cost(cfg, was, "rapid_fire") == Upgrades.cost(cfg, "rapid_fire", 2),
"an old save's {\"rapid_fire\": 1} loads as level 1, with level 2 next")
r.check(was != null and Upgrades.owned(was, "sprint") and Upgrades.level(was, "sprint") == 1,
"and its {\"sprint\": 1} still owns Sprint, now the speed upgrade (same id)")
c.queue_free()
## Timed shed stock (#26): each shed item arrives on its day ("from_day"; day N is the day before
## night N) and can't be bought before it. Its row shows just its name, greyed, and "Arrives on
## day N"; a hidden one shows "?" and its day until it arrives, then the bare "?" until revealed.
## Debug F4 (CampaignDebug.unlock_all): on day 1, every upgrade and shop item goes to its last
## level for free, each level's effect applied; a retry from the morning review keeps it, one from
## later in the day goes back to the morning without it.
func _unlock_all(r: GameTestRunner) -> void:
var c := r.make_campaign((load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig)
var cfg := c.config
var s := c.state
var debug := CampaignDebug.new()
debug.campaign = c
r.root.add_child(debug)
await r.process_frame
var hp := s.scarecrow_max_hp
var pouch := s.resources.pouch_capacity
var shed: Dictionary = s.resources.shed.duplicate()
var damage := Upgrades.value(cfg, s, "shot_damage")
var key := InputEventKey.new()
key.physical_keycode = KEY_F4
key.pressed = true
debug._unhandled_input(key)
var all_max := true
for id: String in cfg.upgrades:
all_max = all_max and Upgrades.maxed(cfg, s, id) and Upgrades.blocker(c, id) == "Done"
r.check(all_max and s.night == 1 and Upgrades.levels_bought(cfg, s) == Upgrades.levels_total(cfg),
"F4 on the first morning: every upgrade and shop item at its last level (%d levels), hidden and not-yet-arrived ones too"
% Upgrades.levels_bought(cfg, s))
r.check(s.resources.shed == shed and int(s.night_events.get("upgrades_bought", 0)) == 0, "free, and not counted as bought")
r.check(s.scarecrow_max_hp == hp + 6 and s.scarecrow_hp == hp + 6 and s.resources.pouch_capacity == pouch + 16
and is_equal_approx(Upgrades.value(cfg, s, "shot_damage"), damage + 3),
"each level's effect applies: max health %d -> %d, pouch %d -> %d, kernels %.0f -> %.0f"
% [hp, s.scarecrow_max_hp, pouch, s.resources.pouch_capacity, damage, Upgrades.value(cfg, s, "shot_damage")])
r.check(debug.unlock_all() == 0, "pressing it again adds nothing")
c.retry_night()
r.check(Upgrades.levels_bought(cfg, c.state) == Upgrades.levels_total(cfg), "from the morning review, a retry keeps it")
c.new_campaign()
c.begin_day()
r.check(debug.unlock_all() == Upgrades.levels_total(cfg), "it works by day too")
c.retry_night()
r.check(Upgrades.levels_bought(cfg, c.state) == 0, "a retry from later in the day goes back to the morning without it")
c.outcome = CampaignController.Outcome.GAME_OVER_SCARECROW
c.state.phase = CampaignController.Phase.GAME_OVER
r.check(debug.unlock_all() == 0 and Upgrades.levels_bought(cfg, c.state) == 0, "nothing once the vacation is over")
debug.queue_free()
c.queue_free()
func _stock(r: GameTestRunner) -> void:
var c := r.make_campaign((load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig)
var cfg := c.config
var s := c.state
var days := {}
for id in Upgrades.ORDER:
if Upgrades.shop_of(cfg, id) == "shed":
days[id] = Upgrades.from_day(cfg, id)
r.check(days == {"corn_shooter": 1, "shurikens": 2, "pumpkin_bomb": 3, "potato_cannon": 6, "radar": 8, "propane_torch": 10, "alien_ray": 14},
"the shed's stock days: %s" % days)
var panel := UpgradePanel.new()
r.root.add_child(panel)
await r.process_frame
panel.setup(c, null, null, "shed")
c.begin_day()
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999, "alien_goop": 999}
panel.refresh()
var row := panel._rows["potato_cannon"] as Button
r.check(Upgrades.blocker(c, "potato_cannon") == "Arrives on day 6" and Upgrades.buy(c, "potato_cannon") == "Potato cannon: arrives on day 6"
and not Upgrades.owned(s, "potato_cannon") and not Upgrades.arrived(s, cfg, "potato_cannon"), "on day 1 the potato cannon isn't in stock and can't be bought")
r.check(row.disabled and row.text == "Potato cannon Arrives on day 6", "its row shows just its name, greyed, and its day: '%s'" % row.text)
r.check((panel._rows["alien_ray"] as Button).text == "? Arrives on day 14" and (panel._rows["alien_ray"] as Button).disabled,
"a hidden item not in stock shows '?' and its day: '%s'" % (panel._rows["alien_ray"] as Button).text)
r.check(not (panel._rows["corn_shooter"] as Button).disabled and Upgrades.blocker(c, "corn_shooter") == "", "the corn shooter is in stock on day 1")
s.night = 5
r.check(Upgrades.blocker(c, "potato_cannon") == "Arrives on day 6" and Upgrades.blocker(c, "pumpkin_bomb") == "", "(day 5: not yet; the pumpkin bombs, from day 3, are)")
s.night = 6
panel.refresh()
r.check(Upgrades.arrived(s, cfg, "potato_cannon") and Upgrades.blocker(c, "potato_cannon") == "" and not row.disabled
and row.text.begins_with("Potato cannon — "), "on day 6 it's in stock: '%s'" % row.text)
r.check(Upgrades.buy(c, "potato_cannon").contains("done:") and Upgrades.owned(s, "potato_cannon"), "and can be bought")
panel.refresh()
r.check(row.disabled and row.text.ends_with(" (Done)"), "a one-off says Done: '%s'" % row.text)
s.night = 14
panel.refresh()
r.check((panel._rows["alien_ray"] as Button).text == "?" and Upgrades.blocker(c, "alien_ray") == "Not discovered yet",
"in stock but not discovered yet, it's a bare '?'")
panel.queue_free()
c.queue_free()
func _layout(r: GameTestRunner, sim: FarmSim) -> void:
var by_material := {}
var names := {}
for n in sim.interactions.nodes:
by_material[n.material] = int(by_material.get(n.material, 0)) + 1
names[String(n.name)] = true
var zone := sim.zones.zone_at(n.global_position)
var want := {"wood": FarmZone.Kind.WOOD, "scrap": FarmZone.Kind.SCRAP, "straw": FarmZone.Kind.STRAW}[n.material] as FarmZone.Kind
r.check(zone != null and zone.kind == want and n.get_child_count() >= 2, "%s (%s) stands in its zone with its props" % [n.name, n.material])
var inside := {}
var outside := {}
for n in sim.interactions.nodes:
var bucket := inside if sim.zones.is_inside_fence(n.global_position) else outside
bucket[n.material] = int(bucket.get(n.material, 0)) + 1
if bucket == outside:
r.check(n.yield_amount > 2 and sim.zones.zone_at(n.global_position).outside, "%s, outside the fence, yields more (%d)" % [n.name, n.yield_amount])
for m in ResourceStore.MATERIALS:
r.check(int(inside.get(m, 0)) >= 3 and int(inside.get(m, 0)) <= 5, "3-5 gather points for %s on the farm (%d)" % [m, int(inside.get(m, 0))])
r.check(int(outside.get(m, 0)) >= 2, "and more outside the fence (%d)" % int(outside.get(m, 0)))
r.check(sim.zones.outside_zones().size() == 4 and sim.zones.zone(FarmZone.Kind.WOOD).display_name == "Woodlot",
"four gathering areas outside, and the farm's own zones still come first")
r.check(names.size() == sim.interactions.nodes.size(), "gather point names are unique (they key the farm state)")
# The scarecrow's body must be able to stand within reach of every point (and the workbench),
# walking there from its start: out through the gaps for the points outside.
var nav := FarmNavigation.new()
nav.build(sim.get_parent(), sim.zones.roam, 0.5, FarmSim.SCARECROW_RADIUS, 1 | 4)
var from := nav.nearest_free(nav.cell_of(sim.player.global_position.x, sim.player.global_position.z))
var walk := nav.distance_field(PackedInt32Array([from]))
var spots: Array[Node3D] = []
spots.assign(sim.interactions.nodes)
spots.append(sim.interactions.workbench)
for n in spots:
var reach: float = n.reach
var c := Vector2(n.global_position.x, n.global_position.z)
var closest := INF
for cell in nav.free_cells_in(Rect2(c - Vector2.ONE * reach, Vector2.ONE * reach * 2.0)):
if walk[cell] < FarmNavigation.UNREACHABLE:
closest = minf(closest, nav.cell_center(cell).distance_to(c))
r.check(closest <= reach - 0.25, "the scarecrow can walk to within reach of %s (%.1f of %.1f m)" % [n.name, closest, reach])
r.check(sim.interactions.workbench != null and sim.zones.zone(FarmZone.Kind.WORK_AREA).contains(sim.interactions.workbench.global_position),
"the workbench stands in the work area")
func _gathering(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
var it := sim.interactions
var res := sim.campaign.state.resources
var tree := _node(it, "DeadTree")
var msgs: Array[String] = []
it.message.connect(func(t: String, _c: Color) -> void: msgs.append(t))
_stand_at(player, tree)
_hold(sim, 30)
r.check(res.pouch_total() == 0 and msgs.has("Gathering is for daytime"), "no gathering before the day starts (once per press: %d)" % msgs.size())
Input.action_release("interact")
sim.campaign.begin_day()
_step(sim, 1)
_hold(sim, 30)
r.check(it.gathering == tree and player.rooted and not it.can_shoot(), "holding interact gathers: rooted, no shooting")
_hold(sim, roundi(sim.config.gather_time * 60.0) - 30 + 2)
r.check(res.pouch["wood"] == tree.yield_amount and it.charges(tree) == tree.max_charges - 1,
"after %.1f s: +%d wood in the pouch, one charge used" % [sim.config.gather_time, tree.yield_amount])
_hold(sim, roundi(sim.config.gather_time * 60.0) + 4)
r.check(it.charges(tree) == 0 and res.pouch["wood"] == tree.yield_amount * 2, "holding on gathers again until the point runs out")
_hold(sim, 10)
r.check(it.gathering == null and msgs.has("Nothing left here; it grows back overnight"), "a used-up point can't be gathered")
# Next to both a used-up point and a full one, interact goes to the full one.
var logs := _node(it, "LogPile")
player.global_position = (tree.global_position + logs.global_position) * 0.5
player.global_position.y = 0.0
Input.action_release("interact")
_step(sim, 1)
var both := Vector2(player.global_position.x - tree.global_position.x, player.global_position.z - tree.global_position.z).length() <= tree.reach \
and Vector2(player.global_position.x - logs.global_position.x, player.global_position.z - logs.global_position.z).length() <= logs.reach
_hold(sim, 5)
r.check(both and it.gathering == logs, "between a used-up point and a full one, the full one is gathered")
Input.action_release("interact")
_step(sim, 1)
res.pouch["wood"] = tree.yield_amount * 2
Input.action_release("interact")
_step(sim, 1)
var snag := _node(it, "Snag")
_stand_at(player, snag)
_hold(sim, 40)
Input.action_release("interact")
_step(sim, 1)
r.check(it.gathering == null and it.charges(snag) == snag.max_charges and not player.rooted, "letting go early gathers nothing")
_hold(sim, 40)
sim.scarecrow.try_damage(1)
r.check(it.gathering == null, "a hit stops gathering")
sim.scarecrow.invulnerable_left = 0.0
sim.campaign.state.scarecrow_hp = sim.campaign.state.scarecrow_max_hp
Input.action_release("interact")
_step(sim, 1)
_hold(sim, 40)
sim.scarecrow.use_fear()
sim.scarecrow.fear_left = 0.0
r.check(it.gathering == null, "using fear stops gathering")
Input.action_release("interact")
_step(sim, 1)
res.add_to_pouch("scrap", res.pouch_room() - 1)
_hold(sim, 20)
r.check(it.gathering == null and msgs.has("Pouch full: drop it off at the supply shed") and it.charges(snag) == snag.max_charges,
"without room for the whole yield, nothing is gathered (and no charge is wasted)")
Input.action_release("interact")
_step(sim, 1)
## The HUD's backpack: "used/capacity", a red dot once something new is carried (gone once the pouch
## is opened, or emptied), and the pouch panel (I / R3) with what's carried and what the shed holds.
func _pouch_hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var hud := farm.get_node("Hud/ResourceHud") as ResourceHud
var res := sim.campaign.state.resources
var keep_shed: Dictionary = res.shed.duplicate()
var keep_pouch: Dictionary = res.pouch.duplicate()
for m in ResourceStore.MATERIALS:
res.pouch[m] = 0
hud._process(0.0)
hud.open = false
r.check(not hud.new_items and hud.count_text() == "0/%d" % res.pouch_capacity, "an empty pouch: '%s', no dot" % hud.count_text())
res.add_to_pouch("wood", 3)
res.shed["scrap"] = 7
hud._process(0.0)
r.check(hud.count_text() == "3/%d" % res.pouch_capacity and hud.new_items, "the backpack counts what's carried ('%s'), with a dot for the new wood" % hud.count_text())
var press := InputEventAction.new()
press.action = &"pouch"
press.pressed = true
hud._unhandled_input(press)
var rows := hud.rows()
r.check(hud.open and not hud.new_items and rows.size() == ResourceStore.MATERIALS.size()
and rows[0] == {"material": "wood", "pouch": 3, "shed": int(res.shed["wood"])} and int(rows[1]["shed"]) == 7,
"I opens the pouch: what's carried and the shed's stock of each, and the dot goes: %s" % [rows])
hud._unhandled_input(press)
r.check(not hud.open, "and closes it again")
res.add_to_pouch("straw", 1)
hud._process(0.0)
var dot := hud.new_items
res.deposit()
hud._process(0.0)
r.check(dot and not hud.new_items, "emptying the pouch clears the dot")
for m in ResourceStore.MATERIALS:
res.shed[m] = int(keep_shed.get(m, 0))
res.pouch[m] = int(keep_pouch.get(m, 0))
hud._process(0.0)
func _deposit_and_night(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
var c := sim.campaign
var res := c.state.resources
var it := sim.interactions
var shed_before: Dictionary = res.shed.duplicate()
var pouch: Dictionary = res.pouch.duplicate()
var moved: Array[Dictionary] = []
it.deposited.connect(func(m: Dictionary) -> void: moved.append(m))
var shed := sim.zones.zone(FarmZone.Kind.SUPPLY_SHED)
player.global_position = shed.global_position + Vector3(0.0, 0.0, 2.0)
_step(sim, 1)
r.check(res.pouch_total() == 0 and moved.size() == 1 and res.shed["wood"] == int(shed_before["wood"]) + int(pouch["wood"])
and res.shed["scrap"] == int(shed_before["scrap"]) + int(pouch["scrap"]), "walking into the supply shed stores the pouch")
var tree := _node(it, "DeadTree")
var deadfall := _node(it, "Deadfall")
c.state.gather_charges["Deadfall"] = 0
deadfall.regen_per_night = 1
c.advance_phase()
c.advance_phase()
r.check(c.state.phase == P.NIGHT, "night falls")
_stand_at(player, _node(it, "LogPile"))
_hold(sim, 30)
r.check(it.gathering == null and res.pouch_total() == 0, "no gathering at night")
Input.action_release("interact")
_step(sim, 1)
c.advance_phase()
c.advance_phase()
r.check(c.state.phase == P.MORNING and it.charges(tree) == tree.max_charges and it.charges(deadfall) == 1,
"overnight the points grow back (a point regrowing 1 a night has 1 again)")
deadfall.regen_per_night = 20
# Retry brings back the morning's materials and points.
var morning := c.state.to_dict()
c.begin_day()
_stand_at(player, _node(it, "Wreck"))
_hold(sim, roundi(sim.config.gather_time * 60.0) + 2)
Input.action_release("interact")
_step(sim, 1)
r.check(res.pouch["scrap"] > 0, "scrap gathered on day 2")
c.advance_phase()
c.advance_phase()
c.state.scarecrow_hp = 0
_step(sim, 1)
c.retry_night()
_step(sim, 1)
r.check(c.state.resources.to_dict() == morning["resources"] and c.state.gather_charges == morning["gather_charges"],
"retry restores the morning's materials and gather points")
func _patch_cost(r: GameTestRunner, sim: FarmSim) -> void:
var s := sim.campaign.state
var kit := sim.scarecrow
var denied: Array[Dictionary] = []
kit.patch_denied.connect(func(m: Dictionary) -> void: denied.append(m))
s.resources.shed["straw"] = 2
s.resources.pouch["straw"] = 0
s.scarecrow_hp = 5
Input.action_press("patch")
_step(sim, roundi(sim.config.patch_time * 60.0) + 2)
r.check(s.scarecrow_hp == 5 + sim.config.patch_heal and s.resources.available("straw") == 0, "a patch costs 2 straw")
_step(sim, 30)
r.check(not kit.patching and denied.size() == 1 and denied[0] == {"straw": 2}, "without straw the patch is refused, once per press")
Input.action_release("patch")
_step(sim, 1)
s.scarecrow_hp = s.scarecrow_max_hp
func _stuffing(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
var c := sim.campaign
var s := c.state
var it := sim.interactions
var bench := it.workbench
var menu := sim.upgrade_panel
var add := roundi(Upgrades.per_level(sim.config.upgrades["straw_stuffing"]["add"], 1))
var msgs: Array[String] = []
it.message.connect(func(t: String, _col: Color) -> void: msgs.append(t))
menu.message.connect(func(t: String, _col: Color) -> void: msgs.append(t))
player.global_position = bench.global_position + Vector3(0.0, 0.0, 1.2)
_press(sim)
r.check(not menu.is_open and msgs[-1] == "The work area is for daytime", "no upgrades during the morning review")
c.begin_day()
s.resources.shed = {"wood": 0, "scrap": 0, "straw": 3}
_press(sim)
r.check(menu.is_open and player.rooted and not it.can_shoot(), "interact at the workbench opens the upgrade menu; the scarecrow stands still")
var row := menu._rows["straw_stuffing"] as Button
r.check(row.disabled and row.text.contains("Need 4 wood, 9 straw more"), "short of materials, the row says what's missing: '%s'" % row.text)
s.resources.shed = {"wood": 3, "scrap": 0, "straw": 12}
s.resources.pouch = {"wood": 1, "scrap": 0, "straw": 0}
menu.refresh()
var max_hp := s.scarecrow_max_hp
row.pressed.emit()
r.check(Upgrades.owned(s, "straw_stuffing") and s.scarecrow_max_hp == max_hp + add and s.scarecrow_hp == s.scarecrow_max_hp,
"Straw stuffing: +%d max HP (%s)" % [add, msgs[-1]])
r.check(s.resources.shed == {"wood": 0, "scrap": 0, "straw": 0} and s.resources.pouch["wood"] == 0, "it costs 12 straw and 4 wood")
r.check(row.disabled and row.text.begins_with("Straw stuffing II —") and row.text.contains("Level 2 opens on day 8"),
"the row offers level II, closed until day 8: '%s'" % row.text)
_press(sim)
r.check(not menu.is_open and not player.rooted, "interact again closes the menu")
_press(sim)
menu.close()
## #6: weapons (corn_shooter, pumpkin_bomb) moved to their own shop at the supply shed's counter
## (ShedCounter, shop "shed"), separate from the workbench's upgrade menu; buying one there works
## the same way, and the shed's walk-in pouch deposit still needs no interact and isn't gated by
## the counter's reach or its shop being open.
func _shed_shop(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
var c := sim.campaign
var s := c.state
var it := sim.interactions
var counter := it.shed_counter
var bench_menu := sim.upgrade_panel
var menu := sim.shed_panel
r.check(counter != null and menu != null, "the supply shed has its own counter and shop menu")
r.check(not bench_menu._rows.has("corn_shooter") and not bench_menu._rows.has("pumpkin_bomb")
and menu._rows.has("corn_shooter") and menu._rows.has("pumpkin_bomb"),
"the workbench no longer sells the weapons; the shed's menu does")
s.upgrades.erase("corn_shooter")
s.resources.shed = {"wood": 4, "scrap": 10, "straw": 0}
player.global_position = counter.global_position + Vector3(0.0, 0.0, 1.2)
_press(sim)
r.check(menu.is_open and not bench_menu.is_open and player.rooted and not it.can_shoot(),
"interact at the shed counter opens the shed's shop, not the workbench's")
var row := menu._rows["corn_shooter"] as Button
row.pressed.emit()
r.check(Upgrades.owned(s, "corn_shooter") and s.resources.shed == {"wood": 0, "scrap": 0, "straw": 0},
"buying the corn shooter from the shed's menu works, for its usual cost")
_press(sim)
r.check(not menu.is_open and not player.rooted, "interact again closes the shed's shop")
var shed_zone := sim.zones.zone(FarmZone.Kind.SUPPLY_SHED)
player.global_position = Vector3(shed_zone.global_position.x, 0.0, shed_zone.global_position.z - 4.0)
r.check(Vector2(player.global_position.x, player.global_position.z).distance_to(Vector2(counter.global_position.x, counter.global_position.z)) > counter.reach,
"well outside the counter's reach, but still in the shed")
s.resources.pouch = {"wood": 2, "scrap": 0, "straw": 0}
_step(sim, 1)
r.check(s.resources.pouch.get("wood", 0) == 0 and s.resources.shed.get("wood", 0) == 2,
"walking into the shed zone still auto-deposits the pouch, away from the counter and with its shop closed")
## Alien Goop (#4): dropped only by killed Aliens (thieves), at GameConfig's rate and quantity,
## credited like a gathered material (respecting the pouch's capacity), and stealable from the
## shed like any other material once it's the one on top.
func _goop_drops(r: GameTestRunner, sim: FarmSim) -> void:
var es := sim.enemies
var s := sim.campaign.state
var cfg := sim.config
var pouch_cap_before := s.resources.pouch_capacity
s.resources.pouch_capacity = 1000000 # room for every drop; isolates the chance roll from capacity
# Statistical: over many kills, the drop rate roughly matches the config chance (the drop
# roll uses a seeded RNG, so this is also reproducible run to run).
const N := 1000
var before := int(s.night_events.get("gathered_alien_goop", 0))
for i in N:
var h := es.spawn(EnemySystem.TYPE_THIEF, 12.0, -30.0, Vector2.UP)
es.apply_hit_handle(h, 99)
_step(sim, 1)
var gained := int(s.night_events.get("gathered_alien_goop", 0)) - before
var rate := float(gained) / float(N * cfg.alien_goop_drop_qty)
r.check(absf(rate - cfg.alien_goop_drop_chance) < 0.06,
"killing %d Aliens drops goop about %.0f%% of the time (got %.1f%%, %d units)" % [N, cfg.alien_goop_drop_chance * 100.0, rate * 100.0, gained])
# Type restriction: only thieves ("Alien") drop goop, not crows or fence breakers.
var before2 := int(s.night_events.get("gathered_alien_goop", 0))
for i in 50:
var hc := es.spawn(EnemySystem.TYPE_CROW, 12.0, -30.0, Vector2.UP)
es.apply_hit_handle(hc, 99)
_step(sim, 1)
var hb := es.spawn(EnemySystem.TYPE_BREAKER, 12.0, -30.0, Vector2.UP)
es.apply_hit_handle(hb, 99)
_step(sim, 1)
r.check(int(s.night_events.get("gathered_alien_goop", 0)) == before2, "only Aliens (thieves) drop goop, not crows or fence breakers")
# Deterministic: a guaranteed drop is credited like a gathered material, capped by pouch room.
cfg.alien_goop_drop_chance = 1.0
cfg.alien_goop_drop_qty = 3
s.resources.pouch_capacity = s.resources.pouch_total() + 2 # room for only 2 of the 3
var pouch_before := s.resources.pouch_total()
var h2 := es.spawn(EnemySystem.TYPE_THIEF, 12.0, -30.0, Vector2.UP)
es.apply_hit_handle(h2, 99)
_step(sim, 1)
r.check(s.resources.pouch_total() == pouch_before + 2, "a drop only adds what fits in the pouch (2 of 3, the pouch nearly full)")
cfg.alien_goop_drop_chance = 0.33
cfg.alien_goop_drop_qty = 1
s.resources.pouch_capacity = pouch_cap_before
# Stealable from the shed: once goop is the shed's most-stocked material, a supply claim
# takes it, and the shed's own pile wiring gives the thief somewhere real to stand.
s.resources.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 20}
var sack := sim.loot._claim_home(LootSystem.Category.SUPPLY)
r.check(sack > 0 and sim.loot.sack_material[sack] == "alien_goop" and sim.loot.home[sack] != Vector2.ZERO,
"a sack claimed at the shed takes goop when it's the most-stocked material, at a real spot")
s.resources.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
func _node(it: Interactions, node_name: String) -> GatherNode:
for n in it.nodes:
if n.name == node_name:
return n
return null
## Puts the scarecrow next to a gather point, within its reach.
func _stand_at(player: PlayerCharacter, n: GatherNode) -> void:
var to_center := Vector3(n.global_position.x, 0.0, n.global_position.z)
player.global_position = to_center + Vector3(n.reach * 0.7, 0.0, 0.0)
func _hold(sim: FarmSim, ticks: int) -> void:
Input.action_press("interact")
_step(sim, ticks)
func _press(sim: FarmSim) -> void:
Input.action_release("interact")
_step(sim, 1)
Input.action_press("interact")
_step(sim, 1)
Input.action_release("interact")
_step(sim, 1)
func _step(sim: FarmSim, n: int) -> void:
for i in n:
sim.step(DT)