diff --git a/src/actor.h b/src/actor.h index 12b775a10..5574f864a 100644 --- a/src/actor.h +++ b/src/actor.h @@ -768,6 +768,8 @@ public: return bloodcls; } + inline void SetFriendPlayer(player_t *player); + bool IsVisibleToPlayer() const; // Calculate amount of missile damage diff --git a/src/d_player.h b/src/d_player.h index f98a88f4d..aa0128848 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -424,6 +424,18 @@ FArchive &operator<< (FArchive &arc, player_t *&p); void P_CheckPlayerSprites(); +inline void AActor::SetFriendPlayer(player_t *player) +{ + if (player == NULL) + { + FriendPlayer = 0; + } + else + { + FriendPlayer = int(player - players) + 1; + } +} + #define CROUCHSPEED (FRACUNIT/12) diff --git a/src/g_hexen/a_summon.cpp b/src/g_hexen/a_summon.cpp index 69c0238ba..cbb8a3854 100644 --- a/src/g_hexen/a_summon.cpp +++ b/src/g_hexen/a_summon.cpp @@ -72,10 +72,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Summon) mo->tracer = self->tracer; // Pointer to master AInventory *power = Spawn (0, 0, 0, NO_REPLACE); power->CallTryPickup (self->tracer); - if (self->tracer->player != NULL) - { - mo->FriendPlayer = int(self->tracer->player - players + 1); - } + mo->SetFriendPlayer(self->tracer->player); } // Make smoke puff diff --git a/src/g_strife/a_rebels.cpp b/src/g_strife/a_rebels.cpp index a9faf1671..58a2f02d1 100644 --- a/src/g_strife/a_rebels.cpp +++ b/src/g_strife/a_rebels.cpp @@ -100,7 +100,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Beacon) { rebel->Translation = owner->Translation; } - rebel->FriendPlayer = owner->player != NULL ? BYTE(owner->player - players + 1) : 0; + rebel->SetFriendPlayer(owner->player); // Set the rebel's target to whatever last hurt the player, so long as it's not // one of the player's other rebels. if (owner->target != NULL && !rebel->IsFriend (owner->target)) diff --git a/src/g_strife/a_strifeweapons.cpp b/src/g_strife/a_strifeweapons.cpp index 1194f9237..b2abb4b43 100644 --- a/src/g_strife/a_strifeweapons.cpp +++ b/src/g_strife/a_strifeweapons.cpp @@ -532,13 +532,9 @@ AActor *P_SpawnSubMissile (AActor *source, const PClass *type, AActor *target) { other->FriendPlayer = source->FriendPlayer; } - else if (target->player != NULL) - { - other->FriendPlayer = int(target->player - players) + 1; - } else { - other->FriendPlayer = 0; + other->SetFriendPlayer(target->player); } } @@ -925,7 +921,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireSigil1) } if (spot != NULL) { - spot->FriendPlayer = int(player-players)+1; + spot->SetFriendPlayer(player); spot->target = self; } } diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 366519890..857eba9d5 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -2656,7 +2656,7 @@ int DoSetMaster (AActor *self, AActor *master) self->master = NULL; level.total_monsters -= self->CountsAsKill(); self->flags|=MF_FRIENDLY; - self->FriendPlayer = int(master->player-players+1); + self->SetFriendPlayer(master->player); AActor * attacker=master->player->attacker; if (attacker) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 5990650ea..31138ad44 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5387,14 +5387,7 @@ AActor *P_SpawnMissileXYZ (fixed_t x, fixed_t y, fixed_t z, if (th->flags4 & MF4_SPECTRAL) { - if (owner->player != NULL) - { - th->FriendPlayer = int(owner->player - players) + 1; - } - else - { - th->FriendPlayer = 0; - } + th->SetFriendPlayer(owner->player); } return (!checkspawn || P_CheckMissileSpawn (th)) ? th : NULL; @@ -5424,14 +5417,7 @@ AActor * P_OldSpawnMissile(AActor * source, AActor * owner, AActor * dest, const if (th->flags4 & MF4_SPECTRAL) { - if (owner->player != NULL) - { - th->FriendPlayer = int(owner->player - players) + 1; - } - else - { - th->FriendPlayer = 0; - } + th->SetFriendPlayer(owner->player); } P_CheckMissileSpawn(th); @@ -5520,14 +5506,7 @@ AActor *P_SpawnMissileAngleZSpeed (AActor *source, fixed_t z, if (mo->flags4 & MF4_SPECTRAL) { - if (owner->player != NULL) - { - mo->FriendPlayer = int(owner->player - players) + 1; - } - else - { - mo->FriendPlayer = 0; - } + mo->SetFriendPlayer(owner->player); } return (!checkspawn || P_CheckMissileSpawn(mo)) ? mo : NULL; @@ -5642,14 +5621,7 @@ AActor *P_SpawnPlayerMissile (AActor *source, fixed_t x, fixed_t y, fixed_t z, if (MissileActor->flags4 & MF4_SPECTRAL) { - if (source->player != NULL) - { - MissileActor->FriendPlayer = int(source->player - players) + 1; - } - else - { - MissileActor->FriendPlayer = 0; - } + MissileActor->SetFriendPlayer(source->player); } if (P_CheckMissileSpawn (MissileActor)) { diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index ee09be238..0edbb87bd 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -963,11 +963,11 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomMissile) missile->tracer=self->target; } // we must redo the spectral check here because the owner is set after spawning so the FriendPlayer value may be wrong - if (missile->flags4&MF4_SPECTRAL) + if (missile->flags4 & MF4_SPECTRAL) { - if (missile->target != NULL && missile->target->player != NULL) + if (missile->target != NULL) { - missile->FriendPlayer = int(missile->target->player - players) + 1; + missile->SetFriendPlayer(missile->target->player); } else { @@ -1737,8 +1737,8 @@ static bool InitSpawnedItem(AActor *self, AActor *mo, int flags) else if (originator->player) { // A player always spawns a monster friendly to him - mo->flags|=MF_FRIENDLY; - mo->FriendPlayer = int(originator->player-players+1); + mo->flags |= MF_FRIENDLY; + mo->SetFriendPlayer(originator->player); AActor * attacker=originator->player->attacker; if (attacker)