From c013e72caa348851eb3bed0f421d478ac9e8ba15 Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Thu, 8 Sep 2011 01:28:26 +0000 Subject: [PATCH] - Backported VisibleToTeam and VisibleToPlayerClass from Skulltag with some modifications. SVN r3290 (trunk) --- src/actor.h | 9 +++++++++ src/p_mobj.cpp | 29 ++++++++++++++++++++++++++++ src/r_things.cpp | 3 ++- src/thingdef/thingdef_properties.cpp | 18 +++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/actor.h b/src/actor.h index e7dece16b..713fc0139 100644 --- a/src/actor.h +++ b/src/actor.h @@ -763,6 +763,8 @@ public: return bloodcls; } + bool IsVisibleToPlayer() const; + // Calculate amount of missile damage virtual int GetMissileDamage(int mask, int add); @@ -814,6 +816,13 @@ public: DWORD flags4; // [RH] Even more flags! DWORD flags5; // OMG! We need another one. DWORD flags6; // Shit! Where did all the flags go? + + // [BB] If 0, everybody can see the actor, if > 0, only members of team (VisibleToTeam-1) can see it. + DWORD VisibleToTeam; + + // [BB] If NAME_None, all players can see the actor, else only players whose playerclass name is VisibleToPlayerClass can see it. + FNameNoInit VisibleToPlayerClass; + int special1; // Special info int special2; // Special info int health; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 36339ffee..814fb1e42 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -310,6 +310,7 @@ void AActor::Serialize (FArchive &arc) << smokecounter << BlockingMobj << BlockingLine + << VisibleToTeam // [BB] << pushfactor << Species << Score; @@ -871,6 +872,34 @@ bool AActor::CheckLocalView (int playernum) const return false; } +//============================================================================ +// +// AActor :: IsVisibleToPlayer +// +// Returns true if this actor should be seen by the console player. +// +//============================================================================ + +bool AActor::IsVisibleToPlayer() const +{ + // [BB] Safety check. This should never be NULL. Nevertheless, we return true to leave the default ZDoom behavior unaltered. + if ( players[consoleplayer].camera == NULL ) + return true; + + if ( VisibleToTeam != 0 && teamplay && + VisibleToTeam-1 != players[consoleplayer].userinfo.team ) + return false; + + const player_t* pPlayer = players[consoleplayer].camera->player; + + if ( ( VisibleToPlayerClass != NAME_None ) + && pPlayer && pPlayer->mo && ( VisibleToPlayerClass != pPlayer->mo->GetClass()->TypeName ) ) + return false; + + // [BB] Passed all checks. + return true; +} + //============================================================================ // // AActor :: ConversationAnimation diff --git a/src/r_things.cpp b/src/r_things.cpp index f604549c6..ec8ec89f1 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -495,7 +495,8 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor // Don't waste time projecting sprites that are definitely not visible. if (thing == NULL || (thing->renderflags & RF_INVISIBLE) || - !thing->RenderStyle.IsVisible(thing->alpha)) + !thing->RenderStyle.IsVisible(thing->alpha) || + !thing->IsVisibleToPlayer()) { return; } diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 558caa6c1..04ffd9d28 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -1234,6 +1234,24 @@ DEFINE_PROPERTY(designatedteam, I, Actor) defaults->DesignatedTeam = val; } +//========================================================================== +// [BB] +//========================================================================== +DEFINE_PROPERTY(visibletoteam, I, Actor) +{ + PROP_INT_PARM(i, 0); + defaults->VisibleToTeam=i+1; +} + +//========================================================================== +// [BB] +//========================================================================== +DEFINE_PROPERTY(visibletoplayerclass, S, Actor) +{ + PROP_STRING_PARM(n, 0); + defaults->VisibleToPlayerClass = n; +} + //========================================================================== // // Special inventory properties