M7: Duos and revive

Two-player teams, enforced by the simulation:
- Match puts every player on a team (SimEntity.team); Weapons.damage_player
  refuses damage between teammates from every weapon, the boathook and blasts.
- A player whose health runs out with a teammate standing goes down instead of
  out: 60 health to bleed (one point every half second), crawling at 1 m/s, no
  firing, building, looting or items. Hits still take it; drowning too.
- A standing teammate within 2 m holding interact for 6 s revives them with 30
  health. Letting go or moving away starts it over.
- Downed players are out when their health runs out again or when no teammate
  is left standing, credited to whoever downed them. A team falls together and
  shares its place; the tie-break puts standing ahead of downed.
- Downs and revives go through Match events and the kill feed ("X knocked Y
  down"); the HUD says what to do while down.

Wire: FLAG_DOWNED in the player record and the own block (flags now u16),
so prediction crawls too. Protocol version 5.

Bots: never target a teammate, land with their teammate, regroup when they
stray past 30 m, crawl toward a standing teammate when down, go to revive a
downed teammate within 60 m when not in a fight, and turn from a downed target
to its standing teammate when it's in view.

Options: --team-size=2 on the server, --duos offline, and Solo/Duos under
Crew in the Practice menu. The figure has a downed crawl pose.

Tests: test_duos (downing, crawl, revive, interrupted revive, bleed-out,
finishing, team out, falling together, no friendly damage including kegs,
drowning while down, hash, match placement and tie-break), bots as teammates,
the downed flag on the wire, the feed, server and menu options. make
duo-matches plays 10 bot duos matches.

Closes #30

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 03:01:09 -05:00
co-authored by Claude Opus 5.5
parent 324bf84dd5
commit 2167900e45
53 changed files with 1105 additions and 61 deletions
+110 -3
View File
@@ -178,6 +178,8 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
return PlayerCommand.from_input(sim.tick, Vector2.ZERO, 0.0, 0.0)
if me.drop_state != Drop.NONE:
return _drop(sim, grid, world)
if me.downed:
return _crawl(sim, world, me)
_count_building(world, me)
_sense(sim, world, me)
_check_tide(sim, world, me)
@@ -205,6 +207,8 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
and not _fleeing and not retreating and not covering and distance <= Tuning.BOT_BRAWL_METRES and provoked)
var interact: bool = false
var walk: bool = true
var patient: SimEntity = _patient(sim, world, me) if not me.swimming else null
var tending: bool = false
# Where to go.
_direct_on = false
@@ -234,6 +238,14 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
elif brawling:
state = "brawl"
_stop()
elif patient != null:
# A teammate is down (M7): get to them and hold interact until they're up.
state = "revive"
if me.position.distance_to(patient.position) <= Tuning.REVIVE_RANGE * 0.75:
_stop()
tending = true
else:
_go(patient.position, Tuning.REVIVE_RANGE * 0.5)
elif target != null and armed:
state = "chase"
_go(_last_seen, 3.0)
@@ -361,6 +373,14 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
chosen_material = _piece_material
if _piece_kind != StructureSet.RAMP:
direction = Vector2.ZERO
if tending:
var to_patient: Vector2 = Vector2(patient.position.x - me.position.x, patient.position.z - me.position.z)
if to_patient.length() > 0.05:
yaw = atan2(to_patient.x, to_patient.y)
pitch = 0.0
direction = Vector2.ZERO
buttons = PlayerCommand.BUTTON_INTERACT
chosen_material = 0
_track_fight(sim, world, me, buttons)
var forward: Vector2 = Vector2(sin(yaw), cos(yaw))
var right: Vector2 = Vector2(-cos(yaw), sin(yaw))
@@ -368,6 +388,64 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
return PlayerCommand.from_input(sim.tick, move, yaw, pitch, buttons, selection, chosen_material)
# Duos (M7)
## The nearest standing teammate, or null.
func _standing_teammate(sim: Simulation, world: BotWorld, me: SimEntity) -> SimEntity:
if me == null or me.team < 0:
return null
var best: SimEntity = null
var best_gap: float = INF
for other_id: int in world.player_ids:
var other: SimEntity = sim.entities.find(other_id)
if not Simulation.is_standing(other) or not sim.are_teammates(me, other) or other.drop_state != Drop.NONE:
continue
var gap: float = me.position.distance_squared_to(other.position)
if gap < best_gap:
best = other
best_gap = gap
return best
## The nearest downed teammate within Tuning.BOT_REVIVE_METRES, or null.
func _patient(sim: Simulation, world: BotWorld, me: SimEntity) -> SimEntity:
var best: SimEntity = null
var best_gap: float = Tuning.BOT_REVIVE_METRES * Tuning.BOT_REVIVE_METRES
for other_id: int in world.player_ids:
var other: SimEntity = sim.entities.find(other_id)
if other == null or not other.downed or other.eliminated or not sim.are_teammates(me, other):
continue
var gap: float = me.position.distance_squared_to(other.position)
if gap <= best_gap:
best = other
best_gap = gap
return best
## Downed: crawl straight for the nearest standing teammate, and stop beside them.
func _crawl(sim: Simulation, world: BotWorld, me: SimEntity) -> PlayerCommand:
state = "downed"
_stop()
_forget_target()
var yaw: float = float(me.yaw) / PlayerCommand.YAW_STEPS * TAU
var move: Vector2 = Vector2.ZERO
var nearest: SimEntity = null
var nearest_gap: float = INF
for other_id: int in world.player_ids:
var other: SimEntity = sim.entities.find(other_id)
if not Simulation.is_standing(other) or not sim.are_teammates(me, other):
continue
var gap: float = me.position.distance_squared_to(other.position)
if gap < nearest_gap:
nearest = other
nearest_gap = gap
if nearest != null and nearest_gap > Tuning.REVIVE_RANGE * Tuning.REVIVE_RANGE * 0.25:
var to: Vector2 = Vector2(nearest.position.x - me.position.x, nearest.position.z - me.position.z)
yaw = atan2(to.x, to.y)
move = Vector2(0.0, 1.0)
return PlayerCommand.from_input(sim.tick, move, yaw, 0.0)
# Movement goals
func _go(goal: Vector3, radius: float) -> void:
@@ -388,6 +466,13 @@ func _stop() -> void:
## Rides the barge to within reach of a loot marker near its route, then glides to it.
func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
state = "drop"
var rider: SimEntity = sim.entities.find(player_id)
if _landing < 0 and rider != null and rider.team >= 0 and world.team_landings.has(rider.team):
# Duos (M7): land with the teammate who already chose.
_landing = int(world.team_landings[rider.team])
_marker = _landing
_marker_since = sim.tick
_go(world.markers[_landing], 2.0)
if _landing < 0 and not world.markers.is_empty() and sim.drop != null:
var rng: RandomNumberGenerator = nav.stream(sim)
var a: Vector2 = Vector2(sim.drop.start.x, sim.drop.start.z)
@@ -413,6 +498,8 @@ func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
best_crowd = crowd
_landing = pick
world.landings.append(world.markers[_landing])
if rider != null and rider.team >= 0:
world.team_landings[rider.team] = _landing
_marker = _landing
_marker_since = sim.tick
_go(world.markers[_landing], 2.0)
@@ -455,6 +542,18 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
elif tick - _last_seen_tick > roundi(Tuning.BOT_MEMORY_SECONDS * TICKS):
_forget_target()
target = null
if target != null and target.downed and target_visible:
# Duos (M7): a downed target can't shoot back, but its teammate can. Turn on the
# teammate if they're in view; otherwise finish the job.
for other_id: int in world.player_ids:
var other: SimEntity = sim.entities.find(other_id)
if Simulation.is_standing(other) and other.drop_state == Drop.NONE and sim.are_teammates(target, other) \
and me.position.distance_to(other.position) <= minf(_sight, Tuning.BOT_ENGAGE_METRES) and _can_see(sim, world, me, other, false):
target_id = other.id
_acquired_tick = tick
_last_seen = other.position
_last_seen_tick = tick
return
if target != null and target_visible:
return
# Look for someone new, nearest first, with a few sight lines at most.
@@ -463,7 +562,7 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
if other_id == player_id or other_id == target_id:
continue
var other: SimEntity = sim.entities.find(other_id)
if other == null or other.eliminated or other.drop_state != Drop.NONE:
if other == null or other.eliminated or other.drop_state != Drop.NONE or sim.are_teammates(me, other):
continue
# A bot picks out a new opponent only this close; one who shoots it first is
# fought at any range it can see (H3).
@@ -974,10 +1073,18 @@ func _hunt(sim: Simulation, world: BotWorld) -> void:
if arrived and not _holding:
_holding = true
_hunt_until = sim.tick + roundi(Tuning.BOT_HOLD_SECONDS * TICKS)
var me: SimEntity = sim.entities.find(player_id)
var mate: SimEntity = _standing_teammate(sim, world, me)
var strayed: bool = mate != null and me.position.distance_to(mate.position) > Tuning.BOT_REGROUP_METRES
if strayed and (_holding or _hunt_goal.distance_to(mate.position) > Tuning.BOT_REGROUP_METRES * 0.5):
# Duos (M7): too far from the teammate to help them up; go back to them.
_holding = false
_hunt_until = sim.tick
if (not _goal_set and not _holding) or sim.tick >= _hunt_until:
var phase: int = sim.tide.phase_at(sim.tick) if sim.tide != null else 0
var me: SimEntity = sim.entities.find(player_id)
_hunt_goal = world.random_safe_near(nav.stream(sim), phase, me.position, Tuning.BOT_ROAM_METRES)
var around: Vector3 = mate.position if strayed else me.position
var radius: float = Tuning.BOT_REGROUP_METRES * 0.3 if strayed else Tuning.BOT_ROAM_METRES
_hunt_goal = world.random_safe_near(nav.stream(sim), phase, around, radius)
_hunt_until = sim.tick + 40 * TICKS
_holding = false
_go(_hunt_goal, 4.0)