@echo off
rem -----------------------------------------
rem Warning: if modifications are made, take care
rem to specify correct pathnames, as the savedir, backup1,
rem and backup2 directories are subject to irretrievable
rem deletion during the normal course of this batch!
rem -----------------------------------------
rem The following variables are provided to simplify any
rem necessary modifications.
re,
rem Modify the following three lines to reflect where
rem Crawl and the saves dir are stored on your PC
set drv=c:
set crawldir=\games\crawl
set savedir=%crawldir%\saves
rem -----------------------------------------
rem Name of crawl *****
rem -----------------------------------------
set crawlexe=crawl*****
rem -----------------------------------------
rem Specifies location of backup directories
rem Important: these two directories are deleted.
rem -----------------------------------------
set backup1=%crawldir%\backup_saves
set backup2=%crawldir%\backup_saves_2
rem -----------------------------------------
rem Specifies where the Choose32***** utility is located (if present)
rem -----------------------------------------
set choosedir=\games
rem -----------------------------------------
rem Checks the pathname assumptions and make
rem a few adjustments if necessary.
rem -----------------------------------------
%drv%
if exist "%crawldir%\%crawlexe%" goto skipverify
rem -----------------------------------------
rem Problem: crawl ***** was not found.
rem Check to see whether there is a need to modify the name of the *****
rem -----------------------------------------
set crawlexe=crawl-tiles*****
if exist "%crawldir%\%crawlexe%" goto skipverify
rem -----------------------------------------
rem Problem: crawl ***** still not found.
rem Check whether the Installer was used for all users.
rem (The Installer can install for all users or only for one.)
rem Note: The ProgramFiles variable is set by the OS.
rem -----------------------------------------
set crawldir=%ProgramFiles%\Crawl
if exist "%crawldir%\%crawlexe%" goto installer
rem -----------------------------------------
rem Installer may have selected just one user.
rem Note: The USERPROFILE variable is set by the OS.
rem -----------------------------------------
set crawldir=%USERPROFILE%\Local Settings\Application Data\Crawl
if not exist "%crawldir%\%crawlexe%" goto skipverify
:installer
rem -----------------------------------------
rem Assume that the Installer was used.
rem Note: The APPDATA variable is set by the OS.
rem -----------------------------------------
set installersave=%APPDATA%\Crawl
set backup1=%installersave%\backup_saves
set backup2=%installersave%\backup_saves_2
set savedir=%installersave%\saves
:skipverify
cls
echo. Environmental variables:
echo.
echo. Drive name is %drv%
echo. Game directory is %crawldir%
echo. Crawl ***** is %crawlexe%
echo.
echo. Saves directory is %savedir%
echo.
echo. Saves are backed up to %backup1%
echo.
echo. and %backup2%.
echo.
set bmsg=The Choose32***** utility was
if not exist "%choosedir%\Choose32*****" set bmsg=%bmsg% not
echo. %bmsg% found at %choosedir%.
echo.
rem --------------------------------------------------------
rem Uncomment the next line to display the environmental variables.
rem pause
rem --------------------------------------------------------
%drv%
cd "%crawldir%"
set backedup=FALSE
if exist %crawlexe% goto begin
echo.
echo. Error: unknown filename. Expecting %crawlexe%.
echo. Suggestion: modify the batch as needed.
echo.
pause
exit
:begin
rem --------------------------------------------------------
rem If player recently backed up saved game, no need to copy
rem --------------------------------------------------------
if %backedup%==TRUE goto housekeeping
rem --------------------------------------------------------
rem Prepare to restore the preserved save files from backup_saves.
rem --------------------------------------------------------
if exist "%backup1%\*.01a" del "%savedir%\*.*" /Q
if exist "%backup1%\sprint\*.01a" del "%savedir%\sprint\*.*" /Q
rem --------------------------------------------------------
rem Restore backup directory to the saves directory.
rem It is necessary to copy the sprint subdirectory.
rem --------------------------------------------------------
if exist "%backup1%\*.01a" copy "%backup1%\*.*" "%savedir%" /Y
if exist "%backup1%\sprint\*.01a" copy "%backup1%\sprint" "%savedir%\sprint" /Y
rem --------------------------------------------------------
rem Housekeeping
rem --------------------------------------------------------
:housekeeping
set backedup=FALSE
if exist "%savedir%\logfile". del "%savedir%\logfile".
if exist "%savedir%\logfile-sprint". del "%savedir%\logfile-sprint".
if exist "%crawldir%\arena.result". del "%crawldir%\arena.result".
echo.You are currently playing the game...
%crawlexe%
rem --------------------------------------------------------
rem Set default messages
rem --------------------------------------------------------
set message=You have quit the game...
set message2=
set message3=
echo. %message%
rem --------------------------------------------------------
rem Existing arena.result indicates Arena was played
rem --------------------------------------------------------
if not exist "%crawldir%\arena.result" goto other_tests
cls
type "%crawldir%\arena.result"
echo.
pause
goto housekeeping
:other_tests
rem --------------------------------------------------------
rem Test for an exit from generic Crawl.
rem --------------------------------------------------------
set logfile=%savedir%\logfile
rem --------------------------------------------------------
rem Missing logfile indicates the current character survived
rem --------------------------------------------------------
if exist "%logfile%" goto testlogfile
rem --------------------------------------------------------
rem Test for an exit from Sprint.
rem --------------------------------------------------------
set logfile=%savedir%\logfile-sprint
if exist "%logfile%" goto testlogfile
set logfile=%savedir%\logfile
rem --------------------------------------------------------
rem Character survived.
rem Check for at least one save file...
rem --------------------------------------------------------
if exist "%savedir%\*.01a" goto normalsave
if exist "%savedir%\sprint\*.01a" goto normalsave
rem --------------------------------------------------------
rem Player hit ESC during intro screens
rem --------------------------------------------------------
goto decision_time
:testlogfile
set message2=Liberalism has science on its side!
set message3=We have the technology to bring you back to life!
rem --------------------------------------------------------
rem If there was a killer, then the current character is dead.
rem This is the most likely scenario.
rem --------------------------------------------------------
find /C "killer=" "%logfile%"
rem --------------------------------------------------------
rem An errorlevel of 1 indicates the search text was not found
rem --------------------------------------------------------
if errorlevel 1 goto quittest
set message=You were defeated by the reactionaries!
goto decision_time
:quittest
rem --------------------------------------------------------
rem Check whether player quit game
rem --------------------------------------------------------
find /C "ktyp=quit" "%logfile%"
if errorlevel 1 goto watertest
set message=You quit the game.
goto decision_time
:watertest
rem --------------------------------------------------------
rem Check for drowning
rem --------------------------------------------------------
find /C "ktyp=water" "%logfile%"
if errorlevel 1 goto lavatest
set message=You drowned.
goto decision_time
:lavatest
rem --------------------------------------------------------
rem Check whether character drowned in lava
rem --------------------------------------------------------
find /C "ktyp=lava" "%logfile%"
if errorlevel 1 goto gastest
set message=You suffered Gollum's fate.
goto decision_time
:gastest
rem --------------------------------------------------------
rem Check whether character was gassed
rem --------------------------------------------------------
find /C "ktyp=cloud" "%logfile%"
if errorlevel 1 goto checkforwin
set message=Noxious gas did you in.
goto decision_time
:checkforwin
rem --------------------------------------------------------
rem If character won, quit.
rem --------------------------------------------------------
find /C "ktyp=win" "%logfile%"
if errorlevel 1 goto starvetest
cls
echo.
echo. Congratulations on your victory!
echo.
pause
exit
:starvetest
rem --------------------------------------------------------
rem Check whether character starved.
rem --------------------------------------------------------
find /C "ktyp=starv" "%logfile%"
if errorlevel 1 goto wildtest
set message=You starved.
goto decision_time
:wildtest
rem --------------------------------------------------------
rem Check whether character slain by wild magic.
rem Any unknown ktyp's will also be trapped here.
rem --------------------------------------------------------
find /C "ktyp=" "%logfile%"
if errorlevel 1 goto normalsave
set message=Wild magic did you in.
goto decision_time
:decision_time
cls
echo Regen.bat for Dungeon Crawl, updated Aug 20th, 2010
echo by igor at
http://techlorebyigor.*************
echo.
set bcounter=0
set bmsg=
if exist "%backup1%\*.01a" set bmsg=Crawl backup available.
if not exist "%backup1%\*.01a" set /a bcounter=%bcounter%+1
if exist "%backup1%\sprint\*.01a" set bmsg=%bmsg% Sprint backup available.
if not exist "%backup1%\sprint\*.01a" set /a bcounter=%bcounter%+1
if %bcounter%==2 set message2=
if %bcounter%==2 set message3=
echo. %message%
echo. %message2%
echo. %message3%
echo.
echo. %bmsg%
echo.
set choose_options=!rq
set choose_label=[!] delete saves, [r]estart, or [q]uit
echo. To restart Crawl, press 'r'
echo. To delete all previous saves and start afresh, press '!'
echo. If you're satisfied with a heroic death, press 'q' to quit.
echo.
rem --------------------------------------------------------
rem Somewhat better functionality is possible with Choose32***** from
rem
http://www.westmesatech.com/editv.html
rem The location of this utility is controlled by the %choosedir% variable.
rem --------------------------------------------------------
if not exist "%choosedir%\Choose32*****" goto simplequery
"%choosedir%\choose32*****" -c %choose_options% -p "%choose_label%" -d r
if errorlevel 3 exit
if errorlevel 2 goto begin
if errorlevel 1 goto deletegames
echo. ERROR: Unexpected response
pause
exit
:simplequery
set /P userinput=Input your command and press Enter.
if "%userinput%"=="" goto decision_time
if /I %userinput%==q exit
if /I %userinput%==r goto begin
if %userinput%==! goto deletegames
goto decision_time
:deletegames
rem --------------------------------------------------------
rem Delete all saved games and start afresh
rem --------------------------------------------------------
if exist "%backup1%" rd "%backup1%" /S /Q
if exist "%backup2%" rd "%backup2%" /S /Q
rem --------------------------------------------------------
rem Spare the subdirectories db and des.
rem --------------------------------------------------------
del "%savedir%\*.*" /Q
if exist "%savedir%\sprint" rd "%savedir%\sprint" /S /Q
goto housekeeping
:normalsave
cls
echo. If you wish to backup your game, press any key to continue.
echo. Otherwise, press Ctrl-C to quit.
if exist "%backup2%" rd /S /Q "%backup2%"
md "%backup2%"
md "%backup2%\sprint"
copy "%backup1%\*.*" "%backup2%" /Y
if exist "%backup1%\sprint" copy "%backup1%\sprint" "%backup2%\sprint" /Y
if exist "%backup1%" rd /S /Q "%backup1%"
md "%backup1%"
md "%backup1%\sprint"
copy "%savedir%\*.*" "%backup1%" /Y
if exist "%savedir%\sprint" copy "%savedir%\sprint" "%backup1%\sprint" /Y
set message=You have backed up your saved game.
set message2=
set message3=
set backedup=TRUE