Split G_DoCompleted into a global part and a level specific part.

This commit is contained in:
Christoph Oelckers 2019-01-29 02:39:14 +01:00
parent 87859b2950
commit 1d748b72a8
5 changed files with 67 additions and 66 deletions

View file

@ -59,7 +59,7 @@ struct event_t
enum gameaction_t : int enum gameaction_t : int
{ {
ga_nothing, ga_nothing,
ga_loadlevel, ga_loadlevel, // not used.
ga_newgame, ga_newgame,
ga_newgame2, ga_newgame2,
ga_recordgame, ga_recordgame,

View file

@ -1037,9 +1037,6 @@ void G_Ticker ()
} }
switch (gameaction) switch (gameaction)
{ {
case ga_loadlevel:
G_DoLoadLevel (-1, false, false);
break;
case ga_recordgame: case ga_recordgame:
G_CheckDemoStatus(); G_CheckDemoStatus();
G_RecordDemo(newdemoname); G_RecordDemo(newdemoname);
@ -1624,7 +1621,6 @@ void FLevelLocals::DoReborn (int playernum, bool freshbot)
BackupSaveName = ""; BackupSaveName = "";
G_InitNew (level.MapName, false); G_InitNew (level.MapName, false);
demoplayback = indemo; demoplayback = indemo;
// gameaction = ga_loadlevel;
} }
} }
else else

View file

