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