diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 082f3115e..939693661 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -270,7 +270,7 @@ int FParser::T_GetPlayerNum(const svalue_t &arg) //script_error("mobj not a player!\n"); return -1; } - playernum = int(arg.value.mobj->player - players); + playernum = Level->PlayerNum(arg.value.mobj->player); } else playernum = intvalue(arg); @@ -734,7 +734,7 @@ void FParser::SF_PlayerName(void) { player_t *pl=NULL; if (Script->trigger) pl = Script->trigger->player; - if(pl) plnum = int(pl - players); + if(pl) plnum = Level->PlayerNum(pl); else plnum=-1; } else @@ -765,7 +765,7 @@ void FParser::SF_PlayerObj(void) { player_t *pl=NULL; if (Script->trigger) pl = Script->trigger->player; - if(pl) plnum = int(pl - players); + if(pl) plnum = Level->PlayerNum(pl); else plnum=-1; } else @@ -805,7 +805,7 @@ void FParser::SF_Player(void) if(mo && mo->player) // haleyjd: added mo->player { - t_return.value.i = (int)(mo->player - players); + t_return.value.i = Level->PlayerNum(mo->player); } else { diff --git a/src/g_level.cpp b/src/g_level.cpp index 616877c12..c2f61fbc4 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -675,9 +675,9 @@ void FLevelLocals::ChangeLevel(const char *levelname, int position, int flags, i for(int i = 0; i < MAXPLAYERS; i++) { - if (playeringame[i]) + if (PlayerInGame(i)) { - player_t *player = &players[i]; + player_t *player = Players[i]; // Un-crouch all players here. player->Uncrouch(); diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 6706de0c2..cd412d727 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -9648,7 +9648,7 @@ scriptwait: } else { - PushToStack (int(activator->player - players)); + PushToStack (Level->PlayerNum(activator->player)); } break; @@ -10351,7 +10351,7 @@ static void addDefered (level_info_t *i, acsdefered_t::EType type, int script, c } if (who != NULL && who->player != NULL) { - def.playernum = int(who->player - players); + def.playernum = who->Level->PlayerNum(who->player); } else { diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index ccf43c9d9..aaa46d256 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -746,10 +746,10 @@ void P_StartConversation (AActor *npc, AActor *pc, bool facetalker, bool saveang // anyone else talk to the NPC. for (i = 0; i < MAXPLAYERS; i++) { - if (!playeringame[i] || pc->player == &players[i]) + if (!Level->PlayerInGame(i) || pc->player == Level->Players[i]) continue; - if (npc == players[i].ConversationNPC) + if (npc == Level->Players[i]->ConversationNPC) return; } diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 1a6fdbe4a..fab4f2992 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -401,7 +401,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf // fair to count them toward a player's score. if (player && Level->maptime) { - source->player->frags[player - players]++; + source->player->frags[Level->PlayerNum(player)]++; if (player == source->player) // [RH] Cumulative frag count { char buff[256]; @@ -560,7 +560,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf ClientObituary (this, inflictor, source, dmgflags, MeansOfDeath); // [ZZ] fire player death hook - E_PlayerDied(int(player - players)); + E_PlayerDied(Level->PlayerNum(player)); // Death script execution, care of Skull Tag Level->Behaviors.StartTypedScripts (SCRIPT_Death, this, true); @@ -593,7 +593,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf // count environment kills against you if (!source) { - player->frags[player - players]++; + player->frags[Level->PlayerNum(player)]++; player->fragcount--; // [RH] Cumulative frag count } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index d414ee8d2..ce0bcb7f8 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -384,7 +384,7 @@ void AActor::PostSerialize() AddToHash(); if (player) { - if (playeringame[player - players] && + if (Level->PlayerInGame(player) && player->cls != NULL && !(flags4 & MF4_NOSKIN) && state->sprite == GetDefaultByType(player->cls)->SpawnState->sprite) @@ -489,7 +489,7 @@ int AActor::GetTics(FState * newstate) bool AActor::SetState (FState *newstate, bool nofunction) { if (debugfile && player && (player->cheats & CF_PREDICTING)) - fprintf (debugfile, "for pl %td: SetState while predicting!\n", player-players); + fprintf (debugfile, "for pl %d: SetState while predicting!\n", Level->PlayerNum(player)); do { if (newstate == NULL) @@ -5155,7 +5155,7 @@ AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flag DObject::StaticPointerSubstitution (oldactor, p->mo); - E_PlayerRespawned(int(p - players)); + E_PlayerRespawned(PlayerNum(p)); Behaviors.StartTypedScripts (SCRIPT_Respawn, p->mo, true); } } @@ -6765,7 +6765,7 @@ int AActor::GetTeam() // Check for monsters that belong to a player on the team but aren't part of the team themselves. if (myTeam == TEAM_NONE && FriendPlayer != 0) { - myTeam = players[FriendPlayer - 1].userinfo.GetTeam(); + myTeam = Level->Players[FriendPlayer - 1]->userinfo.GetTeam(); } return myTeam; diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 45b394e22..cee4e897d 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -588,13 +588,13 @@ void P_SerializePlayers(FLevelLocals *Level, FSerializer &arc, bool skipload) // Record each player's name, followed by their data. for (i = 0; i < MAXPLAYERS; ++i) { - if (playeringame[i]) + if (Level->PlayerInGame(i)) { if (arc.BeginObject(nullptr)) { - const char *n = players[i].userinfo.GetName(); + const char *n = Level->Players[i]->userinfo.GetName(); arc.StringPtr("playername", n); - players[i].Serialize(arc); + Level->Players[i]->Serialize(arc); arc.EndObject(); } } diff --git a/src/p_user.cpp b/src/p_user.cpp index 7616d954c..9062957d8 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -676,9 +676,10 @@ bool player_t::Resurrect() mo->special1 = 0; // required for the Hexen fighter's fist attack. // This gets set by AActor::Die as flag for the wimpy death and must be reset here. mo->SetState(mo->SpawnState); + int pnum = mo->Level->PlayerNum(this); if (!(mo->flags2 & MF2_DONTTRANSLATE)) { - mo->Translation = TRANSLATION(TRANSLATION_Players, uint8_t(this - players)); + mo->Translation = TRANSLATION(TRANSLATION_Players, uint8_t(pnum)); } if (ReadyWeapon != nullptr) { @@ -693,7 +694,7 @@ bool player_t::Resurrect() // player is now alive. // fire E_PlayerRespawned and start the ACS SCRIPT_Respawn. - E_PlayerRespawned(int(this - players)); + E_PlayerRespawned(pnum); // mo->Level->Behaviors.StartTypedScripts(SCRIPT_Respawn, mo, true); return true; @@ -1124,7 +1125,7 @@ void P_CheckMusicChange(player_t *player) S_ChangeMusic("*"); } } - DPrintf(DMSG_NOTIFY, "MUSINFO change for player %d to %d\n", (int)(player - players), player->MUSINFOactor->args[0]); + DPrintf(DMSG_NOTIFY, "MUSINFO change for player %d to %d\n", (int)player->mo->Level->PlayerNum(player), player->MUSINFOactor->args[0]); } } } diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp index dc6a465b6..9131fe10e 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp @@ -23,6 +23,7 @@ #include "vm.h" #include "d_player.h" #include "hw_postprocessshader.h" +#include "g_levellocals.h" TArray PostProcessShaders; @@ -32,7 +33,7 @@ static bool IsConsolePlayer(player_t *player) AActor *activator = player ? player->mo : nullptr; if (activator == nullptr || activator->player == nullptr) return false; - return int(activator->player - players) == consoleplayer; + return activator->player == activator->Level->GetConsolePlayer(); } static void ShaderSetEnabled(player_t *player, const FString &shaderName, bool value) diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index d4b8f260a..dd674bf80 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -566,7 +566,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, RestoreDamage, RestoreDamage) static int PlayerNumber(AActor *self) { - return self->player ? int(self->player - players) : 0; + return self->player ? self->Level->PlayerNum(self->player) : 0; } DEFINE_ACTION_FUNCTION_NATIVE(AActor, PlayerNumber, PlayerNumber)