From b51e80ef8824aa77bbd21d955023379a94e7dd67 Mon Sep 17 00:00:00 2001
From: toasterbabe <rollerorbital@gmail.com>
Date: Sat, 5 Aug 2017 22:13:35 +0100
Subject: [PATCH] Make timer reset work in LF_NORELOAD as well.

---
 src/g_game.c  | 34 +++++++++++++++++++++++++++-------
 src/p_setup.c |  1 +
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/g_game.c b/src/g_game.c
index 6e43aeb8ba..600c8c8964 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -2592,6 +2592,8 @@ void G_DoReborn(INT32 playernum)
 		{
 			for (i = 0; i < MAXPLAYERS; i++)
 			{
+				if (!playeringame[i])
+					continue;
 				players[i].starpostangle = 0;
 				players[i].starposttime = 0;
 				players[i].starpostx = 0;
@@ -2602,9 +2604,15 @@ void G_DoReborn(INT32 playernum)
 		}
 		if (!countdowntimeup && (mapheaderinfo[gamemap-1]->levelflags & LF_NORELOAD))
 		{
-			player->playerstate = PST_REBORN;
 			P_LoadThingsOnly();
-			P_ClearStarPost(player->starpostnum);
+
+			for (i = 0; i < MAXPLAYERS; i++)
+			{
+				if (!playeringame[i])
+					continue;
+				players[i].playerstate = PST_REBORN;
+				P_ClearStarPost(players[i].starpostnum);
+			}
 
 			// Do a wipe
 			wipegamestate = -1;
@@ -2628,12 +2636,24 @@ void G_DoReborn(INT32 playernum)
 			CON_ClearHUD();
 
 			// Starpost support
-			G_SpawnPlayer(playernum, (player->starposttime));
+			for (i = 0; i < MAXPLAYERS; i++)
+			{
+				if (!playeringame[i])
+					continue;
+				G_SpawnPlayer(i, (players[i].starposttime));
+			}
 
-			if (botingame)
-			{ // Bots respawn next to their master.
-				players[secondarydisplayplayer].playerstate = PST_REBORN;
-				G_SpawnPlayer(secondarydisplayplayer, false);
+			// restore time in netgame (see also p_setup.c)
+			if ((netgame || multiplayer) && gametype == GT_COOP && cv_coopstarposts.value == 2)
+			{
+				// is this a hack? maybe
+				tic_t maxstarposttime = 0;
+				for (i = 0; i < MAXPLAYERS; i++)
+				{
+					if (playeringame[i] && players[i].starposttime > maxstarposttime)
+						maxstarposttime = players[i].starposttime;
+				}
+				leveltime = maxstarposttime;
 			}
 		}
 		else
diff --git a/src/p_setup.c b/src/p_setup.c
index d40f4fc3b1..8a91de76bb 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -2860,6 +2860,7 @@ boolean P_SetupLevel(boolean skipprecip)
 			}
 		}
 
+	// restore time in netgame (see also g_game.c)
 	if ((netgame || multiplayer) && gametype == GT_COOP && cv_coopstarposts.value == 2)
 	{
 		// is this a hack? maybe
-- 
GitLab