@echo off
copy %1.wad backup.wad
if exist tmp.dwd erase tmp.dwd
doom2wad %1.wad 0
wad_dwd %1.wad tmp.dwd
if errorlevel 1 goto buildfailed
erase %1.wad
idbsp tmp.dwd %1.wad
if errorlevel 1 goto buildfailed
echo .
doom2wad %1.wad %2
echo Build successful.
goto end
:buildfailed
copy backup.wad %1.wad
echo .
echo .
echo ****************** BUILD FAILED *********************
echo  NOTE if you chose "play map":
echo   DOOM will still try to load the PWAD.
echo   If it doesn't quit on its own, hit Ctrl-Break
echo   to stop it during the "Init DOOM refresh daemon".
echo   EdMap will re-load automatically.
echo -----------------------------------------------------
pause
:end
