#!/bin/sh
LIBDIR=/usr/local/games/netrek-server-vanilla
cd ${LIBDIR}

# start a test player in slot 0 before starting this script

# start a set of robots
for x in `seq 8`; do
    lib/og/robot -h localhost -p 4577 -Tr 2>/dev/null >/dev/null &
    sleep 0.2
    lib/og/robot -h localhost -p 4566 -Tf 2>/dev/null >/dev/null &
    sleep 0.2
done

# allow time to get in
sleep 2

# choose captains
lib/tools/message forge-to-self 8 captain
lib/tools/message forge-to-self 0 captain

# start the draft
lib/tools/message forge-to-self 8 draft
lib/tools/message forge-to-self 0 draft

# wait for it to end
echo wait-for-inl-draft-to-end
sleep 0.1
lib/tools/setship 0 wait-for-inl-draft-to-end

# start the game
sleep 0.1
lib/tools/message forge-to-self 8 rom
lib/tools/message forge-to-self 0 fed
lib/tools/message forge-to-self 8 "gametime 1 1"
lib/tools/message forge-to-self 0 "gametime 1 1"
lib/tools/message forge-to-self 8 "start"
lib/tools/message forge-to-self 0 "start"

echo wait-for-inl-start
sleep 0.1
lib/tools/setgame wait-for-inl-start
echo started
sleep 0.1
lib/tools/setgame wait-for-inl-end
echo ended