#!/usr/bin/env bash
# Which input SELECTS a target, and does a lock then build?
#
# 98 guided missiles produced 2 kills. A guided missile with nothing to guide to
# flies straight, so the suspicion is that the loop has never selected a target
# at all: the HUD carries a `TARGET` marker and a lock reticle, and no button in
# pilot.py has ever touched them. fire_probe.sh already showed LB/X/B/A/LS/RS do
# not discharge a weapon — but "does not fire" says nothing about "does not
# select", so sweep them again watching the RETICLE instead of the ammo.
#
# Captures the centre of the screen (reticle + lock brackets) and the right-hand
# target panel, so a selection or a building lock is visible either way.
set -u
export HOME=/sylph-home/re SDL_AUDIODRIVER=dummy DISPLAY=:98
SD="$(cd "$(dirname "$0")" && pwd)"
SHOTS=/sylph-home/re/shots
HOLD="${1:-3}"

shot(){ screenshot "$SHOTS/lock-$1.png" >/dev/null 2>&1; echo "  shot $1"; }

"$SD/launch_mission.sh" fly || { echo "BOOT FAILED"; exit 1; }
sleep 3
shot "00-idle"

# tap, not hold: a select is an edge, and holding a cycle button would just spin
# through every contact. Two taps each, so a cycle that lands on nothing the
# first time still shows on the second.
for b in RS LS LB B X A Y; do
  vgamepad tap "$b" 200; sleep 0.4; vgamepad tap "$b" 200; sleep "$HOLD"
  shot "tap-$b"
done
vgamepad reset
shot "99-final"
echo "PROBE DONE"
