#!/bin/bash

# Conmen for Linux, Console menu scripts. (cmgames).
# Copyright (C) 1999  Maxim Heijndijk

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# Email: cchq@wanadoo.nl"

# set -x

# Set variables
MNAME=cmgames
RCFILE=$HOME/.conmen/${MNAME}rc

# Read common functions
. /usr/lib/conmen/cmfunk

# Read script-specific functions
for FILE in /usr/lib/conmen/$MNAME/*[!~] ; do
    . $FILE
done

# Create script-specific configuration file during first run
[ -f "$RCFILE" ] || saverc

# Read configuration files
. $GLOBALRC
. $USERRC
. $RCFILE

# Warn if the Xdialog wrapper is not installed.
if_no_wrapper

# Read and execute selected function in /usr/lib/conmen/$MNAME
function menuchoices1 {
    unset RESULT
    RESULT=`grep -l "${choice}1=$choice" /usr/lib/conmen/$MNAME/*[!~]`
    `basename $RESULT`
    games
}

# Main function
function games {
    #read
    MENU="GAMES"
    MENUCHOICES=menuchoices1
    menubox $A1 "${A2[@]}" \
	    $B1 "${B2[@]}" \
	    $C1 "${C2[@]}" \
	    $D1 "${D2[@]}" \
	    $E1 "${E2[@]}" \
	    $F1 "${F2[@]}" \
	    $G1 "${G2[@]}" \
	    $H1 "${H2[@]}" \
	    $I1 "${I2[@]}" \
	    $J1 "${J2[@]}" \
	    $K1 "${K2[@]}" \
	    $L1 "${L2[@]}" \
	    $M1 "${M2[@]}" \
	    $N1 "${N2[@]}" \
	    $O1 "${O2[@]}" \
	    $P1 "${P2[@]}"
}

# for this script only
check_cdrom

if [ -d "$DOOMBINDIR" -a -d "$IWADDIR" -a -d "$PWADDIR" ]; then
    make_doom_config
else
    unset A1
    unset A2
    unset C1
    unset C2
    unset D1
    unset D2
    [ -d "$DOOMBINDIR" ] || echo "DOOM binaries not found !" >> $TXTTMP
    [ -d "$IWADDIR" ] || echo "DOOM IWAD files not found !" >> $TXTTMP
    [ -d "$PWADDIR" ] || echo "DOOM PWAD files not found !" >> $TXTTMP
fi

if [ -d "$QUAKEBINDIR" ]; then
    make_quake_config
else
    unset E1
    unset E2
    echo "QUAKE binaries not found !" >> $TXTTMP
fi

if [ -d "$QUAKE2BINDIR" ]; then
    make_quake2_config
else
    unset G1
    unset G2
    echo "QUAKE II binaries not found!" >> $TXTTMP
fi

[ -f $TXTTMP ] && textbox "$TXTTMP"

# Execute main function
games

exit 0
