# zdoom selector script
# 08/04/08 bman
# 08/05/08 bman - syntax fixes
# 08/11/08 bman - updated syntax for zdoom PB1.2
#               - added support for music, level, and graphics addons
#               - added WAD path variable

DOOMWADDIR=./wad/
export DOOMWADDIR

# Extract the selected path/file and extension (only supports .wad,.deh,.warp)
if [ "$4" = "NONE.wad" ] ; then
 ext="wad"
 fil="./wad/$3"
else
 ext=`echo $4|cut -f3 -d.`
 fil=`echo $4|cut -f2 -d.`
fi

case $2 in
 'use' )
# Are we substituting a default IWAD?
  iwad="$4"
 ;;
 'with' )
# Are we running a default IWAD?
  iwad="$3.wad"
# Are we using a Dehack?
  if [ "$ext" = "deh" ] ; then
   pwad="-deh $4 -file .$fil.wad"
  else
   pwad="-file $4"
  fi
# Are there any add-on levels, graphic, or music defined?
  for addon in levels music graphics
   do
    if [ -f .$fil$addon.wad ] ; then
     pwad="$pwad .$fil$addon.wad"
    fi
   done
 ;;
 'only' )
# Are we running default games?
  iwad="$3.wad"
  if [ "$3" = "strife" ] ; then
   pwad="-file voices.wad"
  fi
  ;;
 * )
# Anything else doesn't work
  exit 1
 ;;
esac

# Are we warping anywhere?
 if [ -f .$fil.warp ] ; then
  lvl="-warp `cat .$fil.warp`"
 fi

# Run the parms
#exec ./2xZdoom220 -frontend ./Zdoom_selector.gpe -stdlog -iwad $iwad $pwad $lvl
#exec ./2xZdoom220 -frontend ./Zdoom_exit -stdlog -iwad $iwad $pwad $lvl
./2xZdoom220 -frontend ./Zdoom_exit -iwad $iwad $pwad $lvl
#echo "./2xZdoom220 -frontend ./Zdoom_exit -stdlog -iwad $iwad $pwad $lvl" > testlog.txt
