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
|
|
@ -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