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:
commit
2fc09ca3fa
23 changed files with 535 additions and 138 deletions
|
|
@ -116,6 +116,11 @@ var _free_ids := PackedInt32Array()
|
|||
var _free_top: int = 0
|
||||
var _pending := PackedInt32Array()
|
||||
var _pending_count: int = 0
|
||||
## Co-op goop credit: the avatar slot whose attack is being resolved right now (FarmSim sets it
|
||||
## around each scarecrow's combat step; -1 otherwise: turrets, bombs going off, tests), and the
|
||||
## slot that landed each enemy's killing hit, by stable id (read through killer_of()).
|
||||
var attacker: int = -1
|
||||
var _killer := PackedInt32Array()
|
||||
|
||||
# Diagnostics.
|
||||
var spawn_skipped: int = 0
|
||||
|
|
@ -139,7 +144,7 @@ func setup(cfg: GameConfig, p_nav: FarmNavigation, p_behavior: ThiefBehavior, me
|
|||
pace, head_x, head_z, flap_phase, hurt, timer, attack_cd, slow_left, alt]:
|
||||
a.resize(capacity)
|
||||
a.fill(0.0)
|
||||
for a: PackedInt32Array in [health, target, carry, barrier, dense_id, id_dense, id_generation, _free_ids, _pending]:
|
||||
for a: PackedInt32Array in [health, target, carry, barrier, dense_id, id_dense, id_generation, _free_ids, _pending, _killer]:
|
||||
a.resize(capacity)
|
||||
a.fill(0)
|
||||
for a: PackedByteArray in [type, state, alive, removal, resume, want]:
|
||||
|
|
@ -232,6 +237,7 @@ func spawn(enemy_type: int, x: float, z: float, heading: Vector2, p_want: int =
|
|||
spawn_skipped += 1
|
||||
return -1
|
||||
_free_top -= 1
|
||||
_killer[id] = -1
|
||||
var d := active_count
|
||||
active_count += 1
|
||||
var h := heading.normalized() if heading.length_squared() > 1e-6 else Vector2(0.0, -1.0)
|
||||
|
|
@ -298,8 +304,9 @@ func visual_position(d: int) -> Vector2:
|
|||
return Vector2(lerpf(prev_x[d], pos_x[d], f), lerpf(prev_z[d], pos_z[d], f))
|
||||
|
||||
|
||||
## Applies one hit. Returns false for dead or pending slots (no double kills).
|
||||
func apply_hit(d: int, damage: int = 1) -> bool:
|
||||
## Applies one hit. Returns false for dead or pending slots (no double kills). by: the avatar
|
||||
## slot that landed it (a shot's shooter), or -1 for whoever is attacking now (attacker).
|
||||
func apply_hit(d: int, damage: int = 1, by: int = -1) -> bool:
|
||||
if not is_alive_slot(d):
|
||||
return false
|
||||
health[d] -= damage
|
||||
|
|
@ -308,14 +315,22 @@ func apply_hit(d: int, damage: int = 1) -> bool:
|
|||
characters.hit(dense_id[d])
|
||||
if health[d] <= 0:
|
||||
kills += 1
|
||||
_killer[dense_id[d]] = by if by >= 0 else attacker
|
||||
queue_removal(d, Removal.KILLED)
|
||||
elif behavior != null:
|
||||
behavior.on_hit(self, d)
|
||||
return true
|
||||
|
||||
|
||||
func apply_hit_handle(handle: int, damage: int = 1) -> bool:
|
||||
return apply_hit(resolve_handle(handle), damage)
|
||||
func apply_hit_handle(handle: int, damage: int = 1, by: int = -1) -> bool:
|
||||
return apply_hit(resolve_handle(handle), damage, by)
|
||||
|
||||
|
||||
## The avatar slot whose hit killed this enemy (while enemy_removed is emitted for it), or -1:
|
||||
## killed by a turret or a bomb, not killed, or a stale handle.
|
||||
func killer_of(handle: int) -> int:
|
||||
var d := resolve_handle(handle)
|
||||
return _killer[dense_id[d]] if d >= 0 else -1
|
||||
|
||||
|
||||
## Takes a living enemy out of the simulation now; its slot is released (and enemy_removed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue