From db0a924fc9c8f8fda35d65643792ad745129259a Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Tue, 16 Jun 2009 22:04:26 +0000
Subject: [PATCH] - Reintroduced damage thrust clamping but with a higher
 threshold. The clamping   is now also done in floating point before any fixed
 point overflows can occur.

SVN r1670 (trunk)
---
 docs/rh-log.txt       |  6 +++++-
 src/m_cheat.cpp       |  2 +-
 src/namedef.h         |  1 +
 src/p_interaction.cpp | 12 +++---------
 src/p_mobj.cpp        |  3 ++-
 src/w_wad.cpp         |  2 +-
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/docs/rh-log.txt b/docs/rh-log.txt
index 79e5aef52..8e2093780 100644
--- a/docs/rh-log.txt
+++ b/docs/rh-log.txt
@@ -1,4 +1,8 @@
-June 14, 2009  (Changes by Graf Zahl)
+June 16, 2009  (Changes by Graf Zahl)
+- Reintroduced damage thrust clamping but with a higher threshold. The clamping
+  is now also done in floating point before any fixed point overflows can occur.
+
+June 14, 2009  (Changes by Graf Zahl)
 - added a compatibility option to restore the original Heretic bug where
   a Minotaur couldn't spawn floor flames when standing in water having its
   feet clipped.
diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp
index 8df4cb1e3..7e8a50a85 100644
--- a/src/m_cheat.cpp
+++ b/src/m_cheat.cpp
@@ -442,7 +442,7 @@ void cht_DoCheat (player_t *player, int cheat)
 			// a very very cheap kill.
 			P_LineAttack (player->mo, player->mo->angle, PLAYERMISSILERANGE,
 				P_AimLineAttack (player->mo, player->mo->angle, PLAYERMISSILERANGE), 1000000,
-				NAME_None, NAME_BulletPuff);
+				NAME_MDK, NAME_BulletPuff);
 		}
 		break;
 
diff --git a/src/namedef.h b/src/namedef.h
index c2b5b1107..b16e2212f 100644
--- a/src/namedef.h
+++ b/src/namedef.h
@@ -235,6 +235,7 @@ xx(PoisonCloud)	// makes monsters howl.
 // Special death name for getting killed excessively. Could be used as
 // a damage type if you wanted to force an extreme death.
 xx(Extreme)
+xx(MDK)
 
 // Special names for thingdef_exp.cpp
 xx(Random)
diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp
index 188b824a6..baa9f0e94 100644
--- a/src/p_interaction.cpp
+++ b/src/p_interaction.cpp
@@ -1043,16 +1043,10 @@ void P_DamageMobj (AActor *target, AActor *inflictor, AActor *source, int damage
 
 			// Calculate this as float to avoid overflows so that the
 			// clamping that had to be done here can be removed.
-			thrust = FLOAT2FIXED((damage * 0.125 * kickback) / target->Mass);
+			double fltthrust = clamp((damage * 0.125 * kickback) / target->Mass, 0.,mod == NAME_MDK? 10. : 32.);
+
+			thrust = FLOAT2FIXED(fltthrust);
 
-			// [RH] If thrust overflows, use a more reasonable amount
-			/* old fixed point code that could overflow.
-			thrust = damage*(FRACUNIT>>3)*kickback / target->Mass;
-			if (thrust < 0 || thrust > 10*FRACUNIT)
-			{
-				thrust = 10*FRACUNIT;
-			}
-			*/
 			// make fall forwards sometimes
 			if ((damage < 40) && (damage > target->health)
 				 && (target->z - origin->z > 64*FRACUNIT)
diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp
index 41f6b5289..c1ab00994 100644
--- a/src/p_mobj.cpp
+++ b/src/p_mobj.cpp
@@ -4520,6 +4520,7 @@ bool P_HitWater (AActor * thing, sector_t * sec, fixed_t x, fixed_t y, fixed_t z
 	AActor *mo = NULL;
 	FSplashDef *splash;
 	int terrainnum;
+	sector_t *hsec = NULL;
 	
 	if (x == FIXED_MIN) x = thing->x;
 	if (y == FIXED_MIN) y = thing->y;
@@ -4545,7 +4546,7 @@ bool P_HitWater (AActor * thing, sector_t * sec, fixed_t x, fixed_t y, fixed_t z
 		if (planez < z) return false;
 	}
 #endif
-	sector_t *hsec = sec->GetHeightSec();
+	hsec = sec->GetHeightSec();
 	if (hsec == NULL || !(hsec->MoreFlags & SECF_CLIPFAKEPLANES))
 	{
 		terrainnum = TerrainTypes[sec->GetTexture(sector_t::floor)];
diff --git a/src/w_wad.cpp b/src/w_wad.cpp
index a91e74656..813d12789 100644
--- a/src/w_wad.cpp
+++ b/src/w_wad.cpp
@@ -217,7 +217,7 @@ int FWadCollection::AddExternalFile(const char *filename)
 	FWadCollection::LumpRecord *lumprec = &LumpInfo[LumpInfo.Reserve(1)];
 	lumprec->lump = lump;
 	lumprec->wadnum = -1;
-	return 0;	// later
+	return LumpInfo.Size()-1;	// later
 }
 
 //==========================================================================