@ -538,7 +538,6 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
bglobal.Init (); bglobal.Init ();
} }
level.MapName = mapname;
if (bTitleLevel) if (bTitleLevel)
{ {
gamestate = GS_TITLELEVEL; gamestate = GS_TITLELEVEL;
@ -548,7 +547,7 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
gamestate = GS_LEVEL; gamestate = GS_LEVEL;
} }
G_DoLoadLevel (0, false, !savegamerestore); G_DoLoadLevel (mapname, 0, false, !savegamerestore);
} }
// //
@ -746,47 +745,63 @@ void G_SecretExitLevel (int position)
// //
//========================================================================== //==========================================================================
void G_DoCompleted (void) void G_DoCompleted (void)
{ {
int i;
gameaction = ga_nothing; gameaction = ga_nothing;
if ( gamestate == GS_DEMOSCREEN if ( gamestate == GS_DEMOSCREEN
|| gamestate == GS_FULLCONSOLE || gamestate == GS_FULLCONSOLE
|| gamestate == GS_STARTUP) || gamestate == GS_STARTUP)
{ {
return; return;
} }
if (gamestate == GS_TITLELEVEL) if (gamestate == GS_TITLELEVEL)
{ {
level.MapName = nextlevel; G_DoLoadLevel (nextlevel, startpos, false, false);
G_DoLoadLevel (startpos, false, false);
startpos = 0; startpos = 0;
viewactive = true; viewactive = true;
return; return;
} }
// [RH] Mark this level as having been visited
if (!(level.flags & LEVEL_CHANGEMAPCHEAT))
FindLevelInfo (level.MapName)->flags |= LEVEL_VISITED;
if (automapactive) if (automapactive)
AM_Stop (); AM_Stop ();
// Close the conversation menu if open. // Close the conversation menu if open.
P_FreeStrifeConversations (); P_FreeStrifeConversations ();
wminfo.finished_ep = level.cluster - 1; if (level.DoCompleted(nextlevel, wminfo))
wminfo.LName0 = TexMan.CheckForTexture(level.info->PName, ETextureType::MiscPatch); {
wminfo.current = level.MapName; gamestate = GS_INTERMISSION;
viewactive = false;
automapactive = false;
// [RH] If you ever get a statistics driver operational, adapt this.
// if (statcopy)
// memcpy (statcopy, &wminfo, sizeof(wminfo));
WI_Start (&wminfo);
}
}
bool FLevelLocals::DoCompleted (FString nextlevel, wbstartstruct_t &wminfo)
{
int i;
// [RH] Mark this level as having been visited
if (!(flags & LEVEL_CHANGEMAPCHEAT))
FindLevelInfo (MapName)->flags |= LEVEL_VISITED;
wminfo.finished_ep = cluster - 1;
wminfo.LName0 = TexMan.CheckForTexture(info->PName, ETextureType::MiscPatch);
wminfo.current = MapName;
if (deathmatch && if (deathmatch &&
(dmflags & DF_SAME_LEVEL) && (dmflags & DF_SAME_LEVEL) &&
!(level.flags & LEVEL_CHANGEMAPCHEAT)) !(flags & LEVEL_CHANGEMAPCHEAT))
{ {
wminfo.next = level.MapName; wminfo.next = MapName;
wminfo.LName1 = wminfo.LName0; wminfo.LName1 = wminfo.LName0;
} }
else else
@ -808,32 +823,31 @@ void G_DoCompleted (void)
nextlevel = wminfo.next; nextlevel = wminfo.next;
wminfo.next_ep = FindLevelInfo (wminfo.next)->cluster - 1; wminfo.next_ep = FindLevelInfo (wminfo.next)->cluster - 1;
wminfo.maxkills = level.total_monsters; wminfo.maxkills = total_monsters;
wminfo.maxitems = level.total_items; wminfo.maxitems = total_items;
wminfo.maxsecret = level.total_secrets; wminfo.maxsecret = total_secrets;
wminfo.maxfrags = 0; wminfo.maxfrags = 0;
wminfo.partime = TICRATE * level.partime; wminfo.partime = TICRATE * partime;
wminfo.sucktime = level.sucktime; wminfo.sucktime = sucktime;
wminfo.pnum = consoleplayer; wminfo.pnum = consoleplayer;
wminfo.totaltime = level.totaltime; wminfo.totaltime = totaltime;
for (i=0 ; i<MAXPLAYERS ; i++) for (i=0 ; i<MAXPLAYERS ; i++)
{ {
wminfo.plyr[i].skills = players[i].killcount; wminfo.plyr[i].skills = players[i].killcount;
wminfo.plyr[i].sitems = players[i].itemcount; wminfo.plyr[i].sitems = players[i].itemcount;
wminfo.plyr[i].ssecret = players[i].secretcount; wminfo.plyr[i].ssecret = players[i].secretcount;
wminfo.plyr[i].stime = level.time; wminfo.plyr[i].stime = time;
memcpy (wminfo.plyr[i].frags, players[i].frags memcpy (wminfo.plyr[i].frags, players[i].frags, sizeof(wminfo.plyr[i].frags));
, sizeof(wminfo.plyr[i].frags));
wminfo.plyr[i].fragcount = players[i].fragcount; wminfo.plyr[i].fragcount = players[i].fragcount;
} }
// [RH] If we're in a hub and staying within that hub, take a snapshot // [RH] If we're in a hub and staying within that hub, take a snapshot.
// of the level. If we're traveling to a new hub, take stuff from // If we're traveling to a new hub, take stuff from
// the player and clear the world vars. If this is just an // the player and clear the world vars. If this is just an
// ordinary cluster (not a hub), take stuff from the player, but // ordinary cluster (not a hub), take stuff from the player, but
// leave the world vars alone. // leave the world vars alone.
cluster_info_t *thiscluster = FindClusterInfo (level.cluster); cluster_info_t *thiscluster = FindClusterInfo (cluster);
cluster_info_t *nextcluster = FindClusterInfo (wminfo.next_ep+1); // next_ep is cluster-1 cluster_info_t *nextcluster = FindClusterInfo (wminfo.next_ep+1); // next_ep is cluster-1
EFinishLevelType mode; EFinishLevelType mode;
@ -855,7 +869,7 @@ void G_DoCompleted (void)
} }
// Intermission stats for entire hubs // Intermission stats for entire hubs
G_LeavingHub(&level, mode, thiscluster, &wminfo); G_LeavingHub(this, mode, thiscluster, &wminfo);
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{ {
@ -867,16 +881,16 @@ void G_DoCompleted (void)
if (mode == FINISH_SameHub) if (mode == FINISH_SameHub)
{ // Remember the level's state for re-entry. { // Remember the level's state for re-entry.
if (!(level.flags2 & LEVEL2_FORGETSTATE)) if (!(flags2 & LEVEL2_FORGETSTATE))
{ {
level.SnapshotLevel (); SnapshotLevel ();
// Do not free any global strings this level might reference // Do not free any global strings this level might reference
// while it's not loaded. // while it's not loaded.
level.Behaviors.LockLevelVarStrings(level.levelnum); Behaviors.LockLevelVarStrings(levelnum);
} }
else else
{ // Make sure we don't have a snapshot lying around from before. { // Make sure we don't have a snapshot lying around from before.
level.info->Snapshot.Clean(); info->Snapshot.Clean();
} }
} }
else else
@ -887,30 +901,21 @@ void G_DoCompleted (void)
{ // Reset world variables for the new hub. { // Reset world variables for the new hub.
P_ClearACSVars(false); P_ClearACSVars(false);
} }
level.time = 0; time = 0;
level.maptime = 0; maptime = 0;
level.spawnindex = 0; spawnindex = 0;
} }
finishstate = mode; finishstate = mode;
if (!deathmatch && if (!deathmatch &&
((level.flags & LEVEL_NOINTERMISSION) || ((flags & LEVEL_NOINTERMISSION) ||
((nextcluster == thiscluster) && (thiscluster->flags & CLUSTER_HUB) && !(thiscluster->flags & CLUSTER_ALLOWINTERMISSION)))) ((nextcluster == thiscluster) && (thiscluster->flags & CLUSTER_HUB) && !(thiscluster->flags & CLUSTER_ALLOWINTERMISSION))))
{ {
level.WorldDone (); WorldDone ();
return; return false;
} }
return true;
gamestate = GS_INTERMISSION;
viewactive = false;
automapactive = false;
// [RH] If you ever get a statistics driver operational, adapt this.
// if (statcopy)
// memcpy (statcopy, &wminfo, sizeof(wminfo));
WI_Start (&wminfo);
} }
//========================================================================== //==========================================================================
@ -942,8 +947,9 @@ void DAutosaver::Tick ()
extern gamestate_t wipegamestate; extern gamestate_t wipegamestate;
void G_DoLoadLevel (int position, bool autosave, bool newGame) void G_DoLoadLevel (const FString &nextmapname, int position, bool autosave, bool newGame)
{ {
level.MapName = nextmapname;
static int lastposition = 0; static int lastposition = 0;
gamestate_t oldgs = gamestate; gamestate_t oldgs = gamestate;
int i; int i;
@ -1277,13 +1283,10 @@ void G_DoWorldDone (void)
{ {
// Don't crash if no next map is given. Just repeat the current one. // Don't crash if no next map is given. Just repeat the current one.
Printf ("No next map specified.\n"); Printf ("No next map specified.\n");
} nextlevel = level.MapName;
else
{
level.MapName = nextlevel;
} }
G_StartTravel (); G_StartTravel ();
G_DoLoadLevel (startpos, true, false); G_DoLoadLevel (nextlevel, startpos, true, false);
startpos = 0; startpos = 0;
gameaction = ga_nothing; gameaction = ga_nothing;
viewactive = true; viewactive = true;

View file

@ -475,7 +475,7 @@ void G_ChangeLevel(const char *levelname, int position, int flags, int nextSkill
void G_StartTravel (); void G_StartTravel ();
int G_FinishTravel (); int G_FinishTravel ();
void G_DoLoadLevel (int position, bool autosave, bool newGame); void G_DoLoadLevel (const FString &MapName, int position, bool autosave, bool newGame);
cluster_info_t *FindClusterInfo (int cluster); cluster_info_t *FindClusterInfo (int cluster);
level_info_t *FindLevelInfo (const char *mapname, bool allowdefault=true); level_info_t *FindLevelInfo (const char *mapname, bool allowdefault=true);

View file

@ -91,6 +91,7 @@ class DSpotState;
class DSeqNode; class DSeqNode;
struct FStrifeDialogueNode; struct FStrifeDialogueNode;
class DAutomapBase; class DAutomapBase;
struct wbstartstruct_t;
typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS) typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS)
typedef TMap<FName, int> FDialogueMap; // maps actor class names to dialogue array index typedef TMap<FName, int> FDialogueMap; // maps actor class names to dialogue array index
@ -218,6 +219,7 @@ public:
FPlayerStart *SelectRandomDeathmatchSpot (int playernum, unsigned int selections); FPlayerStart *SelectRandomDeathmatchSpot (int playernum, unsigned int selections);
void DeathMatchSpawnPlayer (int playernum); void DeathMatchSpawnPlayer (int playernum);
FPlayerStart *PickPlayerStart(int playernum, int flags = 0); FPlayerStart *PickPlayerStart(int playernum, int flags = 0);
bool DoCompleted(FString nextlevel, wbstartstruct_t &wminfo);
private: private: