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:
parent
26b735d3e6
commit
fa7f67fe04
23 changed files with 535 additions and 138 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue