Language: EN FR PT ES NL DE SV RU
#!/bin/bash
#slackins custom q3map2 tool!
#still a work in progress but makes life much easyer than just typing a ton everytime.
 
 
#Get -vis options funtion:
function getvisargs {
  visargs="-hint -merge -fast -saveprt"
  visbasearg="-vis"
  for argname in $visargs
  do
    echo "use ${argname}?(y/n)"
    read answ
    if [[ $answ = "y" ]]; then
        visbasearg="$visbasearg $argname"
    else
      echo "Not using $argname"
    fi
    echo "q3map2 set to run vis stage with $visbasearg"
  done
}
 
#Get -light options function:
function getlightargs {
  lightargs="-filter -super -samples -bounce -border -debug -dirty -fast -faster -fastbounce -fastgrid -patchshadows -shade"
  lightbasearg="-light"
  for argname in $lightargs
  do
    echo "use ${argname}?(y/n)"
    read answ
    if [[ $answ = "y" ]]; then
      if [[ $argname = "-bounce" || $argname = "-super" || $argname = "-samples" ]]; then
        echo "number?(2-10)"
        read cntnum
        lightbasearg="$lightbasearg $argname $cntnum"
      else
        lightbasearg="$lightbasearg $argname"
      fi
    else
      echo "Not using $argname"
    fi
    echo "q3map2 set to run light stage with $lightbasearg"
  done
}
 
#Get mapname funtion:
function getmapname {
  echo "please enter the map name(no .bsp .map .pk3, ie: ut4_casa)"
  read mapname
  pathmapname="q3ut4/maps/"
  mapname="${q3ut4tree}${pathmapname}${mapname}.map"
}
 
#Run q3map2 function:
function runqthreemaptwo {
  $qmapprog -game q3ut4 -fs_basepath "$q3ut4tree" -fs_game q3ut4 ${*}
}
 
#Run config setup
function doconfig {
  echo "Config mode, please enter your default options for normal compile"
  getvisargs
  getlightargs
  defavisopts="$visbasearg"
  defalightopts="$lightbasearg"
  echo "Now please enter your default options for fast/test compile"
  getvisargs
  getlightargs
  fastavisopts="$visbasearg"
  fastalightopts="$lightbasearg"
  getpath
  gettree
  saveconfig
}
 
function saveconfig {
#------------------------------------
# CONFIG START
 
echo "q3ut4tree=\"$qtreepath"\" 1>$configfile
echo "qmapprog=\"$qmappath"\" 1>>$configfile
echo "defvisopts=\"$defavisopts"\" 1>>$configfile
echo "deflightopts=\"$defalightopts"\" 1>>$configfile
echo "fastvisopts=\"$fastavisopts"\" 1>>$configfile
echo "fastlightopts=\"$fastalightopts"\" 1>>$configfile
 
#END OF CONFIG
#------------------------------------
}
 
#Get path to q3map2
function getpath {
  echo "Please enter full path to q3map2(ie: /opt/bin/q3map2.trunk)"
  read qmappath
}
 
#Get path to q3map2 tree
function gettree {
  echo "Please enter path to q3ut4 directory(ie: /usr/local/games/urbanterror/ note the trailing slash IS there)"
  read qtreepath
}
 
function pusage {
    echo "Usage: ut4slacktoolz.sh mode mapname"
    echo "Where mode is one of the following:"
    echo "--------------------------------------------------"
    echo "[1]: BSP"
    echo "[2]: VIS"
    echo "[3]: LIGHT"
    echo "[4]: ALL"
    echo "[5]: ALL FAST"
    echo "[6]: ALL CUSTOM (Interactively pick compile flags)"
    echo "[7]: Reconfigure default options"
    echo "--------------------------------------------------"
    echo "And mapname should be the name with out any extentions, ie: [ ut4_casa ]"
    exit 0
}
 
function imenu {
echo "slackin's q3map2 script!"
echo "Please select what mode to run:"
echo "[1]: META"
echo "[2]: VIS"
echo "[3]: LIGHT"
echo "[4]: ALL"
echo "[5]: ALL FAST"
echo "[6]: ALL CUSTOM"
echo "[7]: Reconfig"
echo "[8]: Help"
read mode
case "$mode" in
  "1" )
    getmapname
    runqthreemaptwo "-meta -v $mapname"
    imenu
    ;;
  "2" )
    getvisargs
    getmapname
    runqthreemaptwo "$visbasearg -v $mapname"
    imenu
    ;;
  "3" )
    getlightargs
    getmapname
    runqthreemaptwo "$lightbasearg -v $mapname"
    imenu
    ;;
  "4" )
    getmapname
    runqthreemaptwo "-meta -v $mapname"
    runqthreemaptwo "$defvisopts -v $mapname"
    runqthreemaptwo "$deflightopts -v $mapname"
    imenu
    ;;
  "5" )
    getmapname
    runqthreemaptwo "-meta -v $mapname"
    runqthreemaptwo "$fastvisopts -v $mapname"
    runqthreemaptwo "$fastlightopts -v $mapname"
    imenu
    ;;
  "6" )
    getvisargs
    getlightargs
    getmapname
    runqthreemaptwo "-meta -v $mapname"
    runqthreemaptwo "$visbasearg -v $mapname"
    runqthreemaptwo "$lightbasearg -v $mapname"
    imenu
    ;;
  "7" )
    doconfig
    imenu
    ;;
  "8" )
    echo "Help coming soon!"
    imenu
    ;;
  "9" )
    exit 0
    ;;
esac
}
 
#Start of program
configfile="${HOME}/.q3slack.conf"
if [ -e $configfile ]; then
  . $configfile
  echo "Config loaded!"
else
  doconfig
  echo "Config all done!"
  . $configfile
fi
 
if [ "$1" && "$2" ]; then
  if [ 0 < $1 < 8 ]; then
    pathmapname="q3ut4/maps/"
    mapname="${q3ut4tree}${pathmapname}${2}.map"
    if [ -e $mapname ]; then
      case "$1" in
        "1" )
          runqthreemaptwo "-meta -v $mapname"
          ;;
        "2" )
          runqthreemaptwo "$fastvisopts -v $mapname"
          ;;
        "3" )
          runqthreemaptwo "$fastlightopts -v $mapname"
          ;;
        "4" )
          runqthreemaptwo "-meta -v $mapname"
          runqthreemaptwo "$defvisopts -v $mapname"
          runqthreemaptwo "$deflightopts -v $mapname"
          ;;
        "5" )
          runqthreemaptwo "-meta -v $mapname"
          runqthreemaptwo "$fastvisopts -v $mapname"
          runqthreemaptwo "$fastlightopts -v $mapname"
          ;;
        "6" )
          getvisargs
          getlightargs
          runqthreemaptwo "-meta -v $mapname"
          runqthreemaptwo "$visbasearg -v $mapname"
          runqthreemaptwo "$lightbasearg -v $mapname"
          ;;
        "7" )
          doconfig
          ;;
      esac
    else
      echo "$mapname NOT FOUND! Please check and try again."
      exit 0
    fi
  else
    pusage
  fi
else
  imenu
fi