Task #16: per-player pouch in co-op

Each scarecrow carries its own pouch (ResourceStore.pouches by avatar
slot; slot 0 is the solo player / host, `pouch` stays slot 0's), with one
shared pouch_capacity so a Bigger pouch grows both. The shed stays shared.

- Gathering, the shed drop-off, repair, upgrade-in-place, patching,
  building and buying all act on the acting avatar's slot. The host pays
  the partner's "place" and "buy" requests from P2's pouch and the shed.
- The partner's build mode, build hotbar, shop menus and materials HUD
  check affordability against P2's pouch (FarmSim.set_local).
- Alien Goop goes to the killer's pouch: FarmSim sets
  EnemySystem.attacker around each avatar's combat step and shots carry
  their shooter's slot; bomb/turret kills go to the nearest scarecrow.
  The replica no longer rolls goop locally.
- When the partner leaves, their pouch goes into the shed (and is named
  in the toast); a co-op save continued alone banks P2's pouch at morning.
- FarmState.VERSION 7 (resources.partner_pouch) with a v6 migration;
  CoopSession.PROTOCOL 4.
- Tests: per-slot store rules, v6 save migration, and test_coop cases for
  separate gathering, no cross-banking in the shed, own-pouch paying,
  shared capacity, goop credit and leaving. test_coop's crowd case now
  resets the loopback's drop counter so earlier traffic can't change
  which messages it loses.
- Docs: COOP.md and RULES.md no longer say the pouch is shared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 13:06:25 -04:00
parent 26b735d3e6
commit fa7f67fe04
23 changed files with 535 additions and 138 deletions

View file

@ -57,8 +57,18 @@ a knock alone doesn't open it) and stays open for 0.4 s after you stop. Talking
- your microphone's state.
- **Edge arrow:** when your friend is off screen, an arrow at the edge points to them, with the
distance.
- **Everything is shared:** the shed, the pouch, upgrades, structures, and the vacation itself.
Either player can gather, build, repair, buy upgrades, and start the day.
- **Shared:** the shed, upgrades, structures, and the vacation itself. Either player can gather,
build, repair, buy upgrades, and start the day.
- **Your pouch is your own.** The materials HUD shows yours.
- What you gather goes into your pouch.
- Only you walking into the Supply Shed banks it: your friend standing there doesn't.
- You pay for building, repairs, patching, and upgrades from your own pouch first, then the
shed, never from your friend's pouch.
- An Alien's goop goes into the pouch of the player who killed it. A pumpkin bomb's or a
turret's kill goes to the nearest scarecrow.
- Both pouches hold the same amount: one Bigger pouch makes both bigger.
- When your friend leaves, what they carried goes into the shed. So does player 2's pouch in
a co-op save that the host continues alone.
- **Health is your own.** Upgrades to max health apply to both scarecrows.
- **A scarecrow at 0 HP is out until the morning.** It lies there and the camera follows the
other one. It comes back each morning at half health. **Game Over only when both are down at
@ -128,7 +138,8 @@ message on both sides.
- **`game/tests/test_coop.gd`** (in the main suite) runs host and partner in one process: the
partner's farm sits in its own world, over the loopback link. It covers the join, requests,
the partner moving, gathering, and shooting (and its pick of weapon), the host's stabs and
the partner moving, gathering, and shooting (and its pick of weapon), each player's own pouch
(gathering, the shed, paying, the shared capacity, goop to the killer, leaving), the host's stabs and
pumpkin bombs drawn on the partner's farm (harmless there), enemies, loot, and shots arriving, the fall rule
and Retry, a crowd with dropped packets, message sizes, and either side leaving.
- **`game/tools/coop_smoke.gd`** plays a real GD-Sync LAN game between two processes on one

View file

@ -281,9 +281,11 @@ Implemented in Step 5. The numbers are in `GameConfig`; the gather points are li
- **Three materials:** wood, scrap, and straw.
- The supply shed's stock starts at 4 wood, 2 scrap, 4 straw.
- The scarecrow's **pouch** holds **15 units** in total.
- The scarecrow's **pouch** holds **15 units** in total. In co-op each scarecrow has its own
pouch, of the same size (below).
- Walking into the Supply Shed zone empties the pouch into the shed, in any phase.
- **Paying:** costs come from the pouch first, then the shed, and are all-or-nothing.
- **Paying:** costs come from the pouch first, then the shed, and are all-or-nothing. In co-op
that's the payer's own pouch, never the other's.
- **Patch:** 2 straw.
- **Buildables:** fence 2 wood; gate 4 wood + 1 scrap; slowing trap 3 scrap + 1 wood; automated
defense 6 scrap + 2 wood + 2 straw.
@ -516,10 +518,18 @@ tip doesn't come back on a retry.
Two players, each with a scarecrow, keep one farm (Main menu → Play with a friend; the details are
in `game/COOP.md`):
- **What's shared:** the shed, the pouch, upgrades, and structures. Either player can gather,
build, repair, buy upgrades, and start the day.
- **What's shared:** the shed, upgrades, and structures. Either player can gather, build,
repair, buy upgrades, and start the day.
- **What's your own:** your scarecrow's health, and the weapon in your hands: a weapon bought
is there for both, and each player picks their own main weapon. Upgrades to max health apply to both.
- **Your pouch is your own** (the materials HUD shows yours):
- You gather into it, and only you walking into the Supply Shed banks it.
- You pay from it first, then from the shed.
- An Alien's goop goes to its killer's pouch. A pumpkin bomb's or a turret's kill goes to the
nearest scarecrow's.
- Both pouches have the same capacity: one Bigger pouch grows both.
- When player 2 leaves, their pouch goes into the shed. So does player 2's pouch in a co-op
save continued alone.
- **Falling:** a scarecrow at 0 HP is out until the morning, when it comes back at half health.
**Game Over only when both are down at once.**
- **Enemies** go for the nearer scarecrow.

View file

@ -1,8 +1,8 @@
class_name BuildHud
extends Control
## The build hotbar, shown in build mode: one slot per buildable with its key, name, and cost
## (red when it can't be afforded), the selected one highlighted, the controls, and how many
## structures stand on the farm.
## (red when the builder can't afford it from their own pouch and the shed), the selected one
## highlighted, the controls, and how many structures stand on the farm.
const SLOT := Vector2(230.0, 76.0)
const GAP := 12.0
@ -34,6 +34,7 @@ func _process(_delta: float) -> void:
if not visible:
return
var r := campaign.state.resources
var slot := build.kit.slot if build.kit != null else 0
var origin := _origin()
for i in StructureSystem.ORDER.size():
var t: String = StructureSystem.ORDER[i]
@ -43,7 +44,7 @@ func _process(_delta: float) -> void:
_names[i].position = pos + Vector2(12.0, 8.0)
_costs[i].text = ResourceStore.describe(cost)
_costs[i].position = pos + Vector2(12.0, 42.0)
_costs[i].add_theme_color_override("font_color", Color(0.9, 0.95, 0.9) if r.can_afford(cost) else Color(1.0, 0.45, 0.4))
_costs[i].add_theme_color_override("font_color", Color(0.9, 0.95, 0.9) if r.can_afford(cost, slot) else Color(1.0, 0.45, 0.4))
_help.text = "Build mode · LMB / RT build · Z C / d-pad rotate · 1-4 / Tab pick · RMB / B dismantle or leave · %d built" % \
build.structures.count()
_help.position = origin + Vector2(0.0, -34.0)

View file

@ -12,6 +12,7 @@ extends Node3D
## The scarecrow doesn't shoot, gather, or repair while building (FarmSim, Interactions).
## Co-op, on the partner's machine: placing and dismantling are sent to the host (place_request,
## dismantle_request), which checks them again and does them; the result comes back as a message.
## The cost is checked against (and paid from) the builder's own pouch and the shed (kit.slot).
signal message(text: String, color: Color)
signal toggled(on: bool)
@ -127,12 +128,12 @@ func step(_dt: float) -> void:
(": %s back in the shed" % ResourceStore.describe(back)) if not back.is_empty() else ""], Color(0.85, 0.95, 1.0))
hover = -1
return
reason = structures.validate(type(), cursor.x, cursor.y, rot, me)
reason = structures.validate(type(), cursor.x, cursor.y, rot, me, kit.slot)
if p[&"fire"]:
if reason == "" and place_request.is_valid():
place_request.call(type(), cursor.x, cursor.y, rot)
elif reason == "":
structures.place(type(), cursor.x, cursor.y, rot)
structures.place(type(), cursor.x, cursor.y, rot, kit.slot)
message.emit("Built a %s" % StructureSystem.NAMES[type()].to_lower(), Color(0.6, 1.0, 0.55))
else:
message.emit(reason, Color(1.0, 0.8, 0.5))

View file

@ -44,8 +44,9 @@ signal welcomed
## The wire format: both machines must speak the same one (hello and welcome carry it). 3: #10
## added a time field and two int32s (the upgrade target/progress) to _put_avatar/_read_avatar's
## per-avatar snapshot record.
const PROTOCOL := 3
## per-avatar snapshot record. 4: #16 gave each scarecrow its own pouch (the farm state's
## resources.partner_pouch, FarmState.VERSION 7).
const PROTOCOL := 4
const SNAP_EVERY := 4 # physics ticks: 15 Hz
const INPUT_EVERY := 3 # 20 Hz, when it changed
## Seconds: the partner's input goes out at least this often, changed or not.
@ -241,11 +242,14 @@ func stop(reason: String = "") -> void:
sim.audio.forward = Callable()
if was == Role.HOST:
var gone_name := partner_name
sim.remove_partner()
var left_behind := sim.remove_partner() # their pouch, now in the shed
sim.avatars[0].player_name = ""
sim.player.set_tag("", Color.WHITE)
if sim.toasts != null:
sim.toasts.push("%s left: you're on your own" % _display(gone_name, "Player 2"), Color(1.0, 0.8, 0.5))
var text := "%s left: you're on your own" % _display(gone_name, "Player 2")
if not left_behind.is_empty():
text += " (%s from their pouch is in the shed)" % ResourceStore.describe(left_behind)
sim.toasts.push(text, Color(1.0, 0.8, 0.5))
partner_left.emit(gone_name)
else:
ended.emit(reason)
@ -532,9 +536,9 @@ func _do_request(r: Array) -> void:
var rot := int(r[4])
if not StructureSystem.ORDER.has(type):
return
var why := sim.structures.validate(type, x, z, rot, a.position())
var why := sim.structures.validate(type, x, z, rot, a.position(), a.slot)
if why == "":
sim.structures.place(type, x, z, rot)
sim.structures.place(type, x, z, rot, a.slot) # paid from P2's pouch, then the shed
_events.append(["toast", "Built a %s" % StructureSystem.NAMES[type].to_lower(), Color(0.6, 1.0, 0.55)])
else:
_events.append(["toast", why, Color(1.0, 0.8, 0.5)])
@ -551,7 +555,7 @@ func _do_request(r: Array) -> void:
if Upgrades.shop_of(c.config, id) == "workbench" and (sim.structures == null or not sim.structures.workbench_available()):
_events.append(["toast", "The work area isn't available", Color(1.0, 0.8, 0.5)])
return
var text := Upgrades.buy(c, id, sim.structures)
var text := Upgrades.buy(c, id, sim.structures, a.slot) # paid from P2's pouch, then the shed
_events.append(["toast", text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5)])

View file

