- redirect most references to the global players array through FLevelLocals.
The Map loader may not access any global state at all - everything it can touch must be exchangable. Furthermore, if we want to sandbox each level, there may be no direct access to any kind of global state whatsoever from the play code.
This commit is contained in:
parent
c15212ca82
commit
8bbdee5c28
19 changed files with 259 additions and 189 deletions
|
|
@ -835,12 +835,12 @@ bool FLevelLocals::DoCompleted (FString nextlevel, wbstartstruct_t &wminfo)
|
|||
|
||||
for (i=0 ; i<MAXPLAYERS ; i++)
|
||||
{
|
||||
wminfo.plyr[i].skills = players[i].killcount;
|
||||
wminfo.plyr[i].sitems = players[i].itemcount;
|
||||
wminfo.plyr[i].ssecret = players[i].secretcount;
|
||||
wminfo.plyr[i].skills = Players[i]->killcount;
|
||||
wminfo.plyr[i].sitems = Players[i]->itemcount;
|
||||
wminfo.plyr[i].ssecret = Players[i]->secretcount;
|
||||
wminfo.plyr[i].stime = time;
|
||||
memcpy (wminfo.plyr[i].frags, players[i].frags, sizeof(wminfo.plyr[i].frags));
|
||||
wminfo.plyr[i].fragcount = players[i].fragcount;
|
||||
memcpy (wminfo.plyr[i].frags, Players[i]->frags, sizeof(wminfo.plyr[i].frags));
|
||||
wminfo.plyr[i].fragcount = Players[i]->fragcount;
|
||||
}
|
||||
|
||||
// [RH] If we're in a hub and staying within that hub, take a snapshot.
|
||||
|
|
@ -1035,11 +1035,11 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
|
|||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i] && (deathmatch || players[i].playerstate == PST_DEAD))
|
||||
players[i].playerstate = PST_ENTER; // [BC]
|
||||
memset (players[i].frags,0,sizeof(players[i].frags));
|
||||
if (PlayerInGame(i) && (deathmatch || Players[i]->playerstate == PST_DEAD))
|
||||
Players[i]->playerstate = PST_ENTER; // [BC]
|
||||
memset (Players[i]->frags,0,sizeof(Players[i]->frags));
|
||||
if (!(dmflags2 & DF2_YES_KEEPFRAGS) && (alwaysapplydmflags || deathmatch))
|
||||
players[i].fragcount = 0;
|
||||
Players[i]->fragcount = 0;
|
||||
}
|
||||
|
||||
if (changeflags & CHANGELEVEL_NOMONSTERS)
|
||||
|
|
@ -1093,19 +1093,19 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
|
|||
{
|
||||
for (int i = 0; i<MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i] && players[i].mo != NULL)
|
||||
P_PlayerStartStomp(players[i].mo);
|
||||
if (PlayerInGame(i) && Players[i]->mo != nullptr)
|
||||
P_PlayerStartStomp(Players[i]->mo);
|
||||
}
|
||||
}
|
||||
|
||||
// For each player, if they are viewing through a player, make sure it is themselves.
|
||||
for (int ii = 0; ii < MAXPLAYERS; ++ii)
|
||||
{
|
||||
if (playeringame[ii])
|
||||
if (PlayerInGame(ii))
|
||||
{
|
||||
if (players[ii].camera == NULL || players[ii].camera->player != NULL)
|
||||
if (Players[ii]->camera == nullptr || Players[ii]->camera->player != nullptr)
|
||||
{
|
||||
players[ii].camera = players[ii].mo;
|
||||
Players[ii]->camera = Players[ii]->mo;
|
||||
}
|
||||
|
||||
if (savegamerestore)
|
||||
|
|
@ -1119,7 +1119,7 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
|
|||
if (fromSnapshot)
|
||||
{
|
||||
// ENTER scripts are being handled when the player gets spawned, this cannot be changed due to its effect on voodoo dolls.
|
||||
Behaviors.StartTypedScripts(SCRIPT_Return, players[ii].mo, true);
|
||||
Behaviors.StartTypedScripts(SCRIPT_Return, Players[ii]->mo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1181,8 +1181,8 @@ void FLevelLocals::WorldDone (void)
|
|||
// Strife needs a special case here to choose between good and sad ending. Bad is handled elsewhere.
|
||||
if (endsequence == NAME_Inter_Strife)
|
||||
{
|
||||
if (players[0].mo->FindInventory (NAME_QuestItem25) ||
|
||||
players[0].mo->FindInventory (NAME_QuestItem28))
|
||||
if (Players[0]->mo->FindInventory (NAME_QuestItem25) ||
|
||||
Players[0]->mo->FindInventory (NAME_QuestItem28))
|
||||
{
|
||||
endsequence = NAME_Inter_Strife_Good;
|
||||
}
|
||||
|
|
@ -1317,12 +1317,12 @@ void FLevelLocals::StartTravel ()
|
|||
{
|
||||
if (playeringame[i])
|
||||
{
|
||||
AActor *pawn = players[i].mo;
|
||||
AActor *pawn = Players[i]->mo;
|
||||
AActor *inv;
|
||||
players[i].camera = nullptr;
|
||||
Players[i]->camera = nullptr;
|
||||
|
||||
// Only living players travel. Dead ones get a new body on the new level.
|
||||
if (players[i].health > 0)
|
||||
if (Players[i]->health > 0)
|
||||
{
|
||||
pawn->UnlinkFromWorld (nullptr);
|
||||
int tid = pawn->tid; // Save TID
|
||||
|
|
@ -1721,14 +1721,14 @@ void FLevelLocals::UnSnapshotLevel (bool hubLoad)
|
|||
while ((pawn = next) != 0)
|
||||
{
|
||||
next = it.Next();
|
||||
if (pawn->player == NULL || pawn->player->mo == NULL || !playeringame[pawn->player - players])
|
||||
if (pawn->player == nullptr || pawn->player->mo == nullptr || !PlayerInGame(pawn->player))
|
||||
{
|
||||
int i;
|
||||
|
||||
// If this isn't the unmorphed original copy of a player, destroy it, because it's extra.
|
||||
for (i = 0; i < MAXPLAYERS; ++i)
|
||||
{
|
||||
if (playeringame[i] && players[i].morphTics && players[i].mo->alternative == pawn)
|
||||
if (PlayerInGame(i) && Players[i]->morphTics && Players[i]->mo->alternative == pawn)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue