From a8ba2a99eab665a935b28e5b268f028d3710c818 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Tue, 31 Oct 2006 21:49:45 +0000
Subject: [PATCH] - Fixed: SetActorPitch with a 0-tid (i.e. affect the
 activator) set the angle   instead of the pitch. - Fixed: The check for
 special death states in AActor::TakeSpecialDamage didn't   work.

SVN r371 (trunk)
---
 docs/rh-log.txt |  4 ++++
 src/actor.h     |  2 +-
 src/info.cpp    | 24 +++++++++++++++++++-----
 src/p_acs.cpp   |  2 +-
 src/p_mobj.cpp  |  2 +-
 5 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/docs/rh-log.txt b/docs/rh-log.txt
index f57cf50bc..6e7f7f169 100644
--- a/docs/rh-log.txt
+++ b/docs/rh-log.txt
@@ -1,4 +1,8 @@
 October 31, 2006 (Changes by Graf Zahl)
+- Fixed: SetActorPitch with a 0-tid (i.e. affect the activator) set the angle
+  instead of the pitch.
+- Fixed: The check for special death states in AActor::TakeSpecialDamage didn't
+  work.
 - Fixed: The global WeaponSection string was never freed. It has been replaced
   with an FString now.
 - Fixed: The music strings in the default level info were never freed and
diff --git a/src/actor.h b/src/actor.h
index 5ca2a1e12..c8aa4128b 100644
--- a/src/actor.h
+++ b/src/actor.h
@@ -743,7 +743,7 @@ public:
 	FState *FindState (FName label) const;
 	FState *FindState (int numnames, int first, ...) const;
 	FState *FindState (int numnames, va_list arglist) const;
-	bool HasStates (FName label) const;
+	bool HasSpecialDeathStates () const;
 
 	static FState States[];
 
diff --git a/src/info.cpp b/src/info.cpp
index 53d29a9d5..f616127ec 100644
--- a/src/info.cpp
+++ b/src/info.cpp
@@ -453,23 +453,37 @@ FState *AActor::FindState (FName label) const
 //
 // HasStates
 //
-// Checks whether the actor has substates for the given name.
+// Checks whether the actor has special death states.
 //
 //===========================================================================
 
-bool AActor::HasStates (FName label) const
+bool AActor::HasSpecialDeathStates () const
 {
 	const FActorInfo *info = GetClass()->ActorInfo;
 	FStateLabel *slabel;
+	TArray<FName> checkedTypes;
 
 	while (info != NULL)
 	{
 		if (info->StateList != NULL)
 		{
-			slabel = info->StateList->FindLabel (label);
-			if (slabel != NULL)
+			slabel = info->StateList->FindLabel (NAME_Death);
+			if (slabel != NULL && slabel->Children != NULL)
 			{
-				return true;
+				for(int i=0;i<slabel->Children->NumLabels;i++)
+				{
+					unsigned int j;
+					for(j=0;j<checkedTypes.Size();j++)
+					{
+						if (slabel->Children->Labels[i].Label == checkedTypes[j]) break;
+					}
+					// Only check if this damage type hasn't been checked by another class with higher priority.
+					if (j==checkedTypes.Size())
+					{
+						if (slabel->Children->Labels[i].State != NULL) return true;
+						else if (slabel->Children->Labels[i].valid) checkedTypes.Push(slabel->Children->Labels[i].Label);
+					}
+				}
 			}
 		}
 		info = info->Class->ParentClass->ActorInfo;
diff --git a/src/p_acs.cpp b/src/p_acs.cpp
index 12d1c6e0b..fe252a661 100644
--- a/src/p_acs.cpp
+++ b/src/p_acs.cpp
@@ -4923,7 +4923,7 @@ int DLevelScript::RunScript ()
 		case PCD_SETACTORPITCH:
 			if (STACK(2) == 0)
 			{
-				activator->angle = STACK(1) << 16;
+				activator->pitch = STACK(1) << 16;
 			}
 			else
 			{
diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp
index 36e51108b..1a2738b03 100644
--- a/src/p_mobj.cpp
+++ b/src/p_mobj.cpp
@@ -4639,7 +4639,7 @@ int AActor::TakeSpecialDamage (AActor *inflictor, AActor *source, int damage, FN
 	// it needs to work.
 
 	// Always kill if there is a regular death state or no death states at all.
-	if (FindState (NAME_Death) != NULL || !HasStates(NAME_Death))
+	if (FindState (NAME_Death) != NULL || !HasSpecialDeathStates())
 	{
 		return damage;
 	}