From 9d21d790a4d741af02c793a0140b22754154246a Mon Sep 17 00:00:00 2001
From: lachwright <lachlanwright17@gmail.com>
Date: Fri, 8 May 2020 02:58:56 +0800
Subject: [PATCH] Prevent laser sprites clipping into walls/off ledges

---
 src/info.c    |  2 +-
 src/p_enemy.c | 18 +++++++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/info.c b/src/info.c
index c64f669ee..d443e035d 100644
--- a/src/info.c
+++ b/src/info.c
@@ -5696,7 +5696,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] =
 		DMG_FIRE,       // mass
 		1,              // damage
 		sfx_None,       // activesound
-		MF_NOBLOCKMAP|MF_MISSILE|MF_NOGRAVITY|MF_FIRE, // flags
+		MF_NOGRAVITY|MF_FIRE|MF_PAIN, // flags
 		S_NULL          // raisestate
 	},
 
diff --git a/src/p_enemy.c b/src/p_enemy.c
index a6dff3b59..6b092fb61 100644
--- a/src/p_enemy.c
+++ b/src/p_enemy.c
@@ -3117,7 +3117,7 @@ void A_Boss1Laser(mobj_t *actor)
 	floorz = P_FloorzAtPos(x, y, z, mobjinfo[MT_EGGMOBILE_FIRE].height);
 	if (z - floorz < mobjinfo[MT_EGGMOBILE_FIRE].height>>1 && dur & 1)
 	{
-		point = P_SpawnMobj(x, y, floorz+1, MT_EGGMOBILE_FIRE);
+		point = P_SpawnMobj(x, y, floorz, MT_EGGMOBILE_FIRE);
 		point->angle = actor->angle;
 		point->destscale = actor->scale;
 		P_SetScale(point, point->destscale);
@@ -3136,8 +3136,20 @@ void A_Boss1Laser(mobj_t *actor)
 					S_StartSound(steam, point->info->painsound);
 			}
 		}
-		else if (point->info->seesound)
-			S_StartSound(point, point->info->seesound);
+		else
+		{
+			fixed_t distx = P_ReturnThrustX(point, point->angle, point->radius);
+			fixed_t disty = P_ReturnThrustY(point, point->angle, point->radius);
+			if (P_TryMove(point, point->x + distx, point->y + disty, false) // prevents the sprite from clipping into the wall or dangling off ledges
+				&& P_TryMove(point, point->x - 2*distx, point->y - 2*disty, false)
+				&& P_TryMove(point, point->x + distx, point->y + disty, false))
+			{
+				if (point->info->seesound)
+					S_StartSound(point, point->info->seesound);
+			}
+			else
+				P_RemoveMobj(point);
+		}
 	}
 
 	if (dur > 1)