From 32a1131c68060a6abb33c04132984f26831211a6 Mon Sep 17 00:00:00 2001
From: MascaraSnake <jonassauer27@gmail.com>
Date: Tue, 14 Apr 2020 09:43:49 +0200
Subject: [PATCH] Implement FOF type 251

---
 extras/conf/udb/Includes/SRB222_linedefs.cfg | 24 ++++++++++++++++++++
 src/p_floor.c                                | 17 ++++----------
 src/p_setup.c                                | 20 ++++++++++++++++
 src/p_spec.c                                 |  2 +-
 4 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/extras/conf/udb/Includes/SRB222_linedefs.cfg b/extras/conf/udb/Includes/SRB222_linedefs.cfg
index 528690dc4f..c63947f658 100644
--- a/extras/conf/udb/Includes/SRB222_linedefs.cfg
+++ b/extras/conf/udb/Includes/SRB222_linedefs.cfg
@@ -1644,6 +1644,30 @@ udmf
 		}
 	}
 
+	251
+	{
+		title = "Thwomp Block";
+		prefix = "(251);
+		arg0
+		{
+			title = "Target sector tag";
+			type = 13;
+		}
+		arg1
+		{
+			title = "Falling speed";
+		}
+		arg2
+		{
+			title = "Rising speed";
+		}
+		stringarg0
+		{
+			title = "Crushing sound";
+			type = 2;
+		}
+	}
+
 	linedefexecmisc
 	{
 		title = "Linedef Executor (misc.)";
diff --git a/src/p_floor.c b/src/p_floor.c
index b8b40df3c1..d9b404155a 100644
--- a/src/p_floor.c
+++ b/src/p_floor.c
@@ -11,6 +11,7 @@
 /// \file  p_floor.c
 /// \brief Floor animation, elevators
 
+#include "dehacked.h"
 #include "doomdef.h"
 #include "doomstat.h"
 #include "m_random.h"
@@ -1885,10 +1886,7 @@ void T_ThwompSector(levelspecthink_t *thwomp)
 		sides[thwomp->sourceline->sidenum[0]].midtexture = sides[thwomp->sourceline->sidenum[0]].bottomtexture;
 		/// \note this should only have to be done once, but is already done repeatedly, above
 
-		if (thwomp->sourceline->flags & ML_EFFECT5)
-			thwomp->speed = thwomp->sourceline->dx/8;
-		else
-			thwomp->speed = 2*FRACUNIT;
+		thwomp->speed = thwomp->sourceline->args[2] << (FRACBITS - 3);
 
 		res = T_MovePlane
 		(
@@ -1924,10 +1922,7 @@ void T_ThwompSector(levelspecthink_t *thwomp)
 		// Set the texture from the upper one (angry)
 		sides[thwomp->sourceline->sidenum[0]].midtexture = sides[thwomp->sourceline->sidenum[0]].toptexture;
 
-		if (thwomp->sourceline->flags & ML_EFFECT5)
-			thwomp->speed = thwomp->sourceline->dy/8;
-		else
-			thwomp->speed = 10*FRACUNIT;
+		thwomp->speed = thwomp->sourceline->args[1] << (FRACBITS - 3);
 
 		res = T_MovePlane
 		(
@@ -1961,10 +1956,8 @@ void T_ThwompSector(levelspecthink_t *thwomp)
 
 			if (!rover || (rover->flags & FF_EXISTS))
 			{
-				if (thwomp->sourceline->flags & ML_EFFECT4)
-					S_StartSound(mp, sides[thwomp->sourceline->sidenum[0]].textureoffset>>FRACBITS);
-				else
-					S_StartSound(mp, sfx_thwomp);
+				sfxenum_t sound = (thwomp->sourceline->stringargs[0]) ? get_number(thwomp->sourceline->stringargs[0]) : sfx_thwomp;
+				S_StartSound(mp, sound);
 			}
 
 			thwomp->direction = 1; // start heading back up
diff --git a/src/p_setup.c b/src/p_setup.c
index 92eaff4b58..82671abb01 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -2938,6 +2938,26 @@ static void P_ConvertBinaryMap(void)
 			if (lines[i].flags & ML_EFFECT1) //Invisible
 				lines[i].args[1] |= 2;
 			break;
+		case 251: //FOF: Thwomp block
+			lines[i].args[0] = lines[i].tag;
+			if (lines[i].flags & ML_EFFECT5) //Custom speeds
+			{
+				lines[i].args[1] = lines[i].dy >> FRACBITS;
+				lines[i].args[2] = lines[i].dx >> FRACBITS;
+			}
+			else
+			{
+				lines[i].args[1] = 80;
+				lines[i].args[2] = 16;
+			}
+			if (lines[i].flags & ML_EFFECT4)
+			{
+				char buffer[6];
+				sprintf(buffer, "%d", sides[lines[i].sidenum[0]].textureoffset >> FRACBITS);
+				lines[i].stringargs[0] = Z_Malloc(strlen(buffer) + 1, PU_LEVEL, NULL);
+				M_Memcpy(lines[i].stringargs[0], buffer, strlen(buffer) + 1);
+			}
+			break;
 		case 443: //Call Lua function
 			if (lines[i].text)
 			{
diff --git a/src/p_spec.c b/src/p_spec.c
index 94e6aa936b..774c7162ae 100644
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -6997,7 +6997,7 @@ void P_SpawnSpecials(boolean fromnetsave)
 
 			case 251: // A THWOMP!
 				sec = sides[*lines[i].sidenum].sector - sectors;
-				for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;)
+				for (s = -1; (s = P_FindSectorFromTag(lines[i].args[0], s)) >= 0 ;)
 				{
 					P_AddThwompThinker(&sectors[sec], &sectors[s], &lines[i]);
 					P_AddFakeFloor(&sectors[s], &sectors[sec], lines + i,
-- 
GitLab