# HG changeset patch
# User Ru5tK1ng
# Date 1704828616 21600
#      Tue Jan 09 13:30:16 2024 -0600
# Branch bossbrain
# Node ID 4fc55e66b7f6e8036349f5480d05a6daa54976c9
# Parent  4f775318d2ecf6db1d7e93a967964defdea7eb19
Fixed: Monsters spawned by BossBrain cubes would move before being spawned on the clients therefore triggering warning messages (addresses 2655).

diff -r 4f775318d2ec -r 4fc55e66b7f6 docs/zandronum-history.txt
--- a/docs/zandronum-history.txt	Wed Dec 20 22:00:46 2023 -0500
+++ b/docs/zandronum-history.txt	Tue Jan 09 13:30:16 2024 -0600
@@ -110,6 +110,7 @@
 -	- Fixed: flags in CTF could be captured after the round was over. [auratoostronk]
 -	- Fixed: opening the text scaling menu sometimes changed the user's con_virtualwidth and/or con_virtualheight CVars when it shouldn't. [Kaminsky]
 -	- Fixed: the coop info wasn't getting drawn in clientside demos. [Kaminsky]
+-   - Fixed: Monsters spawned by BossBrain cubes would move before being spawned on the clients therefore triggering warning messages (addresses 2655). [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 4f775318d2ec -r 4fc55e66b7f6 src/g_doom/a_bossbrain.cpp
--- a/src/g_doom/a_bossbrain.cpp	Wed Dec 20 22:00:46 2023 -0500
+++ b/src/g_doom/a_bossbrain.cpp	Tue Jan 09 13:30:16 2024 -0600
@@ -295,6 +295,11 @@
 		newmobj = Spawn (spawntype, targ->x, targ->y, targ->z, ALLOW_REPLACE);
 		if (newmobj != NULL)
 		{
+			// [BC] If we're the server, tell clients to spawn the new monster.
+			// [RK] We'll spawn it on the clients now since CallAction will move it.
+			if ( NETWORK_GetState() == NETSTATE_SERVER )
+				SERVERCOMMANDS_SpawnThing( newmobj );
+			
 			// Make the new monster hate what the boss eye hates
 			if (eye != NULL)
 			{
@@ -313,14 +318,19 @@
 				// telefrag anything in this spot
 				P_TeleportMove (newmobj, newmobj->x, newmobj->y, newmobj->z, true);
 
-				// [BC] If we're the server, tell clients to spawn the new monster.
+				// [RK] The server updates the state info to the clients.
 				if ( NETWORK_GetState( ) == NETSTATE_SERVER )
 				{
-					SERVERCOMMANDS_SpawnThing( newmobj );
 					if ( newmobj->state == newmobj->SeeState )
 						SERVERCOMMANDS_SetThingState( newmobj, STATE_SEE );
 				}
 			}
+			else
+			{
+				// [RK] IF for some reason the monster wants to die at this point we'll remove it
+				if ( NETWORK_GetState( ) == NETSTATE_SERVER )
+					SERVERCOMMANDS_DestroyThing( newmobj );
+			}
 			newmobj->flags4 |= MF4_BOSSSPAWNED;
 		}
 	}
