#!/bin/sh

sconf="server.conf"
cconf="client.conf"
fconf="formation.conf"


ROLES="LSB LCB RCB RSB CB DH LOH ROH LWG CFW RWG"
role="RSB"

host="localhost"
port="6000"
team="OZ"
reconnect_number=""
goalie="false"

usage()
{
	(echo "Usage: $0 [options]"
	 echo "Possible options are:"
	 echo "      --help"
	 echo "  -h, --host HOST"
	 echo "  -p, --port PORT"
	 echo "  -t, --team-name TEAM"
	 echo "  -r, --reconnect NUMBER"
	 echo "  -g, --goalie"
	 echo "  -R, --role"
	 echo "  -a, --acceptable-roles") 1>&2
}

while [ $# -gt 0 ]
do
	case $1 in

	--help)
		usage
		exit 0
		;;

	-h|--host)
		host=$2
		shift 1
		;;

	-p|--port)
		port=$2
		shift 1
		;;

	-t|--team-name)
		team=$2
		shift 1
		;;

	-r|--reconnect)
		reconnect_number=$2
		shift 1
		;;

	-g|--goalie)
		goalie="true"
		;;

	-R|--role)
		role=$2
		shift 1
		;;

	-a|--acceptable-roles)
		echo $ROLES
		exit 0
		;;

	*)
		usage
		exit 1
		;;
	esac

	shift 1
done



if [ "${goalie}" = "true" ]; then
	goalie_option="--goalie"
else
	goalie_option=""
fi

if [ ! -z "${reconnect_number}" ]; then
	reconnect_option="--reconnect ${reconnect_number}"
fi

case $role in
        LSB)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf formation.conf -h ${host} -t ${team} -p 2 1>/dev/null 2>&1 &
		;;
        LCB)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 3 1>/dev/null 2>&1 &
		;;
        RCB)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 4 1>/dev/null 2>&1 &
		;;
        RSB)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 5 1>/dev/null 2>&1 &
		;;
        CB)     ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf formation.cenda.conf -h ${host} -t ${team} -p 3 1>/dev/null 2>&1 &
    ;;
        DH)     ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 6 1>/dev/null 2>&1 &
		;;
        LOH)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 7 1>/dev/null 2>&1 &
		;;
        ROH)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 8 1>/dev/null 2>&1 &
		;;
        LWG)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 9 1>/dev/null 2>&1 &
		;;
        CFW)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 10 1>/dev/null 2>&1 &
		;;
        RWG)    ./TITPlayer -sfile ${sconf} -cfile ${cconf} -fconf ${fconf} -h ${host} -t ${team} -p 11 1>/dev/null 2>&1 &
		;;
	*)
		echo "Can't accept role: \"${role}\""
		exit 1
		;;
esac
