#!/usr/bin/env bash
# Task #52 translocation sphere: A force-kills B repeatedly; A is the WATCHER
# (sees B's replicant). Check A's log for [tloc]: is the renderable created
# (does a replicant BTPlayer exist?), does tsphere.bgf load, what trigger
# states occur across B's death/respawn.
set -x
cd /c/git/bt411/content || exit 1
rm -f mp_a.log mp_b.log

BT_LOG=mp_b.log BT_AFFINITY=0x2 BT_MP_LOG=1 BT_MP_NET=1 BT_DEATH_LOG=1 BT_SCORE_LOG=1 BT_TLOC_LOG=1 \
  ../build/Debug/btl4.exe -egg MP.EGG -net 1601 &
sleep 2
BT_LOG=mp_a.log BT_AFFINITY=0x1 BT_MP_FORCE_DMG=1 BT_MP_LOG=1 BT_TLOC_LOG=1 \
  ../build/Debug/btl4.exe -egg MP.EGG -net 1501 &
sleep 4
python ../tools/btconsole.py MP.EGG 127.0.0.1:1501 127.0.0.1:1601 &
PC=$!
# wait for B's first respawn hunt, then settle so a full death->respawn cycle plays
n=0
until grep -q "drop-zone hunt" mp_b.log 2>/dev/null || [ $n -ge 150 ]; do sleep 2; n=$((n+2)); done
echo "=== hunt at ~${n}s; settle 40s for the sphere cycle ==="
sleep 40
kill $PC 2>/dev/null
taskkill //F //IM btl4.exe 2>/dev/null
taskkill //F //IM python.exe 2>/dev/null
echo "=== DONE ==="
echo "=== A [tloc] ==="; grep "\[tloc\]" mp_a.log | head -20
echo "=== B [tloc] ==="; grep "\[tloc\]" mp_b.log | head -20
