/** * \brief Place player in level */ PUBLIC void PL_Spawn( placeonplane_t location, LevelData_t *lvl ) { r_damageflash = 0; Player.position = location; Player.tilex = POS2TILE( location.origin[ 0 ] ); Player.tiley = POS2TILE( location.origin[ 1 ] ); Player.areanumber = lvl->areas[ Player.tilex ][ Player.tiley ]; if( Player.areanumber < 0 ) { Player.areanumber = 36; } Areas_Connect( Player.areanumber ); ClientState.viewangles[ YAW ] = RAD2FINE(location.angle); ClientState.viewangles[ PITCH ] = 0; Player.playstate = ex_playing; }
/** * \brief Load game state from file * \param[in] name Name of save game file to load. * \return 1 on success, otherwise 0 */ PUBLIC int LoadTheGame( const char *name ) { FILE *f; char path[1024]; int version; int i; int oldCompleted; com_snprintf( path, sizeof( path ), "%s%c%s.bin", FS_Userdir(), PATH_SEP, name ); f = fopen( path, "rb" ); if( ! f ) { Com_Printf( "Could not open %s.\n", path ); return 0; } fread( ¤tMap, 1,sizeof(currentMap) , f); if ( currentMap.version != SAVEGAME_VERSION ) { Com_Printf( "Savegame header version mismatch: %i != %i\n", currentMap.version, SAVEGAME_VERSION ); fclose( f ); return 0; } Com_Printf("episode: %i\nmap: %i\n", currentMap.episode, currentMap.map); // load the huds //fread( &huds, 1,sizeof(huds), f); // do a normal map start Cvar_SetValue( skill->name, (float)currentMap.skill ); PL_NewGame( &Player ); oldCompleted = currentMap.levelCompleted; StartGame( currentMap.episode, currentMap.map, currentMap.skill ); Cbuf_Execute(); currentMap.levelCompleted = oldCompleted; // load modifications on top fread( &levelData, 1,sizeof(levelData), f); fread( &LevelRatios, 1,sizeof(LRstruct), f ); fread( &levelstate, 1,sizeof(levelstate), f ); fread( Guards, 1,sizeof(Guards), f ); fread( areaconnect, 1,sizeof(areaconnect), f ); fread( areabyplayer, 1,sizeof(areabyplayer), f ); fread( &PWall, 1,sizeof(PWall), f ); fread( &Player, 1,sizeof(Player), f ); fread( &version, 1,sizeof(version), f ); fclose( f ); ClientState.viewangles[ YAW ] = RAD2FINE(Player.position.angle); ClientState.viewangles[ PITCH ] = RAD2FINE(Player.position.pitch); if ( version != SAVEGAME_VERSION ) { Com_Printf( "Savegame trailer version mismatch: %i != %i\n", version, SAVEGAME_VERSION ); return 0; } // turn the r_world->Doors.doors back to pointers for ( i = 0 ; i < r_world->Doors.doornum ; i++ ) { int index = (int)r_world->Doors.Doors[i]; assert( index >= 0 && index < 4096 ); r_world->Doors.Doors[i] = &r_world->Doors.DoorMap[0][0] + index; } return 1; }