Files
tidewall/test/capture/figure_scene.gd
T
claudeandClaude Opus 5.5 2167900e45 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>
2026-11-15 03:01:09 -05:00

174 lines
5.6 KiB
GDScript

## Capture scenario for the player figure (A2), on seed 2's island in the real
## MatchView. Each stage stands a row of figures, each frozen at a chosen moment of one
## animation, seen from in front and to their right:
##
## - states: idle, walk, run, crouched, creeping, in the air, skydiving, gliding,
## swimming, downed (M7). (Aboard the barge is the idle with the feet set wider; the deck
## placement would pull it out of the row.)
## - actions: carrying a longgun, a revolver and a tonic, firing each kind, a boathook
## swing, a keg thrown, building, reloading, drinking and a flinch.
## - close: one figure holding the dock carbine, close up, three-quarter front.
extends Node3D
@export var stage: String = "states"
@export var match_seed: int = 2
## [label, item id or "", setup, seconds to run, action or ""]. Setup names a state.
const STATES: Array = [
["idle", "", "ground", 0.6, ""],
["walk", "", "walk", 0.2, ""],
["run", "", "run", 0.15, ""],
["crouch", "", "crouch", 0.8, ""],
["creep", "", "creep", 0.25, ""],
["air", "", "air", 0.5, ""],
["skydive", "", "skydive", 0.8, ""],
["glide", "", "glide", 0.8, ""],
["swim", "", "swim", 0.35, ""],
["downed", "", "downed", 0.5, ""],
]
const ACTIONS: Array = [
["long", "whalers_longgun", "ground", 0.6, ""],
["short", "signal_revolver", "ground", 0.6, ""],
["carry", "brine_tonic", "ground", 0.6, ""],
["fire_long", "dock_carbine", "ground", 0.04, "fire_long"],
["fire_short", "signal_revolver", "ground", 0.04, "fire_short"],
["swing_back", "", "ground", 0.16, "swing"],
["swing", "", "ground", 0.26, "swing"],
["throw", "powder_keg", "ground", 0.2, "throw"],
["build", "", "ground", 0.1, "build"],
["reload", "dock_carbine", "reload", 0.5, ""],
["use", "brine_tonic", "use", 0.5, ""],
["flinch", "dock_carbine", "flinch", 0.06, ""],
]
var sim: Simulation
var view: MatchView
func _ready() -> void:
sim = Simulation.new(match_seed)
var spot: Vector3 = _open_ground()
var rows: Array = STATES if stage == "states" else ACTIONS
if stage == "close":
rows = [["close", "dock_carbine", "ground", 0.6, ""]]
var players: Array[SimEntity] = []
for index: int in rows.size():
players.append(_stand(_at(spot, index, rows.size()), rows[index]))
view = MatchView.new()
view.setup(sim, 0)
add_child(view)
view.entities.animate_live = false
view.sync()
for index: int in rows.size():
_pose(players[index], rows[index])
var middle: Vector3 = _at(spot, (rows.size() - 1) * 0.5 + (1.0 if rows.size() > 1 else 0.0), rows.size())
if stage == "close":
view.look_from(middle + Vector3(-2.0, 1.55, 2.6), middle + Vector3(0.0, 1.0, 0.0))
else:
var back: float = 2.0 + rows.size() * 0.42
view.look_from(middle + Vector3(-back, 1.7, back * 0.3), middle + Vector3(0.0, 1.0, 0.0))
view.settle()
func _at(spot: Vector3, index: float, count: int) -> Vector3:
var at: Vector3 = spot + Vector3(0.0, 0.0, (index - (count - 1) * 0.5) * 1.5 + 1.0)
at.y = sim.ground.terrain_height(at.x, at.z)
return at
func _stand(at: Vector3, row: Array) -> SimEntity:
var player: SimEntity = sim.entities.find(sim.add_player())
player.position = at
player.drop_state = Drop.NONE
player.on_ground = true
player.health = 100
player.yaw = 0
var id: String = row[1]
if id != "":
player.slot_items[0] = ItemCatalog.code_of(id)
player.slot_counts[0] = 1
player.slot_tiers[0] = 2
player.selected = 1
else:
player.selected = 0
match String(row[2]):
"walk":
player.velocity = Vector3(0.0, 0.0, Tuning.WALK_SPEED)
"run":
player.velocity = Vector3(0.0, 0.0, Tuning.SPRINT_SPEED)
"crouch":
player.crouching = true
"creep":
player.crouching = true
player.velocity = Vector3(0.0, 0.0, Tuning.CROUCH_SPEED)
"air":
player.on_ground = false
player.position.y += 0.5
"skydive":
player.drop_state = Drop.FREEFALL
player.on_ground = false
player.position.y += 0.6
"glide":
player.drop_state = Drop.GLIDING
player.on_ground = false
player.position.y += 0.4
"swim":
player.swimming = true
player.on_ground = false
"downed":
player.downed = true
player.crouching = true
player.health = Tuning.DOWNED_HEALTH
"aboard":
player.drop_state = Drop.ABOARD
player.on_ground = false
"reload":
player.reload_ticks = 10
"use":
player.use_ticks = 10
return player
func _pose(player: SimEntity, row: Array) -> void:
var figure: FigureRig = view.entities.figure_of(player.id)
# The barge's deck isn't drawn here: put the passenger back where it stands.
figure.position = player.position
figure.drive(player, 0.0)
figure.drive(player, 1.0)
figure.advance(0.0)
if String(row[2]) == "flinch":
figure.advance(0.4)
player.health = 70
figure.drive(player, 0.0)
if String(row[4]) != "":
figure.advance(0.4)
figure.act(row[4])
var left: float = float(row[3])
while left > 0.0:
var step: float = minf(left, 1.0 / 60.0)
figure.advance(step)
left -= step
## Fairly flat, open ground above the sea near the middle of the island.
func _open_ground() -> Vector3:
var size: float = Tuning.WORLD_SIZE_METRES
var best: Vector3 = Vector3(size * 0.5, 0.0, size * 0.5)
for ring: int in 60:
for step: int in 24:
var angle: float = TAU * step / 24.0
var x: float = size * 0.5 + cos(angle) * ring * 12.0
var z: float = size * 0.5 + sin(angle) * ring * 12.0
var feet: Vector3 = Vector3(x, sim.ground.terrain_height(x, z), z)
if feet.y < sim.sea_level + 3.0 or sim.ground.terrain_normal(x, z).y < 0.985:
continue
if not sim.props.near(feet, 12.0).is_empty():
continue
var level: bool = true
for dz: float in [-7.0, 0.0, 9.0]:
if absf(sim.ground.terrain_height(x - 2.0, z + dz) - feet.y) > 0.8:
level = false
if level:
return feet
return best