@echo off

@echo ===----------------------------------------------
@echo === Deathball Launcher
@echo ===----------------------------------------------


@echo === Environment Check ===

if exist  ..\Deathball\PlayDeathball.bat goto Defcheck
echo 'PlayDeathball.bat' is missing from your UT2004\Deathball Deathball folder. Please reinstall Deathball.
pause
goto end

:Defcheck
IF EXIST ..\System\Default.ini goto DBUCheck
echo 'UT2004\System\Default.ini' is missing! Please reinstall UT2004!
pause
goto end

:DBUCheck
IF EXIST System\Deathball.u goto DBAICheck
echo 'Deathball.u' Package missing! Please reinstall Deathball.
pause
goto end

:DBAICheck
IF EXIST System\DeathballAI.u goto DBRCCheck
echo 'DeathballAI.u' Package missing! Please reinstall Deathball.
pause
goto end

:DBRCCheck
IF EXIST System\Deathball_rc.u goto EntryCheck 
echo 'Deathball_rc.u' Package missing! Please reinstall Deathball.
pause
goto end

:EntryCheck
IF EXIST Maps\Entry.ut2 goto UCLProcess
echo 'Deathball\Maps\Entry.ut2' missing. Using UT2k4 default Entry map.
copy ..\Maps\Entry.ut2 Maps\Entry.ut2 > NUL

:UCLProcess
IF EXIST System\Deathball.ucl goto AutoUpdate
echo === Exporting Deathball.ucl ===
..\System\ucc exportcache -Mod=Deathball -v Deathball.u Deathball_rc.u DeathballAI.u Deathball.ucl

IF NOT errorlevel 1 goto UCLPostCheck
echo ERROR! Unable to run UCC.
pause			
goto end
	
:UCLPostCheck
IF EXIST System\Deathball.ucl goto AutoUpdate
echo ERROR! Unable to export Deathball.ucl! 
pause			
goto end


:AutoUpdate
AutoUpdate.exe /S /D=%CD%

@echo === Starting Deathball ===

@REM Use START always when possible!
IF DEFINED OS (
	IF %OS%==Windows_NT (
@echo %OS%
cd..
cd system
start ut2004.exe -Mod=Deathball
	)
)
	IF %OS%!=Windows_NT (
..\System\ut2004.exe -Mod=Deathball	)


:end

