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
|
|
@ -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)])
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue