@echo off

rem ------ Collision Mesh -------

if "%1"=="col" goto collide
if "%1"=="COL" goto collide
if "%1"=="coll" goto collide
if "%1"=="COLL" goto collide

goto nocoll

:collide

collconv %CWLDDIR%\%LEVNAME%.x %CWLDDIR%\%LEVNAME%1.raw %CCONV_ARGS%

if errorlevel 1 goto colerr
goto nocoll

:colerr

echo The Collision failed. Try MAKECOLL %LEVNAME% instead
echo to see if it's a batch-depth problem


:nocoll

bff_coll %CWLDDIR%\%LEVNAME%.raw %DESTFILE% /create /dat
if errorlevel 1 goto ending

rem ------ Level Mesh -------

if exist %CWLDDIR%\LNDPSA\%LEVNAME%.lnd goto genesis

call makemesh %LEVNAME% %MMESH_ARGS%
if errorlevel 1 goto ending

bff_psa %CWLDDIR%\%LEVNAME%.wld %DESTFILE% /halfg /noanim
rem /fogged
if errorlevel 1 goto ending

goto meshdone

:genesis

bff_coll  %CWLDDIR%\LNDPSA\%LEVNAME%.lnd %DESTFILE%
if errorlevel 1 goto ending

bff_psa  %CWLDDIR%\LNDPSA\%LEVNAME%.lnd %DESTFILE% /halfg
rem /fogged
if errorlevel 1 goto ending

scripted %CWLDDIR%\LNDPSA\%LEVNAME%.lnd %CWLDDIR%\LNDPSA\%LEVNAME%.lev -psx
if errorlevel 1 goto ending

@move %CWLDDIR%\LNDPSA\%LEVNAME%.lev %DESTDIR%\%SUBDIR%


:meshdone

rem ------ Textures -------
rem call maketex %LEVNAME%
cd %CWLDDIR%\textures
doschop -u -f%CWLDDIR%\%LEVNAME%.SPT *.bmp >errlst.txt
cd c:\psx\whack\glovsrc
if errorlevel 1 goto ending

move %CWLDDIR%\%LEVNAME%.spt %DESTDIR%\%SUBDIR%


rem ------ Sky -------

if exist %CWLDDIR%\%LEVNAME%.sky bff_psa %CWLDDIR%\%LEVNAME%.sky %DESTFILE% /rename sky


rem copy %CWLDDIR%\%LEVNAME%.sky %DESTDIR%\%SUBDIR%

goto alright


:ending

echo ***** THERE WERE ERRORS *****


:alright

