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
|
|
@ -34,6 +34,9 @@ var _life := PackedFloat32Array()
|
|||
## Cannon, Shurikens, and Alien Ray fly at their own speeds).
|
||||
var _speed := PackedFloat32Array()
|
||||
var _damage := PackedInt32Array()
|
||||
## The avatar slot that fired each shot (EnemySystem.attacker when it was fired; -1 for the
|
||||
## automated defenses'), credited with what it kills (co-op Alien Goop).
|
||||
var _owner := PackedInt32Array()
|
||||
var _cfg: GameConfig
|
||||
var _enemies: EnemySystem
|
||||
var _bounds: Rect2
|
||||
|
|
@ -50,6 +53,7 @@ func setup(cfg: GameConfig, enemies: EnemySystem, bounds: Rect2, shooter: RID) -
|
|||
a.resize(capacity)
|
||||
a.fill(0.0)
|
||||
_damage.resize(capacity)
|
||||
_owner.resize(capacity)
|
||||
_ray.collision_mask = WORLD_LAYER
|
||||
_ray.collide_with_areas = false
|
||||
_ray.collide_with_bodies = true
|
||||
|
|
@ -84,7 +88,8 @@ func fire(origin: Vector3, muzzle: Vector3, dir: Vector3, damage: int = 1, speed
|
|||
exhausted += 1
|
||||
return false
|
||||
fired += 1
|
||||
if _resolve_segment(origin.x, origin.z, muzzle.x, muzzle.z, false, damage):
|
||||
var by := _enemies.attacker
|
||||
if _resolve_segment(origin.x, origin.z, muzzle.x, muzzle.z, false, damage, by):
|
||||
blocked_at_muzzle += 1
|
||||
return false
|
||||
var d := active_count
|
||||
|
|
@ -95,6 +100,7 @@ func fire(origin: Vector3, muzzle: Vector3, dir: Vector3, damage: int = 1, speed
|
|||
_dz[d] = dir.z
|
||||
_life[d] = lifetime if lifetime > 0.0 else _cfg.projectile_lifetime
|
||||
_damage[d] = damage
|
||||
_owner[d] = by
|
||||
_speed[d] = speed if speed > 0.0 else _cfg.projectile_speed
|
||||
_renderer.write_new(d, muzzle.x, muzzle.z, dir.x, dir.z, 0.0)
|
||||
return true
|
||||
|
|
@ -108,7 +114,7 @@ func step(dt: float) -> void:
|
|||
var z0 := _pz[i]
|
||||
var x1 := x0 + _dx[i] * step_len
|
||||
var z1 := z0 + _dz[i] * step_len
|
||||
if _resolve_segment(x0, z0, x1, z1, true, _damage[i]):
|
||||
if _resolve_segment(x0, z0, x1, z1, true, _damage[i], _owner[i]):
|
||||
_release(i)
|
||||
continue
|
||||
_px[i] = x1
|
||||
|
|
@ -152,8 +158,9 @@ func commit_render() -> void:
|
|||
|
||||
|
||||
## Resolves the nearest world/enemy hit along a segment. Returns true if something was hit
|
||||
## (damage is applied for enemy hits). use_motion selects the relative-motion enemy test.
|
||||
func _resolve_segment(x0: float, z0: float, x1: float, z1: float, use_motion: bool, damage: int) -> bool:
|
||||
## (damage is applied for enemy hits, credited to the shooter's avatar slot by). use_motion
|
||||
## selects the relative-motion enemy test.
|
||||
func _resolve_segment(x0: float, z0: float, x1: float, z1: float, use_motion: bool, damage: int, by: int) -> bool:
|
||||
var h := _cfg.combat_height
|
||||
var world_t := 2.0
|
||||
_ray.from = Vector3(x0, h, z0)
|
||||
|
|
@ -166,7 +173,7 @@ func _resolve_segment(x0: float, z0: float, x1: float, z1: float, use_motion: bo
|
|||
var e := _enemies.sweep_hit(x0, z0, x1, z1, use_motion)
|
||||
if e >= 0 and _enemies.hit_t <= world_t:
|
||||
var t := _enemies.type[e]
|
||||
_enemies.apply_hit(e, damage)
|
||||
_enemies.apply_hit(e, damage, by)
|
||||
hits_enemy += 1
|
||||
hit.emit(Vector3(lerpf(x0, x1, _enemies.hit_t), h, lerpf(z0, z1, _enemies.hit_t)), t)
|
||||
return true
|
||||
|
|
@ -187,5 +194,6 @@ func _release(i: int) -> void:
|
|||
_life[i] = _life[last]
|
||||
_damage[i] = _damage[last]
|
||||
_speed[i] = _speed[last]
|
||||
_owner[i] = _owner[last]
|
||||
_renderer.move_slot(last, i)
|
||||
active_count -= 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue