From df0d3543a85076168fa73b26486ac9a105e69a7d Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Thu, 21 Aug 2014 13:01:12 +0200
Subject: [PATCH] - fixed: *ALL* original ceiling crushers, not just type 49,
 require a distance of 8 to the floor for the destination height. For the
 silent types this required a new action special,
 Ceiling_CrushAndRaiseSilentDist. This change only affects the XLAT mapping,
 the Hexen format types behave as before. - removed the redundant internal
 ceilCrushAndRaiseDist ceiling movement type. It was precisely the same as
 ceilCrushAndRaise in all details.

---
 src/actionspecials.h          |  1 +
 src/cmdlib.h                  |  5 +++--
 src/p_ceiling.cpp             |  8 ++------
 src/p_lnspec.cpp              | 10 ++++++++--
 src/p_spec.h                  |  1 -
 wadsrc/static/xlat/base.txt   | 22 +++++++++++-----------
 wadsrc/static/xlat/strife.txt | 10 +++++-----
 7 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/src/actionspecials.h b/src/actionspecials.h
index 1377def82..752ef77eb 100644
--- a/src/actionspecials.h
+++ b/src/actionspecials.h
@@ -102,6 +102,7 @@ DEFINE_SPECIAL(Scroll_Texture_Left, 100, -1, -1, 2)
 DEFINE_SPECIAL(Scroll_Texture_Right, 101, -1, -1, 2)
 DEFINE_SPECIAL(Scroll_Texture_Up, 102, -1, -1, 2)
 DEFINE_SPECIAL(Scroll_Texture_Down, 103, -1, -1, 2)
+DEFINE_SPECIAL(Ceiling_CrushAndRaiseSilentDist, 104, 3, 5, 5)
 
 DEFINE_SPECIAL(Light_ForceLightning, 109, 1, 1, 1)
 DEFINE_SPECIAL(Light_RaiseByValue, 110, 2, 2, 2)
diff --git a/src/cmdlib.h b/src/cmdlib.h
index f6f0e6ad8..6df893580 100644
--- a/src/cmdlib.h
+++ b/src/cmdlib.h
@@ -6,6 +6,7 @@
 
 #include "doomtype.h"
 #include "doomdef.h"
+#include "m_fixed.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -75,12 +76,12 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath);
 
 inline int AdjustTics(int tics)
 {
-	return (tics * 98) / 100;
+	return Scale(tics, 98, 100);
 }
 
 inline int Tics2Seconds(int tics)
 {
-	return (tics * 98) / (100 * TICRATE);
+	return Scale(tics, 98, (100 * TICRATE));
 }
 
 
diff --git a/src/p_ceiling.cpp b/src/p_ceiling.cpp
index 426bdf507..d0c54761a 100644
--- a/src/p_ceiling.cpp
+++ b/src/p_ceiling.cpp
@@ -133,7 +133,6 @@ void DCeiling::Tick ()
 			switch (m_Type)
 			{
 			case ceilCrushAndRaise:
-			case ceilCrushAndRaiseDist:
 				m_Direction = -1;
 				m_Speed = m_Speed1;
 				if (!SN_IsMakingLoopingSound (m_Sector))
@@ -165,7 +164,6 @@ void DCeiling::Tick ()
 			switch (m_Type)
 			{
 			case ceilCrushAndRaise:
-			case ceilCrushAndRaiseDist:
 			case ceilCrushRaiseAndStay:
 				m_Speed = m_Speed2;
 				m_Direction = 1;
@@ -195,7 +193,6 @@ void DCeiling::Tick ()
 				switch (m_Type)
 				{
 				case ceilCrushAndRaise:
-				case ceilCrushAndRaiseDist:
 				case ceilLowerAndCrush:
 				case ceilLowerAndCrushDist:
 					if (m_Speed1 == FRACUNIT && m_Speed2 == FRACUNIT)
@@ -257,7 +254,6 @@ DCeiling *DCeiling::Create(sector_t *sec, DCeiling::ECeiling type, line_t *line,
 	switch (type)
 	{
 	case ceilCrushAndRaise:
-	case ceilCrushAndRaiseDist:
 	case ceilCrushRaiseAndStay:
 		ceiling->m_TopHeight = sec->ceilingplane.d;
 	case ceilLowerAndCrush:
@@ -267,7 +263,7 @@ DCeiling *DCeiling::Create(sector_t *sec, DCeiling::ECeiling type, line_t *line,
 		{
 			targheight += 8*FRACUNIT;
 		}
-		else if (type == ceilLowerAndCrushDist || type == ceilCrushAndRaiseDist)
+		else if (type == ceilCrushAndRaise)
 		{
 			targheight += height;
 		}
@@ -509,7 +505,7 @@ bool EV_DoCeiling (DCeiling::ECeiling type, line_t *line,
 	
 	//	Reactivate in-stasis ceilings...for certain types.
 	// This restarts a crusher after it has been stopped
-	if (type == DCeiling::ceilCrushAndRaise || type == DCeiling::ceilCrushAndRaiseDist)
+	if (type == DCeiling::ceilCrushAndRaise)
 	{
 		P_ActivateInStasisCeiling (tag);
 	}
diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp
index 7cb5ca7e6..14bcd430c 100644
--- a/src/p_lnspec.cpp
+++ b/src/p_lnspec.cpp
@@ -641,7 +641,7 @@ FUNC(LS_Ceiling_CrushAndRaiseA)
 FUNC(LS_Ceiling_CrushAndRaiseDist)
 // Ceiling_CrushAndRaiseDist (tag, dist, speed, damage, crushtype)
 {
-	return EV_DoCeiling (DCeiling::ceilCrushAndRaiseDist, ln, arg0, SPEED(arg2), SPEED(arg2), arg1*FRACUNIT, arg3, 0, 0, CRUSHTYPE(arg4));
+	return EV_DoCeiling (DCeiling::ceilCrushAndRaise, ln, arg0, SPEED(arg2), SPEED(arg2), arg1*FRACUNIT, arg3, 0, 0, CRUSHTYPE(arg4));
 }
 
 FUNC(LS_Ceiling_CrushAndRaiseSilentA)
@@ -650,6 +650,12 @@ FUNC(LS_Ceiling_CrushAndRaiseSilentA)
 	return EV_DoCeiling (DCeiling::ceilCrushAndRaise, ln, arg0, SPEED(arg1), SPEED(arg2), 0, arg3, 1, 0, CRUSHTYPE(arg4));
 }
 
+FUNC(LS_Ceiling_CrushAndRaiseSilentDist)
+// Ceiling_CrushAndRaiseSilentDist (tag, dist, upspeed, damage, crushtype)
+{
+	return EV_DoCeiling (DCeiling::ceilCrushAndRaise, ln, arg0, SPEED(arg2), SPEED(arg2), arg1*FRACUNIT, arg3, 1, 0, CRUSHTYPE(arg4));
+}
+
 FUNC(LS_Ceiling_RaiseToNearest)
 // Ceiling_RaiseToNearest (tag, speed)
 {
@@ -3261,7 +3267,7 @@ lnSpecFunc LineSpecials[256] =
 	/* 101 */ LS_NOP,		// Scroll_Texture_Right
 	/* 102 */ LS_NOP,		// Scroll_Texture_Up
 	/* 103 */ LS_NOP,		// Scroll_Texture_Down
-	/* 104 */ LS_NOP,
+	/* 104 */ LS_Ceiling_CrushAndRaiseSilentDist,
 	/* 105 */ LS_NOP,
 	/* 106 */ LS_NOP,
 	/* 107 */ LS_NOP,
diff --git a/src/p_spec.h b/src/p_spec.h
index dc0eb3646..c9bb6eded 100644
--- a/src/p_spec.h
+++ b/src/p_spec.h
@@ -628,7 +628,6 @@ public:
 		ceilLowerInstant,
 		ceilRaiseInstant,
 		ceilCrushAndRaise,
-		ceilCrushAndRaiseDist,
 		ceilLowerAndCrush,
 		ceilLowerAndCrushDist,
 		ceilCrushRaiseAndStay,
diff --git a/wadsrc/static/xlat/base.txt b/wadsrc/static/xlat/base.txt
index 11b9fd315..856e7a505 100644
--- a/wadsrc/static/xlat/base.txt
+++ b/wadsrc/static/xlat/base.txt
@@ -5,7 +5,7 @@ include "xlat/defines.i"
   3 = WALK,		Door_Close (tag, D_SLOW)
   4 = WALK|MONST,	Door_Raise (tag, D_SLOW, VDOORWAIT)
   5 = WALK,		Floor_RaiseToLowestCeiling (tag, F_SLOW)
-  6 = WALK,		Ceiling_CrushAndRaiseA (tag, C_NORMAL, C_NORMAL, 10)
+  6 = WALK,		Ceiling_CrushAndRaiseDist (tag, 8, C_NORMAL, 10)
   7 = USE,		Stairs_BuildUpDoom (tag, ST_SLOW, 8)
   8 = WALK,		Stairs_BuildUpDoom (tag, ST_SLOW, 8)
   9 = USE,		Floor_Donut (tag, DORATE, DORATE)
@@ -24,7 +24,7 @@ include "xlat/defines.i"
  22 = WALK,		Plat_RaiseAndStayTx0 (tag, P_SLOW/2)
  23 = USE,		Floor_LowerToLowest (tag, F_SLOW)
  24 = SHOOT,		Floor_RaiseToLowestCeiling (tag, F_SLOW)
- 25 = WALK,		Ceiling_CrushAndRaiseA (tag, C_SLOW, C_SLOW, 10)
+ 25 = WALK,		Ceiling_CrushAndRaiseDist (tag, C_SLOW, C_SLOW, 10)
  26 = USE|REP,		Door_LockedRaise (0, D_SLOW, VDOORWAIT, BCard | CardIsSkull, tag)
  27 = USE|REP,		Door_LockedRaise (0, D_SLOW, VDOORWAIT, YCard | CardIsSkull, tag)
  28 = USE|REP,		Door_LockedRaise (0, D_SLOW, VDOORWAIT, RCard | CardIsSkull, tag)
@@ -72,11 +72,11 @@ include "xlat/defines.i"
  70 = USE|REP,		Floor_LowerToHighest (tag, F_FAST, 136)
  71 = USE,		Floor_LowerToHighest (tag, F_FAST, 136)
  72 = WALK|REP,		Ceiling_LowerAndCrush (tag, C_SLOW, 0, 2)
- 73 = WALK|REP,		Ceiling_CrushAndRaiseA (tag, C_SLOW, C_SLOW, 10)
+ 73 = WALK|REP,		Ceiling_CrushAndRaiseDist (tag, 8, C_SLOW, 10)
  74 = WALK|REP,		Ceiling_CrushStop (tag)
  75 = WALK|REP,		Door_Close (tag, D_SLOW)
  76 = WALK|REP,		Door_CloseWaitOpen (tag, D_SLOW, 240)
- 77 = WALK|REP,		Ceiling_CrushAndRaiseA (tag, C_NORMAL, C_NORMAL, 10)
+ 77 = WALK|REP,		Ceiling_CrushAndRaiseDist (tag, 8, C_NORMAL, 10)
  78 = USE|REP,		Floor_TransferNumeric (tag)			// <- BOOM special
  79 = WALK|REP,		Light_ChangeToValue (tag, 35)
  80 = WALK|REP,		Light_MaxNeighbor (tag)
@@ -140,7 +140,7 @@ include "xlat/defines.i"
 138 = USE|REP,		Light_ChangeToValue (tag, 255)
 139 = USE|REP,		Light_ChangeToValue (tag, 35)
 140 = USE,		Floor_RaiseByValueTimes8 (tag, F_SLOW, 64)
-141 = WALK,		Ceiling_CrushAndRaiseSilentA (tag, C_SLOW, C_SLOW, 10)
+141 = WALK,		Ceiling_CrushAndRaiseSilentDist (tag, 8, C_SLOW, 10)
 
 /****** The following are all new to BOOM ******/
 
@@ -152,7 +152,7 @@ include "xlat/defines.i"
 147 = WALK|REP,		Floor_RaiseByValueTimes8 (tag, F_SLOW, 64)
 148 = WALK|REP,		Plat_UpByValueStayTx (tag, P_SLOW/2, 3)
 149 = WALK|REP,		Plat_UpByValueStayTx (tag, P_SLOW/2, 4)
-150 = WALK|REP,		Ceiling_CrushAndRaiseSilentA (tag, C_SLOW, C_SLOW, 10)
+150 = WALK|REP,		Ceiling_CrushAndRaiseSilentDist (tag, 8, C_SLOW, 10)
 151 = WALK|REP,		FloorAndCeiling_LowerRaise (tag, F_SLOW, C_SLOW)
 152 = WALK|REP,		Ceiling_LowerToFloor (tag, C_SLOW)
 153 = WALK,		Floor_TransferTrigger (tag)
@@ -166,8 +166,8 @@ include "xlat/defines.i"
 161 = USE,		Floor_RaiseByValue (tag, F_SLOW, 24)
 162 = USE,		Plat_PerpetualRaiseLip (tag, P_SLOW, PLATWAIT, 0)
 163 = USE,		Plat_Stop (tag)
-164 = USE,		Ceiling_CrushAndRaiseA (tag, C_NORMAL, C_NORMAL, 10)
-165 = USE,		Ceiling_CrushAndRaiseSilentA (tag, C_SLOW, C_SLOW, 10)
+164 = USE,		Ceiling_CrushAndRaiseDist (tag, 8, C_NORMAL, 10)
+165 = USE,		Ceiling_CrushAndRaiseSilentDist (tag, 8, C_SLOW, 10)
 166 = USE,		FloorAndCeiling_LowerRaise (tag, F_SLOW, C_SLOW, 1998)
 167 = USE,		Ceiling_LowerAndCrush (tag, C_SLOW, 0, 2)
 168 = USE,		Ceiling_CrushStop (tag)
@@ -185,9 +185,9 @@ include "xlat/defines.i"
 180 = USE|REP,		Floor_RaiseByValue (tag, F_SLOW, 24)
 181 = USE|REP,		Plat_PerpetualRaiseLip (tag, P_SLOW, PLATWAIT, 0)
 182 = USE|REP,		Plat_Stop (tag)
-183 = USE|REP,		Ceiling_CrushAndRaiseA (tag, C_NORMAL, C_NORMAL, 10)
-184 = USE|REP,		Ceiling_CrushAndRaiseA (tag, C_SLOW, C_SLOW, 10)
-185 = USE|REP,		Ceiling_CrushAndRaiseSilentA (tag, C_SLOW, C_SLOW, 10)
+183 = USE|REP,		Ceiling_CrushAndRaiseDist (tag, 8, C_NORMAL, 10)
+184 = USE|REP,		Ceiling_CrushAndRaiseDist (tag, 8, C_SLOW, 10)
+185 = USE|REP,		Ceiling_CrushAndRaiseSilentDist (tag, 8, C_SLOW, 10)
 186 = USE|REP,		FloorAndCeiling_LowerRaise (tag, F_SLOW, C_SLOW, 1998)
 187 = USE|REP,		Ceiling_LowerAndCrush (tag, C_SLOW, 0, 2)
 188 = USE|REP,		Ceiling_CrushStop (tag)
diff --git a/wadsrc/static/xlat/strife.txt b/wadsrc/static/xlat/strife.txt
index 159933c80..755ace5ad 100644
--- a/wadsrc/static/xlat/strife.txt
+++ b/wadsrc/static/xlat/strife.txt
@@ -90,7 +90,7 @@ RetailOnly		= 121
   3 = WALK,		Door_Close (tag, D_SLOW)
   4 = WALK|MONST,	Door_Raise (tag, D_SLOW, VDOORWAIT)
   5 = WALK,		Floor_RaiseToLowestCeiling (tag, F_SLOW)
-  6 = WALK,		Ceiling_CrushAndRaiseA (tag, C_FAST, C_FAST, 10)
+  6 = WALK,		Ceiling_CrushAndRaiseDist (tag, 8, C_FAST, 10)
   8 = WALK,		Stairs_BuildUpDoom (tag, ST_SLOW, 8)
  10 = WALK|MONST,	Plat_DownWaitUpStayLip (tag, P_FAST, PLATWAIT, 0)
  12 = WALK,		Light_MaxNeighbor (tag)
@@ -99,7 +99,7 @@ RetailOnly		= 121
  17 = WALK,		Light_StrobeDoom (tag, 5, 35)
  19 = WALK,		Floor_LowerToHighest (tag, F_SLOW, 128)
  22 = WALK,		Plat_RaiseAndStayTx0 (tag, P_SLOW/2)
- 25 = WALK,		Ceiling_CrushAndRaiseA (tag, C_SLOW, C_SLOW, 0)
+ 25 = WALK,		Ceiling_CrushAndRaiseDist (tag, 8, C_SLOW, 0)
  30 = WALK,		Floor_RaiseByTexture (tag, F_SLOW)
  35 = WALK,		Light_ChangeToValue (tag, 35)
  36 = WALK,		Floor_LowerToHighest (tag, F_FAST, 128)
@@ -128,7 +128,7 @@ RetailOnly		= 121
 124 = WALK,		Teleport_EndGame ()
 125 = MONWALK,		Teleport (0, tag)
 130 = WALK,		Floor_RaiseToNearest (tag, F_FAST)
-141 = WALK,		Ceiling_CrushAndRaiseSilentA (tag, C_SLOW, C_SLOW, 0)
+141 = WALK,		Ceiling_CrushAndRaiseSilentDist (tag, 8, C_SLOW, 10)
 174 = WALK,		ACS_ExecuteAlways (0, 0, 174, tag)
 183 = WALK,		ACS_ExecuteAlways (0, 0, 183, tag)
 178 = WALK,		Generic_Stairs (tag, ST_FAST, 16, 0, 0)
@@ -146,11 +146,11 @@ RetailOnly		= 121
 216 = WALK|REP,		ACS_ExecuteAlways (0, 0, 216, tag)
  90 = WALK|REP,		Door_Raise (tag, D_SLOW, VDOORWAIT)
  72 = WALK|REP,		Ceiling_LowerAndCrushDist (tag, C_SLOW, 10)
- 73 = WALK|REP,		Ceiling_CrushAndRaiseA (tag, C_SLOW, C_SLOW, 0)
+ 73 = WALK|REP,		Ceiling_CrushAndRaiseDist (tag, 8, C_SLOW, 0)
  74 = WALK|REP,		Ceiling_CrushStop (tag)
  75 = WALK|REP,		Door_Close (tag, D_SLOW)
  76 = WALK|REP,		Door_CloseWaitOpen (tag, D_SLOW, 240)
- 77 = WALK|REP,		Ceiling_CrushAndRaiseA (tag, C_FAST, C_FAST, 10)
+ 77 = WALK|REP,		Ceiling_CrushAndRaiseDist (tag, 8, C_FAST, 10)
  79 = WALK|REP,		Light_ChangeToValue (tag, 35)
  80 = WALK|REP,		Light_MaxNeighbor (tag)
  81 = WALK|REP,		Light_ChangeToValue (tag, 255)