From 6dbdcf5f6098189651bf11f2e668d685dfacdb3c Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Wed, 14 May 2008 07:45:40 +0000
Subject: [PATCH] - Changed: For actors not being spawned on the floor
 P_FindFloorCeiling should   be used to prevent them from dropping through
 3DMIDTEX textures. - Fixed: AMageStaffFX2::IsOkayToAttack overwrote the
 projectile's angle variable.

SVN r970 (trunk)
---
 docs/rh-log.txt             |  6 ++++++
 src/g_hexen/a_magestaff.cpp |  2 +-
 src/p_local.h               |  2 +-
 src/p_map.cpp               | 19 +++++++++++--------
 src/p_mobj.cpp              |  3 +++
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/docs/rh-log.txt b/docs/rh-log.txt
index 012774741..53f36f070 100644
--- a/docs/rh-log.txt
+++ b/docs/rh-log.txt
@@ -1,3 +1,8 @@
+May 13, 2008 (Changes by Graf Zahl)
+- Changed: For actors not being spawned on the floor P_FindFloorCeiling should
+  be used to prevent them from dropping through 3DMIDTEX textures.
+- Fixed: AMageStaffFX2::IsOkayToAttack overwrote the projectile's angle variable.
+
 May 13, 2008
 - Changed the types of object hash indices in FArchive from size_t to DWORD.
   This seems to fix crashes on GCC 64-bit builds when saving games. Not sure
@@ -8,6 +13,7 @@ May 13, 2008
   FString::Format() so that I can fix all the problem printf strings that a
   64-bit GCC compile finds.
 
+>>>>>>> .r969
 May 12, 2008 (Changes by Graf Zahl)
 - Added Skulltag's PUFFGETSOWNER flag.
 - Fixed: Parsing sector special bit masks must be done backwards so that later
diff --git a/src/g_hexen/a_magestaff.cpp b/src/g_hexen/a_magestaff.cpp
index eb0dede3c..ac8a253b1 100644
--- a/src/g_hexen/a_magestaff.cpp
+++ b/src/g_hexen/a_magestaff.cpp
@@ -321,7 +321,7 @@ bool AMageStaffFX2::IsOkayToAttack (AActor *link)
 		else if (P_CheckSight (this, link))
 		{
 			AActor *master = target;
-			angle = R_PointToAngle2 (master->x, master->y,
+			angle_t angle = R_PointToAngle2 (master->x, master->y,
 							link->x, link->y) - master->angle;
 			angle >>= 24;
 			if (angle>226 || angle<30)
diff --git a/src/p_local.h b/src/p_local.h
index 6d668ce55..470a0895d 100644
--- a/src/p_local.h
+++ b/src/p_local.h
@@ -373,7 +373,7 @@ bool	P_CheckSight (const AActor* t1, const AActor* t2, int flags=0);
 void	P_ResetSightCounters (bool full);
 void	P_UseLines (player_t* player);
 bool	P_UsePuzzleItem (AActor *actor, int itemType);
-void	P_FindFloorCeiling (AActor *actor);
+void	P_FindFloorCeiling (AActor *actor, bool onlymidtex = false);
 
 bool	P_ChangeSector (sector_t* sector, int crunch, int amt, int floorOrCeil, bool isreset);
 
diff --git a/src/p_map.cpp b/src/p_map.cpp
index acb7534d4..88eb13a14 100644
--- a/src/p_map.cpp
+++ b/src/p_map.cpp
@@ -163,7 +163,7 @@ static bool PIT_FindFloorCeiling (line_t *ld, const FBoundingBox &box, FCheckPos
 //
 //==========================================================================
 
-void P_FindFloorCeiling (AActor *actor)
+void P_FindFloorCeiling (AActor *actor, bool onlymidtex)
 {
 	sector_t *sec;
 	FCheckPosition tmf;
@@ -194,13 +194,16 @@ void P_FindFloorCeiling (AActor *actor)
 
 	if (tmf.touchmidtex) tmf.dropoffz = tmf.floorz;
 
-	actor->floorz = tmf.floorz;
-	actor->dropoffz = tmf.dropoffz;
-	actor->ceilingz = tmf.ceilingz;
-	actor->floorpic = tmf.floorpic;
-	actor->floorsector = tmf.floorsector;
-	actor->ceilingpic = tmf.ceilingpic;
-	actor->ceilingsector = tmf.ceilingsector;
+	if (!onlymidtex || (tmf.touchmidtex && (tmf.floorz < actor->z)))
+	{
+		actor->floorz = tmf.floorz;
+		actor->dropoffz = tmf.dropoffz;
+		actor->ceilingz = tmf.ceilingz;
+		actor->floorpic = tmf.floorpic;
+		actor->floorsector = tmf.floorsector;
+		actor->ceilingpic = tmf.ceilingpic;
+		actor->ceilingsector = tmf.ceilingsector;
+	}
 }
 
 //
diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp
index 906c0d088..08f1a5f62 100644
--- a/src/p_mobj.cpp
+++ b/src/p_mobj.cpp
@@ -3238,6 +3238,9 @@ AActor *AActor::StaticSpawn (const PClass *type, fixed_t ix, fixed_t iy, fixed_t
 		actor->floorpic = actor->floorsector->floorpic;
 		actor->ceilingsector = actor->Sector;
 		actor->ceilingpic = actor->ceilingsector->ceilingpic;
+		// Check if there's something solid to stand on between the current position and the
+		// current sector's floor.
+		P_FindFloorCeiling(actor, true);
 	}
 	else if (!(actor->flags5 & MF5_NOINTERACTION))
 	{