Eric chose option B on #72. The drop is now the GDD's launch: - A packet ship sails a seeded straight line past the island, offshore, as close in as it can while keeping 45 m of open water from any land (eight-way probes; up to 32 headings, then the four world sides). - Jump fires the lifeline mortar along the look heading. How high the player aims sets the charge (-10 to 45 degrees: 16 to 110 m/s over the ground; every shot climbs at 75 m/s). The climb can't be steered and the kite can't open until the arc tops out. Riders still aboard at the end are fired towards the middle of the island. - Drop.reach() mirrors the fall for both ways down (kite at the top, or a fall with the kite opening by itself); bots, the soak and autoplay clients and the tutorial pilot aim with Drop.aim_charge(). - Bots fire at their landing spot once abeam of it, when in easy reach at their own staggered moment, or just before the route ends, and open the kite early only when the spot is beyond the rest of a fall. - Art: VesselModels.ship() (two-masted packet, tanned square sails, a salt-white boot-top, a bowsprit and the mortar on its bed, mirrored to face the island), the figure's gull-kite (figure.py), and a lifeline cord from the muzzle to each player still climbing. - Renamed barge to ship and wing-sail to gull-kite throughout code, tests, captures, docs and the tutorial text. make match now defaults to seed 2, where the scripted player still harvests and builds. Closes #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
179 lines
7.1 KiB
GDScript
179 lines
7.1 KiB
GDScript
## Capture scenario for a whole match. It replays the command log `make match` saved
|
|
## to the moment `stage` names, draws that moment with the client's MatchView, and
|
|
## prints what it shows as a caption (Godot's default font; this is a test caption,
|
|
## not the game's HUD).
|
|
##
|
|
## Stages: lobby, ship, glide, landed, built, final, tide (the island just before the
|
|
## end, from where the lobby saw it), results.
|
|
extends Node3D
|
|
|
|
const TICKS: int = Tuning.TICK_RATE_HZ
|
|
## The scripted player's handle.
|
|
const PLAYER: int = 1
|
|
|
|
@export var log_path: String = "res://build/match/match.tclog"
|
|
@export var stage: String = "lobby"
|
|
## H2: a GameSettings quality preset to draw with (-1: the view's defaults).
|
|
@export var quality: int = -1
|
|
|
|
var _replay: MatchReplay
|
|
var _view: MatchView
|
|
|
|
|
|
func _ready() -> void:
|
|
var commands: CommandLog = CommandLog.load_from(log_path)
|
|
if commands == null:
|
|
push_error("match capture: no usable command log at %s; run `make match` first" % log_path)
|
|
return
|
|
_replay = MatchReplay.new(commands)
|
|
var flow: Match = _replay.flow
|
|
var last: int = commands.final_tick
|
|
match stage:
|
|
"lobby":
|
|
pass
|
|
"ship":
|
|
_replay.run_until(func() -> bool: return flow.in_match() and flow.sim.tick >= 2 * TICKS)
|
|
"launch":
|
|
# A bot half a second up the mortar's arc, its lifeline still trailing.
|
|
_replay.run_until(func() -> bool: return flow.in_match() and _climber() != null and _climber().velocity.y < Tuning.MORTAR_RISE_SPEED - 8.0)
|
|
"glide":
|
|
_replay.run_until(func() -> bool: return _player() != null and _player().drop_state == Drop.GLIDING)
|
|
_run_ticks(TICKS)
|
|
"landed":
|
|
_replay.run_until(func() -> bool: return _player() != null and _player().drop_state == Drop.NONE and flow.in_match())
|
|
_run_ticks(4 * TICKS)
|
|
"built":
|
|
_replay.run_until(func() -> bool: return flow.sim.structures.count() >= 2)
|
|
_run_ticks(3 * TICKS)
|
|
"tide":
|
|
_replay.run_until(func() -> bool: return flow.in_match() and flow.sim.tick >= last - 2 * TICKS)
|
|
"final":
|
|
_replay.run_until(func() -> bool: return flow.in_match() and flow.sim.tick > 10 * TICKS and flow.alive().size() <= 3)
|
|
"results":
|
|
_replay.run_to_end()
|
|
_:
|
|
push_error("match capture: unknown stage '%s'" % stage)
|
|
return
|
|
|
|
var sim: Simulation = flow.sim
|
|
var player_id: int = int(flow.entity_of.get(PLAYER, 0))
|
|
_view = MatchView.new()
|
|
_view.setup(sim, player_id)
|
|
add_child(_view)
|
|
if quality >= 0:
|
|
var settings: GameSettings = GameSettings.new()
|
|
settings.quality = quality
|
|
settings.apply_to_viewport(get_viewport())
|
|
_view.apply_settings(settings)
|
|
var watched: int = _watched()
|
|
var who: String = "nobody"
|
|
if stage == "lobby" or stage == "tide":
|
|
_view.overview()
|
|
who = "the island"
|
|
elif stage == "ship" or stage == "launch":
|
|
# From over the water astern and seaward of the ship, looking past it to the island.
|
|
var along: Vector3 = (sim.drop.finish - sim.drop.start).normalized()
|
|
var at: Vector3 = sim.drop.ship_position(sim.tick)
|
|
var centre: Vector3 = Vector3(Tuning.WORLD_SIZE_METRES * 0.5, 0.0, Tuning.WORLD_SIZE_METRES * 0.5)
|
|
var inland: Vector3 = Vector3(centre.x - at.x, 0.0, centre.z - at.z).normalized()
|
|
if stage == "ship":
|
|
_view.look_from(at - along * 26.0 - inland * 16.0 + Vector3(0.0, 11.0, 0.0), at + inland * 30.0 + Vector3(0.0, 2.0, 0.0))
|
|
who = "the ship"
|
|
else:
|
|
var climber: SimEntity = _climber()
|
|
_view.look_from(at - along * 30.0 - inland * 24.0 + Vector3(0.0, 8.0, 0.0), climber.position.lerp(at, 0.45))
|
|
who = "a bot fired from the ship"
|
|
elif watched != 0:
|
|
var entity: SimEntity = sim.entities.find(flow.entity_of[watched])
|
|
var airborne: bool = entity.drop_state != Drop.NONE
|
|
if stage == "built" and sim.structures.count() > 0:
|
|
var piece: StructureSet.Piece = sim.structures.pieces.values()[0]
|
|
_view.frame(entity.id, 7.0, 2.8, piece.boxes[0].get_center())
|
|
elif stage == "results":
|
|
_view.frame(entity.id)
|
|
else:
|
|
_view.follow(entity.id, deg_to_rad(-22.0) if airborne else deg_to_rad(-9.0))
|
|
who = "the player" if watched == PLAYER else "bot %d" % -watched
|
|
else:
|
|
_view.overview()
|
|
_view.settle()
|
|
_caption(_describe(who) + ("" if quality < 0 else "\nquality: %s, renderer: %s" % [GameSettings.QUALITY_NAMES[quality], RenderingServer.get_current_rendering_method()]))
|
|
|
|
|
|
## The first player climbing the mortar's arc, or null.
|
|
func _climber() -> SimEntity:
|
|
var sim: Simulation = _replay.flow.sim
|
|
if sim == null or sim.drop == null:
|
|
return null
|
|
for entity: SimEntity in sim.entities.entities():
|
|
if entity.archetype == SimEntity.ARCHETYPE_PLAYER and entity.drop_state == Drop.FREEFALL and entity.velocity.y > 0.0:
|
|
return entity
|
|
return null
|
|
|
|
|
|
func _player() -> SimEntity:
|
|
var flow: Match = _replay.flow
|
|
if not flow.entity_of.has(PLAYER):
|
|
return null
|
|
return flow.sim.entities.find(flow.entity_of[PLAYER])
|
|
|
|
|
|
func _run_ticks(count: int) -> void:
|
|
for _index: int in count:
|
|
if not _replay.step():
|
|
return
|
|
|
|
|
|
## The handle the camera follows: the player while they stand, then whoever they're
|
|
## spectating, then a winner, then anyone still standing. 0 for nobody.
|
|
func _watched() -> int:
|
|
var flow: Match = _replay.flow
|
|
var living: Array[int] = flow.alive()
|
|
if living.has(PLAYER):
|
|
return PLAYER
|
|
var target: int = flow.spectate_target(PLAYER)
|
|
if target != 0 and flow.entity_of.has(target):
|
|
return target
|
|
if not flow.winners.is_empty():
|
|
return flow.winners[0]
|
|
return living[0] if not living.is_empty() else 0
|
|
|
|
|
|
func _describe(who: String) -> String:
|
|
var flow: Match = _replay.flow
|
|
var sim: Simulation = flow.sim
|
|
var lines: Array[String] = []
|
|
lines.append("%s · %s · seed %d" % [stage.to_upper(), flow.phase_name(), _replay.commands.session_seed])
|
|
if flow.phase == Match.LOBBY or flow.phase == Match.COUNTDOWN:
|
|
lines.append("%d waiting · the match starts in %d s" % [flow.participants.size(), (flow.rules.lobby_ticks + flow.rules.countdown_ticks) / TICKS])
|
|
return "\n".join(lines)
|
|
lines.append("%d:%02d · %d of %d standing · sea %.1f m · tide phase %d" % [
|
|
sim.tick / TICKS / 60, sim.tick / TICKS % 60, flow.alive().size(), flow.summary().size(), sim.sea_level,
|
|
sim.tide.phase_at(sim.tick) + 1 if sim.tide != null else 0])
|
|
var me: SimEntity = _player()
|
|
if me != null:
|
|
lines.append("player: health %d · driftwood %d · %d pieces built · watching %s" % [
|
|
me.health, me.materials[Materials.DRIFTWOOD], sim.structures.count(), who])
|
|
if flow.phase == Match.RESULTS:
|
|
for row: Dictionary in flow.summary():
|
|
if row["place"] <= 3 or row["handle"] == PLAYER:
|
|
lines.append("#%d %s · %d eliminations · %d damage · %d s" % [
|
|
row["place"], "player" if row["handle"] == PLAYER else "bot %d" % -int(row["handle"]),
|
|
row["eliminations"], row["damage_dealt"], roundi(row["survival_seconds"])])
|
|
return "\n".join(lines)
|
|
|
|
|
|
func _caption(text: String) -> void:
|
|
var settings: LabelSettings = LabelSettings.new()
|
|
settings.font_size = 20
|
|
settings.font_color = Color(0.96, 0.94, 0.88)
|
|
settings.outline_size = 6
|
|
settings.outline_color = Color(0.08, 0.09, 0.1)
|
|
var label: Label = Label.new()
|
|
label.label_settings = settings
|
|
label.text = text
|
|
label.position = Vector2(18.0, 14.0)
|
|
var layer: CanvasLayer = CanvasLayer.new()
|
|
layer.add_child(label)
|
|
add_child(layer)
|