@echo off
rem --------------------------------------------------------------
rem BUILD.BAT for EdMap v1.25+                (by Jeff Rabenhorst)
rem
rem         Edit this file to use a different NODE-BUILDER
rem
rem   Requires STUFFBUF.EXE to insert keystrokes into the buffer
rem   and NPXTEST.EXE to test whether a NPX (80x87) is availible
rem xxand DOOM2WAD.EXE to convert PWAD map entries (DOOM1/DOOM2)xx
rem --------------------------------------------------------------

	if not "%1"=="" goto ONEPARAM
	error Missing WAD filename.
	goto TEXTDESC
:ONEPARAM
	if "%1"=="/?" goto TEXTDESC
	if "%1"=="-?" goto TEXTDESC
	if exist %1.wad goto OKPARAMS
	error %1.wad does not exist.
	goto TEXTDESC
:OKPARAMS
	if exist build.tmp del build.tmp > nul
	copy %1.wad backup.wad > nul
rem       DOOM2WAD %1.wad 0
	copy %1.wad build.wad > nul
	echo Building BSP data...
rem        NPXTEST
rem        if errorlevel 2 echo Software NPX (80x87) emulation.
rem        if errorlevel 1 goto BUILDNOW
rem        goto NONPX
:BUILDNOW
	  STUFFBUF y! > nul
	  IDBSP -fullreject -wad build.wad %1.wad
	if errorlevel 1 goto BUILDFAILED

		echo ÿ
		del build.wad > nul
rem               DOOM2WAD %1.wad %2
		echo ÿ
		echo Finished building PWAD; %1.wad is now playable.
		echo ÿ
		if "%4"=="" goto END
		  STUFFBUF !
		  EDMAPCOM %3 %4 BUILT OK
		goto END
:BUILDFAILED
		copy backup.wad %1.wad > nul
		if "%4"=="" goto FAILTEXT
			  EDMAPCOM %3 %4 PLAYMAP=FALSE
			  EDMAPCOM %3 %4 ERROR BuildFailed
:FAILTEXT
		echo BUILD FAILED!
		echo PWAD RESTORED
		goto END
:NONPX
		if "%4"=="" goto NONPXTEXT
			  EDMAPCOM %3 %4 PLAYMAP=FALSE
			  EDMAPCOM %3 %4 ERROR NoNPX
:NONPXTEXT
		echo BUILD FAILED!
		echo No NPX (80x87) present for builder.
		goto END
:TEXTDESC
	echo ÿ
	echo BUILD.BAT        
	echo   PWAD node-builder (builds BSP data for maps)
	echo ÿ
	echo format: BUILD filename
	echo     ex: BUILD C:\DOOM\PWADS\CASTLE
	echo ÿ
	goto END
:END
rem --------------------------------------------------------------
