Fixed startpos not saving

Will now load properly from a save game preventing respawning at the wrong player starts.
This commit is contained in:
Boondorl 2024-11-03 20:40:37 -05:00 committed by Rachael Alexanderson
parent 85cefd8516
commit 0fe2d72b75
2 changed files with 16 additions and 8 deletions

View file

@ -96,6 +96,8 @@
static FRandom pr_dmspawn ("DMSpawn"); static FRandom pr_dmspawn ("DMSpawn");
static FRandom pr_pspawn ("PlayerSpawn"); static FRandom pr_pspawn ("PlayerSpawn");
extern int startpos, laststartpos;
bool WriteZip(const char* filename, const FileSys::FCompressedBuffer* content, size_t contentcount); bool WriteZip(const char* filename, const FileSys::FCompressedBuffer* content, size_t contentcount);
bool G_CheckDemoStatus (void); bool G_CheckDemoStatus (void);
void G_ReadDemoTiccmd (ticcmd_t *cmd, int player); void G_ReadDemoTiccmd (ticcmd_t *cmd, int player);
@ -2146,7 +2148,9 @@ void G_DoLoadGame ()
arc("ticrate", time[0]) arc("ticrate", time[0])
("leveltime", time[1]) ("leveltime", time[1])
("globalfreeze", globalfreeze); ("globalfreeze", globalfreeze)
("startpos", startpos)
("laststartpos", laststartpos);
// dearchive all the modifications // dearchive all the modifications
level.time = Scale(time[1], TICRATE, time[0]); level.time = Scale(time[1], TICRATE, time[0]);
@ -2434,6 +2438,10 @@ void G_DoSaveGame (bool okForQuicksave, bool forceQuicksave, FString filename, c
savegameglobals("leveltime", level.time); savegameglobals("leveltime", level.time);
} }
savegameglobals("globalfreeze", globalfreeze)
("startpos", startpos)
("laststartpos", laststartpos);
STAT_Serialize(savegameglobals); STAT_Serialize(savegameglobals);
FRandom::StaticWriteRNGState(savegameglobals); FRandom::StaticWriteRNGState(savegameglobals);
P_WriteACSDefereds(savegameglobals); P_WriteACSDefereds(savegameglobals);

View file

@ -111,6 +111,8 @@ EXTERN_CVAR (Int, disableautosave)
EXTERN_CVAR (String, playerclass) EXTERN_CVAR (String, playerclass)
extern uint8_t globalfreeze, globalchangefreeze; extern uint8_t globalfreeze, globalchangefreeze;
int startpos = 0; // [RH] Support for multiple starts per level
int laststartpos = 0;
#define SNAP_ID MAKE_ID('s','n','A','p') #define SNAP_ID MAKE_ID('s','n','A','p')
#define DSNP_ID MAKE_ID('d','s','N','p') #define DSNP_ID MAKE_ID('d','s','N','p')
@ -652,7 +654,9 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
gamestate = GS_LEVEL; gamestate = GS_LEVEL;
} }
G_DoLoadLevel (mapname, 0, false, !savegamerestore); if (!savegamerestore)
startpos = laststartpos = 0;
G_DoLoadLevel (mapname, startpos, false, !savegamerestore);
if (!savegamerestore && (gameinfo.gametype == GAME_Strife || (SBarInfoScript[SCRIPT_CUSTOM] != nullptr && SBarInfoScript[SCRIPT_CUSTOM]->GetGameType() == GAME_Strife))) if (!savegamerestore && (gameinfo.gametype == GAME_Strife || (SBarInfoScript[SCRIPT_CUSTOM] != nullptr && SBarInfoScript[SCRIPT_CUSTOM]->GetGameType() == GAME_Strife)))
{ {
@ -669,7 +673,6 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
// G_DoCompleted // G_DoCompleted
// //
static FString nextlevel; static FString nextlevel;
static int startpos; // [RH] Support for multiple starts per level
extern int NoWipe; // [RH] Don't wipe when travelling in hubs extern int NoWipe; // [RH] Don't wipe when travelling in hubs
static int changeflags; static int changeflags;
static bool unloading; static bool unloading;
@ -1100,7 +1103,6 @@ void G_DoCompleted (void)
if (gamestate == GS_TITLELEVEL) if (gamestate == GS_TITLELEVEL)
{ {
G_DoLoadLevel (nextlevel, startpos, false, false); G_DoLoadLevel (nextlevel, startpos, false, false);
startpos = 0;
viewactive = true; viewactive = true;
return; return;
} }
@ -1373,7 +1375,6 @@ void G_DoLoadLevel(const FString &nextmapname, int position, bool autosave, bool
void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool autosave, bool newGame) void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool autosave, bool newGame)
{ {
MapName = nextmapname; MapName = nextmapname;
static int lastposition = 0;
int i; int i;
if (NextSkill >= 0) if (NextSkill >= 0)
@ -1385,9 +1386,9 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
} }
if (position == -1) if (position == -1)
position = lastposition; position = laststartpos;
else else
lastposition = position; laststartpos = position;
Init(); Init();
StatusBar->DetachAllMessages (); StatusBar->DetachAllMessages ();
@ -1575,7 +1576,6 @@ void G_DoWorldDone (void)
} }
primaryLevel->StartTravel (); primaryLevel->StartTravel ();
G_DoLoadLevel (nextlevel, startpos, true, false); G_DoLoadLevel (nextlevel, startpos, true, false);
startpos = 0;
gameaction = ga_nothing; gameaction = ga_nothing;
viewactive = true; viewactive = true;
} }