From faa122ede3af7128fd452b66d9ccea0b1accbbd5 Mon Sep 17 00:00:00 2001
From: Braden Obrzut <admin@maniacsvault.net>
Date: Sat, 10 Sep 2011 04:24:40 +0000
Subject: [PATCH] - Adjust VisibleToPlayerClass to accept multiple classes as
 well as work with inheritance.

SVN r3291 (trunk)
---
 src/actor.h                          |  3 ---
 src/info.h                           |  1 +
 src/p_mobj.cpp                       | 18 +++++++++++++++---
 src/thingdef/thingdef_properties.cpp |  9 ++++++---
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/actor.h b/src/actor.h
index 713fc0139..374dc9b89 100644
--- a/src/actor.h
+++ b/src/actor.h
@@ -820,9 +820,6 @@ public:
 	// [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/info.h b/src/info.h
index 66d564606..0ac7a0fed 100644
--- a/src/info.h
+++ b/src/info.h
@@ -210,6 +210,7 @@ struct FActorInfo
 	PainChanceList *PainChances;
 	PainFlashList *PainFlashes;
 	FPlayerColorSetMap *ColorSets;
+	TArray<const PClass *> VisibleToPlayerClass;
 };
 
 class FDoomEdMap
diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp
index 814fb1e42..73a4cd49b 100644
--- a/src/p_mobj.cpp
+++ b/src/p_mobj.cpp
@@ -892,9 +892,21 @@ bool AActor::IsVisibleToPlayer() const
 
 	const player_t* pPlayer = players[consoleplayer].camera->player;
 
-	if ( ( VisibleToPlayerClass != NAME_None )
-		&& pPlayer && pPlayer->mo && ( VisibleToPlayerClass != pPlayer->mo->GetClass()->TypeName ) )
-		return false;
+	if(pPlayer && pPlayer->mo && GetClass()->ActorInfo->VisibleToPlayerClass.Size() > 0)
+	{
+		bool visible = false;
+		for(unsigned int i = 0;i < GetClass()->ActorInfo->VisibleToPlayerClass.Size();++i)
+		{
+			const PClass *cls = GetClass()->ActorInfo->VisibleToPlayerClass[i];
+			if(cls && pPlayer->mo->GetClass()->IsDescendantOf(cls))
+			{
+				visible = true;
+				break;
+			}
+		}
+		if(!visible)
+			return false;
+	}
 
 	// [BB] Passed all checks.
 	return true;
diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp
index 04ffd9d28..22264b683 100644
--- a/src/thingdef/thingdef_properties.cpp
+++ b/src/thingdef/thingdef_properties.cpp
@@ -1246,10 +1246,13 @@ DEFINE_PROPERTY(visibletoteam, I, Actor)
 //==========================================================================
 // [BB]
 //==========================================================================
-DEFINE_PROPERTY(visibletoplayerclass, S, Actor)
+DEFINE_PROPERTY(visibletoplayerclass, S_s, Actor)
 {
-	PROP_STRING_PARM(n, 0);
-	defaults->VisibleToPlayerClass = n;
+	for(unsigned int i = 0;i < PROP_PARM_COUNT;++i)
+	{
+		PROP_STRING_PARM(n, i);
+		info->VisibleToPlayerClass.Push(FindClassTentative(n, "PlayerPawn"));
+	}
 }
 
 //==========================================================================