# HG changeset patch
# User Ru5tK1ng
# Date 1705700846 21600
#      Fri Jan 19 15:47:26 2024 -0600
# Branch hexenfixes
# Node ID 7a6dc118680a12665403a98c007a4dd173dd415e
# Parent  f46ab13b972a3a2ffbd7baf2e88c43a1828ce7af
Fixed: P_CheckMissileSpawn instructed clients to blow up a missile they weren't aware of due to out of sequence commands (addresses 4186).

diff -r f46ab13b972a -r 7a6dc118680a docs/zandronum-history.txt
--- a/docs/zandronum-history.txt	Fri Sep 29 08:23:34 2023 -0400
+++ b/docs/zandronum-history.txt	Fri Jan 19 15:47:26 2024 -0600
@@ -114,6 +114,7 @@
 -	- Fixed: the coop info wasn't getting drawn in clientside demos. [Kaminsky]
 -	- Fixed: Floatbob items having incorrect z-height after a map reset and glitchy GL floor clipping (addresses 2361). [Ru5tK1ng]
 -	- Fixed: Monsters spawned by BossBrain cubes would move before being spawned on the clients therefore triggering warning messages (addresses 2655). [Ru5tK1ng]
+-   - Fixed: P_CheckMissileSpawn instructed clients to blow up a missile they weren't aware of due to out of sequence commands (addresses 4186). [Ru5tK1ng]
 !	- The result value of GAMEEVENT_MEDALS event scripts can now be used to determine whether or not the player receives the medal. [Kaminsky]
 !	- GAMEMODE flags are now validated after all GAMEMODE lumps have been parsed instead of after each one. The internal game mode name (e.g. "TeamLMS") is now printed with the error message instead of the actual name. [Kaminsky]
 !	- Added an extra check to ensure that game modes have a (short) name. [Kaminsky]
diff -r f46ab13b972a -r 7a6dc118680a src/p_things.cpp
--- a/src/p_things.cpp	Fri Sep 29 08:23:34 2023 -0400
+++ b/src/p_things.cpp	Fri Jan 19 15:47:26 2024 -0600
@@ -405,6 +405,12 @@
 						mobj->flags |= MF_DROPPED;
 					}
 					bMissileExplode = false;
+
+					// [RK] We'll spawn the missile on the clients before we blow
+					// it up in P_CheckMissileSpawn when P_TryMove returns false
+					if ( NETWORK_GetState() == NETSTATE_SERVER )
+						SERVERCOMMANDS_SpawnMissile( mobj );
+
 					if (mobj->flags & MF_MISSILE)
 					{
 						if (P_CheckMissileSpawn (mobj, spot->radius))
@@ -427,12 +433,10 @@
 						rtn = 1;
 					}
 
-					// [BC] Spawn this actor to clients. It must be spawned as a missile because
-					// it can potentially have velocity, etc. 
-					if ( NETWORK_GetState( ) == NETSTATE_SERVER )
+					// [RK] Update the flags if necessary on the client and don't
+					// send if the missile already blew up in P_CheckMissileSpawn
+					if ( NETWORK_GetState( ) == NETSTATE_SERVER && !bMissileExplode )
 					{
-						SERVERCOMMANDS_SpawnMissile( mobj );
-
 						// Determine which flags we need to update.
 						if ( mobj->flags != mobj->GetDefault( )->flags )
 							SERVERCOMMANDS_SetThingFlags( mobj, FLAGSET_FLAGS );
@@ -449,12 +453,6 @@
 						// [BB] If necessary, also adjust gravity.
 						if ( mobj->gravity != mobj->GetDefault( )->gravity )
 							SERVERCOMMANDS_SetThingGravity( mobj );
-
-						// For missiles that exploded when P_CheckMissileSpawn() was
-						// called, we need to tell clients to explode the missile since
-						// it wasn't actually spawned at that point.
-						if ( bMissileExplode )
-							SERVERCOMMANDS_MissileExplode( mobj, NULL );
 					}
 				}
 			} while (dest != 0 && (targ = tit.Next()));