@ -112,6 +112,11 @@ var _free_ids := PackedInt32Array()
var _free_top: int = 0
var _pending := PackedInt32Array()
var _pending_count: int = 0
## Co-op goop credit: the avatar slot whose attack is being resolved right now (FarmSim sets it
## around each scarecrow's combat step; -1 otherwise: turrets, bombs going off, tests), and the
## slot that landed each enemy's killing hit, by stable id (read through killer_of()).
var attacker: int = -1
var _killer := PackedInt32Array()
# Diagnostics.
var spawn_skipped: int = 0
@ -134,7 +139,7 @@ func setup(cfg: GameConfig, p_nav: FarmNavigation, p_behavior: ThiefBehavior, me
pace, head_x, head_z, flap_phase, hurt, timer, attack_cd, slow_left, alt]:
a.resize(capacity)
a.fill(0.0)
for a: PackedInt32Array in [health, target, carry, barrier, dense_id, id_dense, id_generation, _free_ids, _pending]:
for a: PackedInt32Array in [health, target, carry, barrier, dense_id, id_dense, id_generation, _free_ids, _pending, _killer]:
a.resize(capacity)
a.fill(0)
for a: PackedByteArray in [type, state, alive, removal, resume, want]:
@ -222,6 +227,7 @@ func spawn(enemy_type: int, x: float, z: float, heading: Vector2, p_want: int =
spawn_skipped += 1
return -1
_free_top -= 1
_killer[id] = -1
var d := active_count
active_count += 1
var h := heading.normalized() if heading.length_squared() > 1e-6 else Vector2(0.0, -1.0)
@ -287,8 +293,9 @@ func visual_position(d: int) -> Vector2:
return Vector2(lerpf(prev_x[d], pos_x[d], f), lerpf(prev_z[d], pos_z[d], f))
## Applies one hit. Returns false for dead or pending slots (no double kills).
func apply_hit(d: int, damage: int = 1) -> bool:
## Applies one hit. Returns false for dead or pending slots (no double kills). by: the avatar
## slot that landed it (a shot's shooter), or -1 for whoever is attacking now (attacker).
func apply_hit(d: int, damage: int = 1, by: int = -1) -> bool:
if not is_alive_slot(d):
return false
health[d] -= damage
@ -297,14 +304,22 @@ func apply_hit(d: int, damage: int = 1) -> bool:
characters.hit(dense_id[d])
if health[d] <= 0:
kills += 1
_killer[dense_id[d]] = by if by >= 0 else attacker
queue_removal(d, Removal.KILLED)
elif behavior != null:
behavior.on_hit(self, d)
return true
func apply_hit_handle(handle: int, damage: int = 1) -> bool:
return apply_hit(resolve_handle(handle), damage)
func apply_hit_handle(handle: int, damage: int = 1, by: int = -1) -> bool:
return apply_hit(resolve_handle(handle), damage, by)
## The avatar slot whose hit killed this enemy (while enemy_removed is emitted for it), or -1:
## killed by a turret or a bomb, not killed, or a stale handle.
func killer_of(handle: int) -> int:
var d := resolve_handle(handle)
return _killer[dense_id[d]] if d >= 0 else -1
## Takes a living enemy out of the simulation now; its slot is released (and enemy_removed

View file

@ -34,6 +34,9 @@ var _life := PackedFloat32Array()
## Cannon, Shurikens, and Alien Ray fly at their own speeds).
var _speed := PackedFloat32Array()
var _damage := PackedInt32Array()
## The avatar slot that fired each shot (EnemySystem.attacker when it was fired; -1 for the
## automated defenses'), credited with what it kills (co-op Alien Goop).
var _owner := PackedInt32Array()
var _cfg: GameConfig
var _enemies: EnemySystem
var _bounds: Rect2
@ -50,6 +53,7 @@ func setup(cfg: GameConfig, enemies: EnemySystem, bounds: Rect2, shooter: RID) -
a.resize(capacity)
a.fill(0.0)
_damage.resize(capacity)
_owner.resize(capacity)
_ray.collision_mask = WORLD_LAYER
_ray.collide_with_areas = false
_ray.collide_with_bodies = true
@ -84,7 +88,8 @@ func fire(origin: Vector3, muzzle: Vector3, dir: Vector3, damage: int = 1, speed
exhausted += 1
return false
fired += 1
if _resolve_segment(origin.x, origin.z, muzzle.x, muzzle.z, false, damage):
var by := _enemies.attacker
if _resolve_segment(origin.x, origin.z, muzzle.x, muzzle.z, false, damage, by):
blocked_at_muzzle += 1
return false
var d := active_count
@ -95,6 +100,7 @@ func fire(origin: Vector3, muzzle: Vector3, dir: Vector3, damage: int = 1, speed
_dz[d] = dir.z
_life[d] = lifetime if lifetime > 0.0 else _cfg.projectile_lifetime
_damage[d] = damage
_owner[d] = by
_speed[d] = speed if speed > 0.0 else _cfg.projectile_speed
_renderer.write_new(d, muzzle.x, muzzle.z, dir.x, dir.z, 0.0)
return true
@ -108,7 +114,7 @@ func step(dt: float) -> void:
var z0 := _pz[i]
var x1 := x0 + _dx[i] * step_len
var z1 := z0 + _dz[i] * step_len
if _resolve_segment(x0, z0, x1, z1, true, _damage[i]):
if _resolve_segment(x0, z0, x1, z1, true, _damage[i], _owner[i]):
_release(i)
continue
_px[i] = x1
@ -152,8 +158,9 @@ func commit_render() -> void:
## Resolves the nearest world/enemy hit along a segment. Returns true if something was hit
## (damage is applied for enemy hits). use_motion selects the relative-motion enemy test.
func _resolve_segment(x0: float, z0: float, x1: float, z1: float, use_motion: bool, damage: int) -> bool:
## (damage is applied for enemy hits, credited to the shooter's avatar slot by). use_motion
## selects the relative-motion enemy test.
func _resolve_segment(x0: float, z0: float, x1: float, z1: float, use_motion: bool, damage: int, by: int) -> bool:
var h := _cfg.combat_height
var world_t := 2.0
_ray.from = Vector3(x0, h, z0)
@ -166,7 +173,7 @@ func _resolve_segment(x0: float, z0: float, x1: float, z1: float, use_motion: bo
var e := _enemies.sweep_hit(x0, z0, x1, z1, use_motion)
if e >= 0 and _enemies.hit_t <= world_t:
var t := _enemies.type[e]
_enemies.apply_hit(e, damage)
_enemies.apply_hit(e, damage, by)
hits_enemy += 1
hit.emit(Vector3(lerpf(x0, x1, _enemies.hit_t), h, lerpf(z0, z1, _enemies.hit_t)), t)
return true
@ -187,5 +194,6 @@ func _release(i: int) -> void:
_life[i] = _life[last]
_damage[i] = _damage[last]
_speed[i] = _speed[last]
_owner[i] = _owner[last]
_renderer.move_slot(last, i)
active_count -= 1

View file

@ -368,7 +368,9 @@ func step(dt: float) -> void:
for a in avatars:
var building := build.active if a.is_local else (a.remote != null and a.remote.build_active)
if a.kit.can_shoot() and a.interactions.can_shoot() and not building:
enemies.attacker = a.slot # its kills (and its shots') are its own (Alien Goop)
a.combat.step(dt)
enemies.attacker = -1
enemies.step(dt, p, SCARECROW_RADIUS)
for a in avatars:
if a.kit.alive:
@ -497,10 +499,14 @@ func add_partner(local: bool, name_text: String = "") -> Avatar:
## Co-op: player 2 left. Their scarecrow goes; if player 1's is down, that's the end of the night.
func remove_partner() -> void:
## What they carried goes into the shed (on the host). Returns what moved (material -> amount).
func remove_partner() -> Dictionary:
if partner == null:
return
return {}
var a := partner
var moved := {} if replica else campaign.state.resources.deposit(a.slot)
if not moved.is_empty():
shed_stock.refresh()
partner = null
avatars.erase(a)
if camera is FollowCamera and (camera as FollowCamera).target == a.body:
@ -515,10 +521,12 @@ func remove_partner() -> void:
campaign.state.coop = false
behavior.scarecrow2 = Vector2(INF, INF)
enemies.scarecrow2 = Vector2(INF, INF)
return moved
## Makes another scarecrow this machine's own (the partner's machine plays player 2): the HUD,
## the camera, build mode, the upgrade menu, sounds, and tips follow it.
## the camera, build mode, the upgrade menu, the materials readout (its own pouch), sounds, and
## tips follow it.
func set_local(a: Avatar) -> void:
for other in avatars:
other.is_local = other == a
@ -538,8 +546,12 @@ func set_local(a: Avatar) -> void:
build.kit = a.kit
if upgrade_panel != null:
upgrade_panel.player = a.body
upgrade_panel.slot = a.slot
if shed_panel != null:
shed_panel.player = a.body
shed_panel.slot = a.slot
if resource_hud != null:
resource_hud.slot = a.slot
if camera is FollowCamera:
(camera as FollowCamera).target = a.body
(camera as FollowCamera).snap_to_target()
@ -625,19 +637,37 @@ func _count_removal(handle: int, reason: EnemySystem.Removal, _x: float, _z: flo
## 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:
## Co-op: into the killer's pouch (EnemySystem.killer_of); a turret's or a bomb's kill goes to the
## scarecrow nearest to it (goop_slot). Only the host rolls it: the partner's farm state follows.
func _drop_alien_goop(handle: int, reason: EnemySystem.Removal, x: float, z: float, _carry: int, _target: int) -> void:
if reason != EnemySystem.Removal.KILLED or replica:
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)
var slot := goop_slot(enemies.killer_of(handle), Vector2(x, z))
var added := campaign.state.resources.add_to_pouch("alien_goop", config.alien_goop_drop_qty, slot)
if added > 0:
campaign.state.record_event("gathered_alien_goop", added)
## Whose pouch a kill's goop goes to: the killer's (an avatar slot still on the farm), else the
## scarecrow nearest to where it fell, a standing one before a downed one (solo: always slot 0).
func goop_slot(killer: int, at: Vector2) -> int:
var best := -1
var best_d := INF
for a in avatars:
if a.slot == killer:
return killer
var d := a.position().distance_squared_to(at) + (0.0 if a.kit.alive else 1e12)
if d < best_d:
best_d = d
best = a.slot
return maxi(best, 0)
## 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)
@ -745,6 +775,7 @@ func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignContr
CampaignController.Phase.MORNING:
if partner == null and not replica:
campaign.state.coop = false # a co-op save continued alone: solo rules
campaign.state.resources.deposit(1) # and player 2's pouch, saved that morning, is in the shed
enemies.clear()
projectiles.clear()
bombs.clear()

View file

@ -4,11 +4,12 @@ extends RefCounted
## scarecrow health, campaign progress, and the nightly records. Scene nodes only display it.
## to_dict() / from_dict() round-trip every field, also through JSON (the morning retry
## snapshot and the save game, SaveGame). Crops and animals are per-unit records (lost ids, 1..total);
## supplies are the supply shed's stock of construction materials (the shed and the scarecrow's
## supplies are the supply shed's stock of construction materials (the shed and each scarecrow's
## pouch live in resources). Gather points below full, bought upgrades, and the built structures
## are kept too.
const VERSION := 6
## 7: a pouch per scarecrow (resources.partner_pouch, #16).
const VERSION := 7
const KEYS: Array[String] = [
"night", "nights_survived", "phase", "phase_time_left", "scarecrow_max_hp", "scarecrow_hp",
"crops_total", "lost_crops", "animals_total", "lost_animals", "penned_animals", "supplies_total",
@ -98,7 +99,7 @@ var supplies: int:
set(_value):
push_error("FarmState.supplies is derived from the shed's stock")
## Wood, scrap, and straw in the supply shed and in the scarecrow's pouch.
## The materials in the supply shed and in each scarecrow's pouch (by avatar slot).
var resources := ResourceStore.new()
## Charges of the gather points that are below full (GatherNode name -> charges left); a point
## missing here is full.
@ -217,10 +218,11 @@ func record_event(key: String, amount: int = 1) -> void:
night_events[key] = int(night_events.get(key, 0)) + amount
## Pays a cost from the pouch and shed (ResourceStore.pay) and counts what was spent. Every
## purchase (building, repairs, patching, upgrades) goes through here.
func pay(cost: Dictionary) -> bool:
if not resources.pay(cost):
## Pays a cost from the payer's pouch (its avatar slot; 0 solo) and the shed (ResourceStore.pay)
## and counts what was spent. Every purchase (building, repairs, patching, upgrades) goes through
## here.
func pay(cost: Dictionary, slot: int = 0) -> bool:
if not resources.pay(cost, slot):
return false
for m in cost:
if int(cost[m]) > 0:

View file

@ -31,7 +31,8 @@ extends Node3D
## In co-op each scarecrow has its own Interactions. The partner's, on the host, reads its
## RemoteControls (remote), asks the partner's game to open its own upgrade menu
## (workbench_requested / shed_requested), and leaves the gather labels to the local player's
## (show_labels).
## (show_labels). Each one gathers into, deposits, and pays from its own scarecrow's pouch
## (kit.slot, ResourceStore): a partner standing in the shed banks only their own pouch.
signal gathered(material: String, amount: int, node: GatherNode)
signal deposited(moved: Dictionary)
@ -179,8 +180,8 @@ func step(dt: float) -> void:
if shed_panel != null and shed_panel.is_open:
_step_menu(shed_panel, shed_counter, p, pressed)
return
if _shed != null and _shed.contains(player.global_position) and campaign.state.resources.pouch_total() > 0:
var moved := campaign.state.resources.deposit()
if _shed != null and _shed.contains(player.global_position) and campaign.state.resources.pouch_total(kit.slot) > 0:
var moved := campaign.state.resources.deposit(kit.slot)
deposited.emit(moved)
message.emit("Stored %s in the shed" % ResourceStore.describe(moved), Color(0.85, 0.95, 1.0))
if repairing >= 0:
@ -192,11 +193,11 @@ func step(dt: float) -> void:
var id := repairing
var cost := structures.repair_cost(id)
cancel()
if structures.repair(id):
if structures.repair(id, kit.slot):
message.emit("Repaired (%s)" % ResourceStore.describe(cost), Color(0.6, 1.0, 0.55))
return
if upgrading >= 0:
if not held or not campaign.is_daytime() or structures.upgrade_blocker(upgrading) != "":
if not held or not campaign.is_daytime() or structures.upgrade_blocker(upgrading, kit.slot) != "":
cancel()
return
upgrade_elapsed += dt
@ -204,7 +205,7 @@ func step(dt: float) -> void:
var id := upgrading
var cost := structures.upgrade_cost(id)
cancel()
if structures.upgrade(id):
if structures.upgrade(id, kit.slot):
message.emit("Upgraded to L%d (%s)" % [structures.level_of(id), ResourceStore.describe(cost)], Color(0.6, 1.0, 0.55))
return
if gathering != null:
@ -223,13 +224,13 @@ func step(dt: float) -> void:
focus = null
if held and not kit.patching:
var cost := structures.repair_cost(repair_target)
if campaign.state.resources.can_afford(cost):
if campaign.state.resources.can_afford(cost, kit.slot):
repairing = repair_target
repair_elapsed = 0.0
player.start_channel(&"Hammering")
elif not _denied:
_denied = true
message.emit("Not enough to repair: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost)), Color(1.0, 0.8, 0.5))
message.emit("Not enough to repair: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost, kit.slot)), Color(1.0, 0.8, 0.5))
return
upgrade_target = structures.upgradeable_near(p, REPAIR_REACH) if structures != null else -1
if upgrade_target >= 0:
@ -240,7 +241,7 @@ func step(dt: float) -> void:
_denied = true
message.emit("Upgrading is for daytime", Color(1.0, 0.8, 0.5))
else:
var why := structures.upgrade_blocker(upgrade_target)
var why := structures.upgrade_blocker(upgrade_target, kit.slot)
if why == "":
upgrading = upgrade_target
upgrade_elapsed = 0.0
@ -293,7 +294,7 @@ func _blocker(n: GatherNode) -> String:
return "Gathering is for daytime"
if charges(n) <= 0:
return "Nothing left here; it grows back overnight"
if campaign.state.resources.pouch_room() < n.yield_amount:
if campaign.state.resources.pouch_room(kit.slot) < n.yield_amount:
return "Pouch full: drop it off at the supply shed"
return ""
@ -303,7 +304,7 @@ func _blocker(n: GatherNode) -> String:
func _upgrade_prompt(id: int) -> String:
if not campaign.is_daytime():
return "Upgrading is for daytime"
var why := structures.upgrade_blocker(id)
var why := structures.upgrade_blocker(id, kit.slot)
if why == "":
return "[E / X] Upgrade to L%d (%s)" % [structures.level_of(id) + 1, ResourceStore.describe(structures.upgrade_cost(id))]
return why
@ -336,7 +337,7 @@ func regen_overnight() -> void:
func _finish_gather() -> void:
var n := gathering
var s := campaign.state
var added := s.resources.add_to_pouch(n.material, n.yield_amount)
var added := s.resources.add_to_pouch(n.material, n.yield_amount, kit.slot)
var left := charges(n) - 1
s.gather_charges[String(n.name)] = left
cancel()

View file

@ -1,9 +1,11 @@
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.
## Top-right materials readout: what the supply shed holds, and what this machine's scarecrow
## carries in its own pouch (with its capacity). A line flashes when its numbers change.
var campaign: CampaignController
## The avatar slot whose pouch is shown (FarmSim.set_local: the partner's machine shows P2's).
var slot: int = 0
## Set by FarmSim: shows how many structures stand.
var structures: StructureSystem
@ -34,7 +36,8 @@ func _process(delta: float) -> void:
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"]
var total := r.pouch_total(slot)
var pouch := "Pouch %d/%d %s" % [total, r.pouch_capacity, _amounts(r.pouch_of(slot)) if total > 0 else "empty"]
if shed != _last_shed:
_last_shed = shed
_shed.text = shed

View file

@ -1,24 +1,48 @@
class_name ResourceStore
extends RefCounted
## The farm's construction materials (wood, scrap, straw, alien goop): stock stored in the supply
## shed, and what the scarecrow carries in its pouch (pouch_capacity units across all materials).
## The pouch empties into the shed when the scarecrow walks in. Costs are paid all-or-nothing,
## from the pouch first and then the shed. Only shed stock can be stolen.
## shed, and what each scarecrow carries in its own pouch (pouch_capacity units across all
## materials; one capacity shared by every pouch). A pouch empties into the shed when its
## scarecrow walks in. Costs are paid all-or-nothing, from the payer's pouch first and then the
## shed. Only shed stock can be stolen.
## Pouches go by avatar slot (Avatar.slot): 0 is player 1 (the solo player, or the host in
## co-op), 1 is player 2 (the partner). Every pouch method takes the slot and defaults to 0, so
## solo callers never name one; `pouch` is slot 0's.
## Methods that sum across MATERIALS read with get(m, 0): a shed/pouch dict built or replaced
## elsewhere (tests, old saves) without every material present is treated as 0 for the rest,
## rather than erroring.
const MATERIALS: Array[String] = ["wood", "scrap", "straw", "alien_goop"]
## How many pouches there are (one per avatar slot), and their keys in to_dict(), by slot.
const SLOTS := 2
const POUCH_KEYS: Array[String] = ["pouch", "partner_pouch"]
var shed := {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
var pouch := {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
## Each scarecrow's pouch, by avatar slot.
var pouches: Array[Dictionary] = [
{"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0},
{"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0},
]
## Player 1's pouch (slot 0): the solo player's, or the host's.
var pouch: Dictionary:
get:
return pouches[0]
set(value):
pouches[0] = value
## Shared by every pouch: one Bigger pouch upgrade grows them all.
var pouch_capacity: int = 15
func pouch_total() -> int:
## The pouch of an avatar slot (an out-of-range slot reads as the nearest valid one).
func pouch_of(slot: int = 0) -> Dictionary:
return pouches[clampi(slot, 0, SLOTS - 1)]
func pouch_total(slot: int = 0) -> int:
var p := pouch_of(slot)
var n := 0
for m in MATERIALS:
n += int(pouch.get(m, 0))
n += int(p.get(m, 0))
return n
@ -40,61 +64,71 @@ func most_stocked() -> String:
return best
func pouch_room() -> int:
return maxi(pouch_capacity - pouch_total(), 0)
func pouch_room(slot: int = 0) -> int:
return maxi(pouch_capacity - pouch_total(slot), 0)
## Puts up to amount into the pouch, as much as fits. Returns how much went in.
func add_to_pouch(material: String, amount: int) -> int:
var added := mini(maxi(amount, 0), pouch_room())
pouch[material] = int(pouch.get(material, 0)) + added
## Puts up to amount into a slot's pouch, as much as fits. Returns how much went in.
func add_to_pouch(material: String, amount: int, slot: int = 0) -> int:
var p := pouch_of(slot)
var added := mini(maxi(amount, 0), pouch_room(slot))
p[material] = int(p.get(material, 0)) + added
return added
## Moves the whole pouch into the shed. Returns what moved (material -> amount, only non-zero).
func deposit() -> Dictionary:
## Moves a slot's whole pouch into the shed. Returns what moved (material -> amount, only
## non-zero).
func deposit(slot: int = 0) -> Dictionary:
var p := pouch_of(slot)
var moved := {}
for m in MATERIALS:
var n := int(pouch.get(m, 0))
var n := int(p.get(m, 0))
if n > 0:
shed[m] = int(shed.get(m, 0)) + n
pouch[m] = 0
p[m] = 0
moved[m] = n
return moved
func available(material: String) -> int:
return int(shed.get(material, 0)) + int(pouch.get(material, 0))
## What a slot's scarecrow can spend of a material: the shed's stock plus its own pouch.
func available(material: String, slot: int = 0) -> int:
return int(shed.get(material, 0)) + int(pouch_of(slot).get(material, 0))
## What a cost still lacks (material -> amount short; empty when affordable).
func missing(cost: Dictionary) -> Dictionary:
## What a cost still lacks for a slot's scarecrow (material -> amount short; empty when
## affordable).
func missing(cost: Dictionary, slot: int = 0) -> Dictionary:
var short := {}
for m in cost:
var need := int(cost[m]) - available(String(m))
var need := int(cost[m]) - available(String(m), slot)
if need > 0:
short[m] = need
return short
func can_afford(cost: Dictionary) -> bool:
return missing(cost).is_empty()
func can_afford(cost: Dictionary, slot: int = 0) -> bool:
return missing(cost, slot).is_empty()
## Pays a cost from the pouch first, then the shed. Pays nothing and returns false if short.
func pay(cost: Dictionary) -> bool:
if not can_afford(cost):
## Pays a cost from a slot's pouch first, then the shed (never another scarecrow's pouch). Pays
## nothing and returns false if short.
func pay(cost: Dictionary, slot: int = 0) -> bool:
if not can_afford(cost, slot):
return false
var p := pouch_of(slot)
for m in cost:
var need := int(cost[m])
var from_pouch := mini(need, int(pouch[m]))
pouch[m] = int(pouch[m]) - from_pouch
shed[m] = int(shed[m]) - (need - from_pouch)
var from_pouch := mini(need, int(p.get(m, 0)))
p[m] = int(p.get(m, 0)) - from_pouch
shed[m] = int(shed.get(m, 0)) - (need - from_pouch)
return true
func to_dict() -> Dictionary:
return {"shed": _filled(shed), "pouch": _filled(pouch), "pouch_capacity": pouch_capacity}
var d := {"shed": _filled(shed), "pouch_capacity": pouch_capacity}
for slot in SLOTS:
d[POUCH_KEYS[slot]] = _filled(pouches[slot])
return d
## A copy with every material present (one missing from shed/pouch, e.g. because it was replaced
@ -108,23 +142,29 @@ static func _filled(d: Dictionary) -> Dictionary:
return out
## Returns null for unknown materials, negative amounts, or an overfull pouch. A material missing
## from shed/pouch (an older save from before it existed, e.g. Alien Goop) is treated as 0, not
## rejected, so new materials stay load-compatible with old saves.
## Returns null for a missing part (the shed, either pouch, the capacity), unknown materials,
## negative amounts, or an overfull pouch. A material missing from the shed or a pouch (an older
## save from before it existed, e.g. Alien Goop) is treated as 0, not rejected, so new materials
## stay load-compatible with old saves.
static func from_dict(d: Variant) -> ResourceStore:
if not d is Dictionary:
return null
var dd := d as Dictionary
if not (dd.get("shed") is Dictionary and dd.get("pouch") is Dictionary and dd.has("pouch_capacity")):
if not (dd.get("shed") is Dictionary and dd.has("pouch_capacity")):
return null
for key in POUCH_KEYS:
if not dd.get(key) is Dictionary:
return null
var r := ResourceStore.new()
r.pouch_capacity = int(dd["pouch_capacity"])
for part in ["shed", "pouch"]:
var parts: Array[String] = ["shed"]
parts.append_array(POUCH_KEYS)
for part in parts:
var src: Dictionary = dd[part]
for key in src:
if not MATERIALS.has(String(key)):
return null # unknown material
var into: Dictionary = r.shed if part == "shed" else r.pouch
var into: Dictionary = r.shed if part == "shed" else r.pouches[POUCH_KEYS.find(part)]
for m in MATERIALS:
if src.has(m):
if int(src[m]) < 0:
@ -132,7 +172,12 @@ static func from_dict(d: Variant) -> ResourceStore:
into[m] = int(src[m])
else:
into[m] = 0
return r if r.pouch_capacity >= 1 and r.pouch_total() <= r.pouch_capacity else null
if r.pouch_capacity < 1:
return null
for slot in SLOTS:
if r.pouch_total(slot) > r.pouch_capacity:
return null
return r
## "6 wood, 2 straw" for a material -> amount dictionary (in MATERIALS order).

View file

@ -128,7 +128,11 @@ func refresh() -> void:
if animals != null and animals.pen_open and s.animals > 0:
lines.append("The pen is open: put a gate in its opening (B) before nightfall, or animals will wander out.")
var r := s.resources
lines.append("In the shed: %s. In the pouch: %s." % [_or_none(ResourceStore.describe(r.shed)), _or_none(ResourceStore.describe(r.pouch))])
if s.coop: # each scarecrow carries its own
lines.append("In the shed: %s. %s's pouch: %s. %s's pouch: %s." % [_or_none(ResourceStore.describe(r.shed)),
Avatar.NAMES[0], _or_none(ResourceStore.describe(r.pouch_of(0))), Avatar.NAMES[1], _or_none(ResourceStore.describe(r.pouch_of(1)))])
else:
lines.append("In the shed: %s. In the pouch: %s." % [_or_none(ResourceStore.describe(r.shed)), _or_none(ResourceStore.describe(r.pouch))])
var plan := waves.tonight() if waves != null else null
if plan != null and plan.title != "":
if structures != null and structures.has_workbench():

View file

@ -107,6 +107,16 @@ static func migrate(d: Dictionary) -> Dictionary:
if entry is Dictionary and not (entry as Dictionary).has("level"):
entry["level"] = 1
out["version"] = 6
6:
# Version 7 gives each scarecrow its own pouch (#16): the old shared one becomes player
# 1's (resources.pouch, unchanged), and player 2's starts empty.
var res: Variant = out.get("resources")
if res is Dictionary and not (res as Dictionary).has("partner_pouch"):
var empty := {}
for m in ResourceStore.MATERIALS:
empty[m] = 0
res["partner_pouch"] = empty
out["version"] = 7
_:
return {}
return out

View file

@ -16,8 +16,8 @@ extends Node3D
## into Game Over on the same tick (in co-op only once both have fallen: until then it's out
## until the morning). Every new morning, also after a retry, revives it with fear ready.
## In co-op there are two kits: slot 0 (player 1) uses FarmState.scarecrow_hp, slot 1 (player 2)
## partner_hp. A kit whose remote is set (the partner's, on the host) reads RemoteControls
## instead of the local input.
## partner_hp, and each patches with straw from its own pouch (and the shed). A kit whose remote
## is set (the partner's, on the host) reads RemoteControls instead of the local input.
signal damaged(hp: int)
signal fear_used(position: Vector3, scared: int)
@ -145,10 +145,10 @@ func step_patch(dt: float, held: bool) -> void:
if not patching:
if hp() >= max_hp() or (interactions != null and interactions.channeling()):
return
if not s.resources.can_afford(cost):
if not s.resources.can_afford(cost, slot):
if not _patch_denied: # once per press
_patch_denied = true
patch_denied.emit(s.resources.missing(cost))
patch_denied.emit(s.resources.missing(cost, slot))
return
patching = true
patch_elapsed = 0.0
@ -156,7 +156,7 @@ func step_patch(dt: float, held: bool) -> void:
patch_elapsed += dt
if patch_elapsed >= config.patch_time:
_end_patch()
if s.pay(cost):
if s.pay(cost, slot):
_set_hp(hp() + config.patch_heal)
s.record_event("patches")
patched.emit(hp())

View file

@ -197,8 +197,9 @@ static func corners(fp: Dictionary, shrink_long: float = 0.0, shrink_wide: float
return pts
## Why a structure can't go here ("" if it can). Space first, then daytime, then the cost.
func validate(type: String, x: float, z: float, rot: int, scarecrow: Vector2) -> String:
## Why a structure can't go here ("" if it can). Space first, then daytime, then the cost (from
## the builder's pouch, its avatar slot, and the shed).
func validate(type: String, x: float, z: float, rot: int, scarecrow: Vector2, slot: int = 0) -> String:
var fp := footprint(type, x, z, rot)
var outline := corners(fp)
var inside := zones.playable.grow(-0.3)
@ -232,15 +233,16 @@ func validate(type: String, x: float, z: float, rot: int, scarecrow: Vector2) ->
if not campaign.is_daytime():
return "Building is for daytime"
var cost: Dictionary = config.costs.get(type, {})
if not campaign.state.resources.can_afford(cost):
return "Not enough: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost))
if not campaign.state.resources.can_afford(cost, slot):
return "Not enough: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost, slot))
return ""
## Builds after validate() passed: pays, records, shows, and updates navigation. Returns the id.
func place(type: String, x: float, z: float, rot: int) -> int:
## Builds after validate() passed: pays (from the builder's pouch, its avatar slot, and the shed),
## records, shows, and updates navigation. Returns the id.
func place(type: String, x: float, z: float, rot: int, slot: int = 0) -> int:
var s := campaign.state
if not s.pay(config.costs.get(type, {})):
if not s.pay(config.costs.get(type, {}), slot):
return -1
var id := s.next_structure_id
s.next_structure_id += 1
@ -365,10 +367,11 @@ func repair_cost(id: int) -> Dictionary:
return out
## Pays and repairs fully. Returns false if there was nothing to repair or it couldn't be paid.
func repair(id: int) -> bool:
## Pays (from the repairer's pouch, its avatar slot, and the shed) and repairs fully. Returns
## false if there was nothing to repair or it couldn't be paid.
func repair(id: int, slot: int = 0) -> bool:
var cost := repair_cost(id)
if cost.is_empty() or not campaign.state.pay(cost):
if cost.is_empty() or not campaign.state.pay(cost, slot):
return false
var e := campaign.state.structure(id)
e["hp"] = max_hp(e["type"])
@ -393,8 +396,9 @@ func upgrade_cost(id: int) -> Dictionary:
## Why id can't be upgraded right now ("" if it can): levelable, undamaged (repair takes
## priority), under MAX_LEVEL, a bigger tar patch footprint clear of neighbors and the world, and
## the cost affordable. Doesn't check the time of day (Interactions, like the build-mode rules).
func upgrade_blocker(id: int) -> String:
## the cost affordable (from the upgrader's pouch, its avatar slot, and the shed). Doesn't check
## the time of day (Interactions, like the build-mode rules).
func upgrade_blocker(id: int, slot: int = 0) -> String:
var e := campaign.state.structure(id)
if e.is_empty() or not is_levelable(e["type"]):
return "Can't be upgraded"
@ -415,17 +419,17 @@ func upgrade_blocker(id: int) -> String:
return "Not enough room to upgrade"
if _world_blocked(fp):
return "Not enough room to upgrade"
if not campaign.state.resources.can_afford(cost):
return "Not enough: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost))
if not campaign.state.resources.can_afford(cost, slot):
return "Not enough: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost, slot))
return ""
## Pays and levels a structure up by one (see upgrade_blocker). Returns false if it couldn't be.
func upgrade(id: int) -> bool:
if upgrade_blocker(id) != "":
func upgrade(id: int, slot: int = 0) -> bool:
if upgrade_blocker(id, slot) != "":
return false
var cost := upgrade_cost(id)
if not campaign.state.pay(cost):
if not campaign.state.pay(cost, slot):
return false
var e := campaign.state.structure(id)
e["level"] = int(e.get("level", 1)) + 1

View file

@ -119,7 +119,7 @@ func _wanted(id: String) -> bool:
"gather":
return day and done.has("move")
"store":
return day and c.state.resources.pouch_total() > 0
return day and c.state.resources.pouch_total(sim.local_avatar.slot) > 0
"build":
return day and (done.has("store") or c.state.phase_time_left < c.phase_length(CampaignController.Phase.DAY) * 0.5
or phase == CampaignController.Phase.DUSK)

View file

@ -20,6 +20,9 @@ var is_open := false
var shop := "workbench"
## Co-op partner: ask the host to buy (upgrade id); the result comes back as a message.
var buy_request: Callable
## The avatar slot of this machine's scarecrow (FarmSim.set_local): what's affordable is its own
## pouch plus the shed.
var slot: int = 0
var _rows := {} # upgrade id -> Button
var _title: Label
@ -115,7 +118,7 @@ func refresh() -> void:
for id: String in _rows:
var u: Dictionary = cfg.upgrades[id]
var b := _rows[id] as Button
var why := Upgrades.blocker(campaign, id)
var why := Upgrades.blocker(campaign, id, slot)
if Upgrades.owned(s, id):
done += 1
if not Upgrades.revealed(s, cfg, id):
@ -137,7 +140,7 @@ func _buy(id: String) -> void:
buy_request.call(id)
return
var was := Upgrades.owned(campaign.state, id)
var text := Upgrades.buy(campaign, id, structures)
var text := Upgrades.buy(campaign, id, structures, slot)
if not was and Upgrades.owned(campaign.state, id):
bought.emit(id)
message.emit(text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5))

View file

@ -9,7 +9,8 @@ extends RefCounted
## of reading GameConfig directly: the corn shooter's fire rate and shot damage, fear's radius and
## cooldown, fences' and gates' health (barrier_hp), the automated defense's range, and the traps'
## slow time. Straw stuffing raises the scarecrow's max health (FarmState) when bought, and the
## Bigger pouch upgrade raises pouch_capacity (ResourceStore) the same way. Sprint, the corn
## Bigger pouch upgrade raises pouch_capacity (ResourceStore, shared: every scarecrow's pouch
## grows) the same way. The buyer pays from their own pouch and the shed (slot). Sprint, the corn
## shooter, and pumpkin bombs change no stat: owning them unlocks sprinting (PlayerCharacter) and
## the two weapons (ScarecrowCombat). Rapid fire and heavy seeds (bought at the workbench) need
## the corn shooter (bought at the shed) first ("requires" crosses shops freely).
@ -73,8 +74,9 @@ static func value(cfg: GameConfig, state: FarmState, stat: String) -> float:
return v
## Why an upgrade can't be bought right now ("" if it can).
static func blocker(campaign: CampaignController, id: String) -> String:
## Why an upgrade can't be bought right now ("" if it can), by the scarecrow in this avatar slot
## (its pouch and the shed pay).
static func blocker(campaign: CampaignController, id: String, slot: int = 0) -> String:
var cfg := campaign.config
var s := campaign.state
if not cfg.upgrades.has(id):
@ -88,21 +90,22 @@ static func blocker(campaign: CampaignController, id: String) -> String:
return "Needs the %s first" % String(cfg.upgrades.get(needs, {}).get("name", needs)).to_lower()
if not campaign.is_daytime():
return "The work area is for daytime"
if not s.resources.can_afford(cost(cfg, id)):
return "Need %s more" % ResourceStore.describe(s.resources.missing(cost(cfg, id)))
if not s.resources.can_afford(cost(cfg, id), slot):
return "Need %s more" % ResourceStore.describe(s.resources.missing(cost(cfg, id), slot))
return ""
## Buys an upgrade if it can be bought. Returns the message for the player.
static func buy(campaign: CampaignController, id: String, structures: StructureSystem = null) -> String:
## Buys an upgrade if it can be bought, paid by the scarecrow in this avatar slot (its pouch,
## then the shed). Returns the message for the player.
static func buy(campaign: CampaignController, id: String, structures: StructureSystem = null, slot: int = 0) -> String:
var cfg := campaign.config
var s := campaign.state
var u: Dictionary = cfg.upgrades.get(id, {})
var why := blocker(campaign, id)
var why := blocker(campaign, id, slot)
if why != "":
return "%s: %s" % [u.get("name", id), why.to_lower() if why != "Done" else "already done"]
var barrier_before := value(cfg, s, "barrier_hp")
s.pay(cost(cfg, id))
s.pay(cost(cfg, id), slot)
s.upgrades[id] = 1
s.record_event("upgrades_bought")
match String(u.get("stat", "")):
@ -117,6 +120,6 @@ static func buy(campaign: CampaignController, id: String, structures: StructureS
for e in s.structures:
if e["type"] == "fence" or e["type"] == "gate":
e["hp"] = mini(roundi(int(e["hp"]) * k), structures.max_hp(e["type"]) if structures != null else 1 << 20)
"pouch_capacity": # the live value lives in ResourceStore, not read from cfg each time
"pouch_capacity": # the live value lives in ResourceStore (one for every pouch), not read from cfg each time
s.resources.pouch_capacity += int(u.get("add", 0))
return "%s done: %s" % [u.get("name", id), String(u.get("text", "")).to_lower()]

View file

@ -3,7 +3,9 @@ extends RefCounted
## with its own world (so the two don't share physics), joined by a loopback CoopLink and stepped
## by hand, tick by tick. Covers the join (the welcome, both scarecrows on both farms, names,
## co-op health), requests from the partner (start the day, build, buy), the partner's scarecrow
## moving, gathering, and shooting on the host (and its pick of weapon), the weapons' stabs and
## moving, gathering, and shooting on the host (and its pick of weapon), each scarecrow's own
## pouch (#16: gathering, the shed drop-off, paying, one shared capacity, goop to the killer, and
## the partner's pouch put in the shed when they leave), the weapons' stabs and
## pumpkin bombs (thrown from the off-hand, not with the right click leaving build mode) reaching the replica (drawn there, doing no damage of their own), enemies, loot,
## and shots reaching the replica,
## the co-op fall rule (one down is out until morning, both down is Game Over) and Retry, message
@ -14,6 +16,8 @@ extends RefCounted
const P := CampaignController.Phase
const DT := 1.0 / 60.0
const AWAY := Vector3(-11.0, 0.0, 13.0)
## Ticks for a change to the farm state to reach the partner (it goes out every STATE_EVERY).
const SETTLE := CoopSession.STATE_EVERY + 3
var r: GameTestRunner
var host_farm: Node3D
@ -33,8 +37,10 @@ func run(p_r: GameTestRunner) -> void:
_requests()
_quiet_wire()
await _partner_moves_and_gathers()
_own_pouches()
_night()
_partner_shoots()
_goop_to_killer()
_weapons_shown()
_fall_rule()
_crowd()
@ -170,7 +176,7 @@ func _partner_moves_and_gathers() -> void:
client.player.global_position = at
_pump(10)
r.check(host.partner.body.global_position.distance_to(at) < 0.3, "the host's copy of P2 follows the partner's own moves")
host.campaign.state.resources.pouch = {"wood": 0, "scrap": 0, "straw": 0}
_empty_pouches()
Input.action_press("interact")
_pump(roundi(host.config.gather_time * 60.0) - 20)
var gathering_there := client.interactions.gathering != null and String(client.interactions.gathering.name) == "DeadTree" and client.player.rooted
@ -178,12 +184,113 @@ func _partner_moves_and_gathers() -> void:
Input.action_release("interact")
_pump(20)
r.check(gathering_there, "while P2 gathers, the partner sees it (the channel, rooted) from the host")
r.check(int(host.campaign.state.resources.pouch["wood"]) >= 2 and int(client.campaign.state.resources.pouch["wood"]) >= 2
and int(host.campaign.state.night_events.get("gathered_wood", 0)) >= 2, "P2 gathered wood into the shared pouch (%s)" % [host.campaign.state.resources.pouch])
var res := host.campaign.state.resources
r.check(int(res.pouch_of(1).get("wood", 0)) >= 2 and int(client.campaign.state.resources.pouch_of(1).get("wood", 0)) >= 2
and int(host.campaign.state.night_events.get("gathered_wood", 0)) >= 2, "P2 gathered wood into P2's own pouch (%s)" % [res.pouch_of(1)])
r.check(res.pouch_total(0) == 0 and client.campaign.state.resources.pouch_total(0) == 0,
"and only P2's: P1's pouch stays empty (%s)" % [res.pouch_of(0)])
r.check(not client.player.rooted, "and is free to move again")
await r.process_frame
## The partner's copy of the materials (re-read each time: every farm state update replaces it).
func _mine() -> ResourceStore:
return client.campaign.state.resources
## Both scarecrows' pouches emptied (every material present, 0).
func _empty_pouches() -> void:
for slot in ResourceStore.SLOTS:
for m in ResourceStore.MATERIALS:
host.campaign.state.resources.pouch_of(slot)[m] = 0
## #16: a pouch per scarecrow, one shared shed. P1 standing in the shed banks only P1's own pouch
## (not what P2 carries); P2 banks its own by walking in; each pays for what it builds or buys
## from its own pouch and the shed, never the other's pouch (the host pays P2's requests from
## P2's); and one Bigger pouch grows both pouches. The partner's HUD, menus, and build mode go
## by P2's pouch.
func _own_pouches() -> void:
var res := host.campaign.state.resources
r.check(client.resource_hud != null and client.resource_hud.slot == 1 and client.upgrade_panel.slot == 1 and client.shed_panel.slot == 1
and client.build.kit.slot == 1 and host.resource_hud.slot == 0 and host.upgrade_panel.slot == 0,
"the partner's materials readout, menus, and build mode go by P2's pouch; the host's by P1's")
var carried := int(res.pouch_of(1).get("wood", 0))
var shed_rect := host.zones.zone(FarmZone.Kind.SUPPLY_SHED).rect()
var in_shed := Vector3(shed_rect.get_center().x, 0.0, shed_rect.get_center().y)
var shed_wood := int(res.shed.get("wood", 0))
res.pouch_of(0)["straw"] = 1 # P1 carries something of its own
var shed_straw := int(res.shed.get("straw", 0))
host.player.global_position = in_shed
_pump(4)
r.check(carried >= 2 and int(res.pouch_of(1).get("wood", 0)) == carried and int(res.shed.get("wood", 0)) == shed_wood,
"P1 standing in the shed doesn't bank P2's pouch (P2 still carries %d wood)" % carried)
r.check(res.pouch_total(0) == 0 and int(res.shed.get("straw", 0)) == shed_straw + 1, "it banks P1's own")
client.player.global_position = in_shed + Vector3(0.8, 0.0, 0.0)
_pump(SETTLE)
r.check(res.pouch_total(1) == 0 and int(res.shed.get("wood", 0)) == shed_wood + carried and _mine().pouch_total(1) == 0,
"P2 banks its own pouch by walking into the shed (on both farms)")
host.player.global_position = AWAY
# Building: P2's request is paid from P2's pouch and the shed, never P1's pouch.
client.player.global_position = Vector3(0.5, 0.0, 6.0)
_pump(12)
var fence: Dictionary = host.config.costs["fence"]
var wood := int(fence.get("wood", 0))
res.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
_empty_pouches()
res.pouch_of(0)["wood"] = wood + 1
res.pouch_of(1)["wood"] = wood - 1
_pump(6)
var before := host.structures.count()
client.build.place_request.call("fence", 0.5, 4.0, 0)
_pump(20)
r.check(host.structures.count() == before and int(res.pouch_of(0)["wood"]) == wood + 1 and int(res.pouch_of(1)["wood"]) == wood - 1,
"P2 can't build a fence with P1's wood: P2's pouch and the shed are short, so the host refuses")
res.shed["wood"] = 1
_pump(SETTLE)
r.check(host.structures.validate("fence", 0.5, 4.0, 0, host.partner.position(), 1) == ""
and client.structures.validate("fence", 0.5, 4.0, 0, client.local_avatar.position(), 1) == "",
"with 1 wood in the shed P2 can afford it (checked on both farms, P2's pouch)")
client.build.place_request.call("fence", 0.5, 4.0, 0)
_pump(20)
r.check(host.structures.count() == before + 1 and int(res.pouch_of(1)["wood"]) == 0 and int(res.shed["wood"]) == 0
and int(res.pouch_of(0)["wood"]) == wood + 1 and client.structures.count() == before + 1,
"P2 builds it, paying from P2's pouch first, then the shed; P1's wood is untouched")
# P1 builds the way its build mode does (solo's calls: no slot, so player 1's pouch).
host.player.global_position = Vector3(1.5, 0.0, 6.0)
r.check(host.structures.validate("fence", 0.5, 2.5, 0, host.avatars[0].position()) == ""
and host.structures.place("fence", 0.5, 2.5, 0) > 0 and int(res.pouch_of(0)["wood"]) == 1 and int(res.pouch_of(1)["wood"]) == 0,
"and P1 building pays from P1's own pouch")
host.player.global_position = AWAY
# Buying: one Bigger pouch, bought by P2 at the work area, paid from P2's pouch and the shed;
# it grows both pouches.
host.structures.grant_workbench()
_pump(4)
var cost: Dictionary = host.config.costs["pouch_upgrade"]
var room := res.pouch_capacity
_empty_pouches()
res.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
for m: String in cost: # P2 carries what fits; the shed has the rest
var take := mini(int(cost[m]), res.pouch_room(1))
res.pouch_of(1)[m] = take
res.shed[m] = int(cost[m]) - take
res.pouch_of(0)["scrap"] = 3 # P1's, kept
_pump(SETTLE)
client.upgrade_panel.refresh()
r.check(Upgrades.blocker(client.campaign, "pouch_upgrade", 1) == "" and Upgrades.blocker(client.campaign, "pouch_upgrade", 0) != ""
and not (client.upgrade_panel._rows["pouch_upgrade"] as Button).disabled,
"the partner's menu offers the Bigger pouch by P2's pouch and the shed (P1's couldn't pay)")
client.upgrade_panel.buy_request.call("pouch_upgrade")
_pump(SETTLE * 2)
r.check(Upgrades.owned(host.campaign.state, "pouch_upgrade") and res.pouch_total(1) == 0 and res.shed_total() == 0
and int(res.pouch_of(0)["scrap"]) == 3, "P2 buys it: paid from P2's pouch and the shed, P1's pouch untouched")
r.check(res.pouch_capacity > room and res.pouch_room(0) == res.pouch_capacity - 3 and res.pouch_room(1) == res.pouch_capacity
and _mine().pouch_capacity == res.pouch_capacity and _mine().pouch_room(1) == res.pouch_capacity,
"one Bigger pouch grows both pouches (%d -> %d units, on both farms)" % [room, res.pouch_capacity])
_empty_pouches()
_pump(6)
func _night() -> void:
host.campaign.advance_phase()
host.campaign.advance_phase()
@ -240,6 +347,63 @@ func _partner_shoots() -> void:
r.check(client.projectiles.fired == 0, "(the partner's own gun only aims: it fired nothing itself)")
## #16: an Alien's goop goes to its killer's pouch (here P2's corn shot, with P1 standing nearer),
## and a kill no scarecrow made itself (a pumpkin bomb's or a turret's) to the nearest scarecrow.
func _goop_to_killer() -> void:
var cfg := host.config
var chance := cfg.alien_goop_drop_chance
cfg.alien_goop_drop_chance = 1.0
var res := host.campaign.state.resources
_empty_pouches()
for i in 240: # P2's last shots fly out
if host.projectiles.active_count == 0:
break
_pump()
client.player.global_position = Vector3(8.0, 0.0, -10.0)
client.combat.aim = Vector2(1.0, 0.0)
_pump(6)
Input.action_press("fire")
var shot := PackedFloat32Array()
for i in 30:
_pump()
shot = host.projectiles.replica_record(1)
if shot.size() == 4:
break
Input.action_release("fire")
var es := host.enemies
var h := -1
var p1_nearer := false
if shot.size() == 4:
# An Alien just ahead of P2's shot, P1 beside it (nearer than P2, out of the shot's way).
var ahead := Vector2(shot[0], shot[1]) + Vector2(shot[2], shot[3]) * 1.5
host.player.global_position = Vector3(ahead.x + 0.5, 0.0, ahead.y - 1.5)
p1_nearer = host.avatars[0].position().distance_to(ahead) < host.partner.position().distance_to(ahead)
h = es.spawn(EnemySystem.TYPE_THIEF, ahead.x, ahead.y, Vector2.UP)
es.health[es.resolve_handle(h)] = 1
for i in 20:
_pump()
if es.resolve_handle(h) < 0:
break
r.check(h >= 0 and es.resolve_handle(h) < 0 and int(res.pouch_of(1).get("alien_goop", 0)) == cfg.alien_goop_drop_qty
and int(res.pouch_of(0).get("alien_goop", 0)) == 0 and p1_nearer,
"P2's shot kills an Alien: its goop goes into P2's pouch, not P1's (nearer) (P2 %s, P1 %s)" % [res.pouch_of(1), res.pouch_of(0)])
_pump(SETTLE)
r.check(int(_mine().pouch_of(1).get("alien_goop", 0)) == cfg.alien_goop_drop_qty, "(on both farms)")
_empty_pouches()
for who in [0, 1]:
var a := host.avatars[who]
var at := a.position() + Vector2(0.6, 0.0)
var hh := es.spawn(EnemySystem.TYPE_THIEF, at.x, at.y, Vector2.UP)
es.apply_hit_handle(hh, 99) # as a pumpkin bomb's burst or a turret's shot: no scarecrow's own hit
_pump()
r.check(int(res.pouch_of(0).get("alien_goop", 0)) == cfg.alien_goop_drop_qty and int(res.pouch_of(1).get("alien_goop", 0)) == cfg.alien_goop_drop_qty,
"a bomb's or a turret's kill goes to the scarecrow nearest to it (one each)")
cfg.alien_goop_drop_chance = chance
_empty_pouches()
host.player.global_position = AWAY
_pump(4)
func _weapons_shown() -> void:
var p1 := client.avatars[0].combat # the host's scarecrow, on the partner's farm
p1.models._attack_t = -1.0
@ -317,6 +481,10 @@ func _crowd() -> void:
host.campaign.advance_phase()
for i in 90:
host.spawn_enemy([EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER][i % 3])
# The drop pattern starts here: the loopback counts every message sent so far, so without this
# the earlier cases' traffic would decide which records are lost (a strictly periodic drop can
# hit all three copies of an enemy's record).
(links[0] as CoopLink.Loopback)._count = 0
links[0].drop_every = 3 # a third of the unreliable messages lost
_pump(60)
r.check(client.enemies.alive_count() == host.enemies.alive_count() and host.enemies.alive_count() > 40,
@ -345,15 +513,30 @@ func _crowd() -> void:
func _leaving() -> void:
var gone: Array[String] = []
cs.ended.connect(func(why: String) -> void: gone.append(why))
var res := host.campaign.state.resources
_empty_pouches()
res.pouch_of(1)["alien_goop"] = 2 # what P2 carries when they go (goop: no thief goes for it here)
var goop := int(res.shed.get("alien_goop", 0))
links[1].close() # the partner quits
_pump(2)
r.check(not hs.is_active() and host.partner == null and host.avatars.size() == 1 and not host.campaign.state.coop
and not is_instance_valid(host.get_parent().get_node_or_null("Player2")) or host.get_parent().get_node("Player2").is_queued_for_deletion(),
"the partner leaves: the host plays on alone")
r.check(res.pouch_total(1) == 0 and int(res.shed.get("alien_goop", 0)) == goop + 2,
"what the partner carried is put in the shed (%s)" % [res.shed])
r.check(not cs.is_active() and gone.size() == 1, "and the partner's game is told the session is over ('%s')" % (gone[0] if not gone.is_empty() else ""))
host.campaign.state.coop = true # as a co-op morning's save would have it
host.campaign.retry_night()
r.check(not host.campaign.state.coop, "a co-op morning played alone goes back to the solo rules")
var snap := host.campaign.morning_snapshot()
snap["coop"] = true
snap["resources"]["partner_pouch"]["wood"] = 3 # the save of a morning P2 carried something
var shed_wood := int(snap["resources"]["shed"]["wood"])
host.campaign._morning_snapshot = snap
host.campaign.retry_night()
res = host.campaign.state.resources
r.check(res.pouch_total(1) == 0 and int(res.shed["wood"]) == shed_wood + 3,
"and P2's pouch from that morning goes into the shed, so nothing is stranded")
## Voice chat's sending, without GD-Sync: the gate, the pieces, and the codec.

View file

@ -10,7 +10,8 @@ extends RefCounted
## 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.
## (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.
const P := CampaignController.Phase
const DT := 1.0 / 60.0
@ -18,6 +19,7 @@ const DT := 1.0 / 60.0
func run(r: GameTestRunner) -> void:
_store(r)
_pouches(r)
_state(r)
_goop_persistence(r)
_pouch_upgrade(r)
@ -64,7 +66,9 @@ func _store(r: GameTestRunner) -> void:
"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()
@ -74,6 +78,37 @@ func _store(r: GameTestRunner) -> void:
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)
@ -125,6 +160,7 @@ func _pouch_upgrade(r: GameTestRunner) -> void:
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("already done"), "it can only be bought once")
# It carries into the next morning (same mechanic as straw_stuffing/scarecrow_max_hp).

View file

@ -1,7 +1,7 @@
extends RefCounted
## Saving and settings without the farm scene: a save written and read back reproduces the farm
## state field for field; missing, damaged, newer, and too-old saves are refused with a reason
## and version 2 saves are upgraded; the campaign autosaves every morning, a retry restores that
## and version 2 and 6 saves are upgraded; the campaign autosaves every morning, a retry restores that
## morning, and finishing the vacation deletes the save; settings persist, fall back on bad
## values, and apply to the audio buses, the dead zones, and the config; and the final
## assessment's score and tiers.
@ -41,6 +41,8 @@ static func busy_state(cfg: GameConfig) -> FarmState:
s.lose_animal(2)
s.resources.shed = {"wood": 13, "scrap": 2, "straw": 21}
s.resources.pouch = {"wood": 0, "scrap": 3, "straw": 1}
s.resources.pouch_of(1)["wood"] = 2 # player 2's own pouch (#16)
s.resources.pouch_of(1)["alien_goop"] = 1
s.gather_charges = {"DeadTree": 1, "Haystack": 0}
s.upgrades = {"rapid_fire": 1, "sticky_tar": 1}
s.structures.append({"id": s.next_structure_id, "type": "fence", "x": 30.5, "z": -18.5, "rot": 3, "hp": 11, "level": 1})
@ -136,6 +138,23 @@ func _migration(r: GameTestRunner) -> void:
r.check(e["crops_stolen"] == s.night_log[1]["crops_stolen"] and e["killed_crow"] == 0 and e["gathered_wood"] == 0
and loaded.state.scarecrow_hp == 7 and loaded.state.structures.size() == s.structures.size(),
"keeping what it had and counting the new nightly records from zero")
# Version 6 (#16): one shared pouch, no partner_pouch. It becomes player 1's; player 2's is empty.
d = s.to_dict()
d["version"] = 6
(d["resources"] as Dictionary).erase("partner_pouch")
SaveGame.write(d, SAVE)
loaded = SaveGame.read(SAVE)
r.check(loaded.status == SaveGame.Status.OK and loaded.version == 6 and loaded.state != null,
"a version 6 save (one shared pouch) is upgraded and loads (%s)" % loaded.message)
if loaded.state == null:
return
var res := loaded.state.resources
r.check(res.to_dict()["pouch"] == s.resources.to_dict()["pouch"] and res.pouch_total(1) == 0
and res.to_dict()["shed"] == s.resources.to_dict()["shed"] and res.pouch_capacity == s.resources.pouch_capacity,
"its pouch is player 1's, unchanged; player 2's starts empty")
var migrated := SaveGame.migrate(d)
r.check(int(migrated["version"]) == FarmState.VERSION and migrated["resources"].has("partner_pouch")
and not d["resources"].has("partner_pouch"), "migrate() adds partner_pouch to a copy, not the original")
func _autosave(r: GameTestRunner) -> void:

View file

@ -221,8 +221,11 @@ func _cycles(n: int) -> void:
_carry_errors.append("cycle %d: %d structures at night - %d broken != %d in the morning" % [k + 1, built_night, broken, _sim.structures.count()])
var now := s.resources.to_dict()
for m in ["wood", "scrap"]:
var before := int(res_night["shed"][m]) + int(res_night["pouch"][m])
var after := int(now["shed"][m]) + int(now["pouch"][m])
var before := int(res_night["shed"][m])
var after := int(now["shed"][m])
for key in ResourceStore.POUCH_KEYS: # every scarecrow's pouch (solo: player 2's stays empty)
before += int(res_night[key][m])
after += int(now[key][m])
if after != before - int(lost_by.get(m, 0)):
_carry_errors.append("cycle %d: %s %d -> %d overnight, %d carried off" % [k + 1, m, before, after, int(lost_by.get(m, 0))])
if s.supplies_in_transit != 0: