From 570a6ab395ee0cc2de69e3d1a6e1abb5da6de3a8 Mon Sep 17 00:00:00 2001
From: MascaraSnake <jonassauer27@gmail.com>
Date: Thu, 30 Dec 2021 20:37:57 +0100
Subject: [PATCH] Turn "intangible to camera" sector special into a sector flag

---
 extras/conf/udb/Includes/SRB222_misc.cfg |  1 +
 src/deh_lua.c                            |  2 +-
 src/deh_tables.c                         |  3 ++-
 src/deh_tables.h                         |  2 +-
 src/p_map.c                              |  6 +++---
 src/p_maputl.c                           |  4 ++--
 src/p_setup.c                            | 14 ++++++++++++++
 src/p_spec.c                             |  2 +-
 src/p_user.c                             |  6 +++---
 src/r_defs.h                             |  1 +
 10 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/extras/conf/udb/Includes/SRB222_misc.cfg b/extras/conf/udb/Includes/SRB222_misc.cfg
index 36518be9f5..709514df87 100644
--- a/extras/conf/udb/Includes/SRB222_misc.cfg
+++ b/extras/conf/udb/Includes/SRB222_misc.cfg
@@ -81,6 +81,7 @@ sectorflags
 	invertprecip = "Invert Precipitation";
 	gravityflip = "Flip Objects in Reverse Gravity";
 	heatwave = "Heat Wave";
+	noclipcamera = "Intangible to the Camera";
 }
 
 thingflags
diff --git a/src/deh_lua.c b/src/deh_lua.c
index e360febaf2..10f5eb46dc 100644
--- a/src/deh_lua.c
+++ b/src/deh_lua.c
@@ -340,7 +340,7 @@ static inline int lib_getenum(lua_State *L)
 	}
 	else if (fastncmp("MSF_", word, 3)) {
 		p = word + 4;
-		for (i = 0; i < 6; i++)
+		for (i = 0; i < 7; i++)
 			if (MSF_LIST[i] && fastcmp(p, MSF_LIST[i])) {
 				lua_pushinteger(L, ((lua_Integer)1 << i));
 				return 1;
diff --git a/src/deh_tables.c b/src/deh_tables.c
index 095aae0f26..276bfce18a 100644
--- a/src/deh_tables.c
+++ b/src/deh_tables.c
@@ -4472,13 +4472,14 @@ const char *const ML_LIST[16] = {
 };
 
 // Sector flags
-const char *const MSF_LIST[6] = {
+const char *const MSF_LIST[7] = {
 	"FLIPSPECIAL_FLOOR",
 	"FLIPSPECIAL_CEILING",
 	"TRIGGERSPECIAL_TOUCH",
 	"TRIGGERSPECIAL_HEADBUMP",
 	"GRAVITYFLIP",
 	"HEATWAVE",
+	"NOCLIPCAMERA",
 };
 
 const char *COLOR_ENUMS[] = {
diff --git a/src/deh_tables.h b/src/deh_tables.h
index 2e514a5b15..8cabb2063d 100644
--- a/src/deh_tables.h
+++ b/src/deh_tables.h
@@ -65,7 +65,7 @@ extern const char *const MAPTHINGFLAG_LIST[4];
 extern const char *const PLAYERFLAG_LIST[];
 extern const char *const GAMETYPERULE_LIST[];
 extern const char *const ML_LIST[16]; // Linedef flags
-extern const char* const MSF_LIST[6]; // Sector flags
+extern const char* const MSF_LIST[7]; // Sector flags
 extern const char *COLOR_ENUMS[];
 extern const char *const POWERS_LIST[];
 extern const char *const HUDITEMS_LIST[];
diff --git a/src/p_map.c b/src/p_map.c
index 6b69df9cbb..8b236c7c34 100644
--- a/src/p_map.c
+++ b/src/p_map.c
@@ -2319,7 +2319,7 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam)
 
 	mapcampointer = thiscam;
 
-	if (GETSECSPECIAL(newsubsec->sector->special, 4) == 12)
+	if (newsubsec->sector->flags & MSF_NOCLIPCAMERA)
 	{ // Camera noclip on entire sector.
 		tmfloorz = tmdropoffz = thiscam->z;
 		tmceilingz = tmdrpoffceilz = thiscam->z + thiscam->height;
@@ -2359,7 +2359,7 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam)
 		for (rover = newsubsec->sector->ffloors; rover; rover = rover->next)
 		{
 			fixed_t topheight, bottomheight;
-			if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)
+			if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || (rover->master->frontsector->flags & MSF_NOCLIPCAMERA))
 				continue;
 
 			topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, x, y, NULL);
@@ -2431,7 +2431,7 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam)
 						// We're inside it! Yess...
 						polysec = po->lines[0]->backsector;
 
