Another part of the single player game is restarting the level after you have died. You should have all your health, weapons, ammo and items that you had when you started the level originally so these must be reloaded just as they were when you did a level change. As well, there is one other complicating factor. Besides entering a level via a level change you may have entered the level through a saved game. In this case you want to reload the saved game rather than start at the beginning of the level.
The source code changes to implement this feature are :
In g_active.c in function ClientThink_real about line 998 add :
if ( client->ps.stats[STAT_HEALTH] <= 0 ) {
// wait for the attack button to be pressed
if ( level.time > client->respawnTime ) {
#ifndef SINGLEPLAYER // ignore forced respawn
// forcerespawn is to prevent users from waiting out powerups
if ( g_forcerespawn.integer > 0 &&
( level.time - client->respawnTime ) > g_forcerespawn.integer * 1000 ) {
respawn( ent );
return;
}
#endif
// pressing attack or use is the normal respawn method
if ( ucmd->buttons & ( BUTTON_ATTACK | BUTTON_USE_HOLDABLE ) ) {
#ifndef SINGLEPLAYER
respawn( ent );
#else
char stmap[MAX_QPATH];
char buf[MAX_QPATH];
trap_Cvar_VariableStringBuffer( "mapname", stmap, sizeof(stmap) );
Com_sprintf(buf,MAX_QPATH,"map %s",stmap);
trap_Cvar_Set( "nextmap", buf );
trap_Cvar_VariableStringBuffer( "ui_LoadGame", buf, sizeof(buf) );
if (buf[0])
trap_Cvar_Set("Save_Loading", "1"); // reload saved game
else
trap_Cvar_Set("Save_Loading", "3"); // restart level
ExitLevel();
#endif
}
}
return;
}
This sets up a level reload using the name of the current map, which will load the persistant attributes if we got here by a level change. The ui_LoadGame cvar is checked to see if it holds a saved game name and, if it does, the Save_Loading cvar is set to reload that saved game. Otherwise it is set to restart the current map.