Merge task #16: each co-op player has their own pouch

The shed stays shared; pouches are per avatar slot with one shared
capacity. Gather/deposit/pay paths take the acting slot, goop goes to
the killer, a leaving partner's pouch goes into the shed. FarmState v7
(partner_pouch), CoopSession PROTOCOL 4.

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

View file

@ -371,7 +371,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:
@ -500,10 +502,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:
@ -518,10 +524,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
@ -541,8 +549,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()
@ -628,19 +640,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)
@ -748,6 +778,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()