-						if (GETSECSPECIAL(polysec->special, 4) == 12)
+						if (polysec->flags & MSF_NOCLIPCAMERA)
 						{ // Camera noclip polyobj.
 							plink = (polymaplink_t *)(plink->link.next);
 							continue;
diff --git a/src/p_maputl.c b/src/p_maputl.c
index efcebe7363..ee22578efb 100644
--- a/src/p_maputl.c
+++ b/src/p_maputl.c
@@ -374,7 +374,7 @@ void P_CameraLineOpening(line_t *linedef)
 				for (rover = front->ffloors; rover; rover = rover->next)
 				{
 					fixed_t topheight, bottomheight;
-					if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)
+					if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || (rover->master->frontsector->flags & MSF_NOCLIPCAMERA))
 						continue;
 
 					topheight = P_CameraGetFOFTopZ(mapcampointer, front, rover, tmx, tmy, linedef);
@@ -398,7 +398,7 @@ void P_CameraLineOpening(line_t *linedef)
 				for (rover = back->ffloors; rover; rover = rover->next)
 				{
 					fixed_t topheight, bottomheight;
-					if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)
+					if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_RENDERALL) || !(rover->flags & FF_EXISTS) || (rover->master->frontsector->flags & MSF_NOCLIPCAMERA))
 						continue;
 
 					topheight = P_CameraGetFOFTopZ(mapcampointer, back, rover, tmx, tmy, linedef);
diff --git a/src/p_setup.c b/src/p_setup.c
index 70c6276d0a..0f398c5bcc 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -1677,6 +1677,8 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val)
 		sectors[i].flags |= MSF_GRAVITYFLIP;
 	else if (fastcmp(param, "heatwave") && fastcmp("true", val))
 		sectors[i].flags |= MSF_HEATWAVE;
+	else if (fastcmp(param, "noclipcamera") && fastcmp("true", val))
+		sectors[i].flags |= MSF_NOCLIPCAMERA;
 	else if (fastcmp(param, "friction"))
 		sectors[i].friction = atol(val);
 	else if (fastcmp(param, "gravity"))
@@ -5017,6 +5019,18 @@ static void P_ConvertBinaryMap(void)
 		}
 	}
 
+	for (i = 0; i < numsectors; i++)
+	{
+		switch(GETSECSPECIAL(sectors[i].special, 4))
+		{
+			case 12: //Intangible to the camera
+				sectors[i].flags |= MSF_NOCLIPCAMERA;
+				break;
+			default:
+				break;
+		}
+	}
+
 	for (i = 0; i < NUMMOBJTYPES; i++)
 	{
 		if (mobjinfo[i].doomednum < 0 || mobjinfo[i].doomednum >= 4096)
diff --git a/src/p_spec.c b/src/p_spec.c
index 2e6094ef2c..9fe9ad8efc 100644
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -5017,7 +5017,7 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers
 			if (isTouching)
 				P_ProcessRopeHang(player, sector, sectag);
 			break;
-		case 12: // Camera noclip
+		case 12: // Unused
 		case 13: // Unused
 		case 14: // Unused
 		case 15: // Unused
diff --git a/src/p_user.c b/src/p_user.c
index 8adb6ef9b6..d94b7556fe 100644
--- a/src/p_user.c
+++ b/src/p_user.c
@@ -10057,7 +10057,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
 			for (rover = newsubsec->sector->ffloors; rover; rover = rover->next)
 			{
 				fixed_t topheight, bottomheight;
-				if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12)
+				if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || (rover->master->frontsector->flags & MSF_NOCLIPCAMERA))
 					continue;
 
 				topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL);
@@ -10121,7 +10121,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
 						// We're inside it! Yess...
 						polysec = po->lines[0]->backsector;
 
-						if (GETSECSPECIAL(polysec->special, 4) == 12)
+						if (polysec->flags & MSF_NOCLIPCAMERA)
 						{ // Camera noclip polyobj.
 							plink = (polymaplink_t *)(plink->link.next);
 							continue;
@@ -10183,7 +10183,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
 			for (rover = newsubsec->sector->ffloors; rover; rover = rover->next)
 			{
 				fixed_t topheight, bottomheight;
-				if ((rover->flags & FF_BLOCKOTHERS) && (rover->flags & FF_RENDERALL) && (rover->flags & FF_EXISTS) && GETSECSPECIAL(rover->master->frontsector->special, 4) != 12)
+				if ((rover->flags & FF_BLOCKOTHERS) && (rover->flags & FF_RENDERALL) && (rover->flags & FF_EXISTS) && !(rover->master->frontsector->flags & MSF_NOCLIPCAMERA))
 				{
 					topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, midx, midy, NULL);
 					bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, midx, midy, NULL);
diff --git a/src/r_defs.h b/src/r_defs.h
index c565473dd0..833958ab11 100644
--- a/src/r_defs.h
+++ b/src/r_defs.h
@@ -286,6 +286,7 @@ typedef enum
 	MSF_INVERTPRECIP            =  1<<4,
 	MSF_GRAVITYFLIP             =  1<<5,
 	MSF_HEATWAVE                =  1<<6,
+	MSF_NOCLIPCAMERA            =  1<<7,
 } sectorflags_t;
 
 
-- 
GitLab