From 69944f1521a25fb8d23868c7f351ce84cbb41fed Mon Sep 17 00:00:00 2001
From: Lactozilla <jp6781615@gmail.com>
Date: Sun, 6 Aug 2023 21:48:46 -0300
Subject: [PATCH] Properly replace MT_REDFLAG and MT_BLUEFLAG with the flags of
 the current teams

---
 src/g_game.c | 2 ++
 src/p_mobj.c | 9 ++++++++-
 src/p_spec.c | 8 ++++----
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/g_game.c b/src/g_game.c
index 112534b304..93c462387a 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -3941,6 +3941,8 @@ void G_InitTeam(UINT8 team)
 	G_FreeTeamData(team);
 
 	memset(&teams[team], 0, sizeof(team_t));
+
+	teams[team].flag = 1 << (team - 1);
 }
 
 UINT8 G_AddTeam(const char *name)
diff --git a/src/p_mobj.c b/src/p_mobj.c
index 2e6e685617..e6d7d6276d 100644
--- a/src/p_mobj.c
+++ b/src/p_mobj.c
@@ -12066,7 +12066,7 @@ static boolean P_AllowMobjSpawn(mapthing_t* mthing, mobjtype_t i)
 	}
 	else if (i == MT_BLUEFLAG || i == MT_REDFLAG || i == MT_TEAMFLAG)
 	{
-		UINT8 team = i == MT_TEAMFLAG ? mthing->args[0] : mobjinfo[i].mass;
+		UINT8 team = i == MT_TEAMFLAG ? mthing->args[0] : G_GetTeam(mobjinfo[i].mass);
 		if (team == TEAM_NONE || team >= numteams)
 			return false;
 		else if (flagmobjs[team] && !P_MobjWasRemoved(flagmobjs[team]))
@@ -12161,6 +12161,13 @@ static mobjtype_t P_GetMobjtypeSubstitute(mapthing_t *mthing, mobjtype_t i)
 			return MT_NULL;
 		return teams[team].flag_mobj_type;
 	}
+	else if (i == MT_BLUEFLAG || i == MT_REDFLAG)
+	{
+		INT32 team = G_GetTeam(mobjinfo[i].mass);
+		if (team == TEAM_NONE || team >= numteams)
+			return MT_NULL;
+		return teams[team].flag_mobj_type;
+	}
 
 	if (!(gametyperules & GTR_TEAMS))
 	{
diff --git a/src/p_spec.c b/src/p_spec.c
index ea345b1b9b..1606c55add 100644
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -3947,7 +3947,7 @@ void P_SetupSignExit(player_t *player)
 //
 boolean P_TeamHasFlagAtBase(UINT8 team)
 {
-	if (team == TEAM_NONE || team >= teamsingame)
+	if (team == TEAM_NONE || team >= numteams)
 		return false;
 
 	thinker_t *think;
@@ -4739,7 +4739,7 @@ static void P_ProcessExitSector(player_t *player, mtag_t sectag)
 
 static void P_ProcessTeamBase(player_t *player, UINT8 team)
 {
-	if (team == TEAM_NONE || team >= teamsingame)
+	if (team == TEAM_NONE || team >= numteams)
 		return;
 
 	if (!(gametyperules & GTR_TEAMFLAGS))
@@ -4795,14 +4795,14 @@ static void P_ProcessTeamBase(player_t *player, UINT8 team)
 	if (totalcaptured == 1)
 	{
 		UINT8 otherteam = teamscaptured[0];
-		HU_DoCEcho(va(M_GetText("%s%s\200\\captured the %s%s\200.\\\\\\\\"), GetChatColorForSkincolor(G_GetTeamColor(team)), player_names[player-players], GetChatColorForSkincolor(G_GetTeamColor(otherteam)), G_GetTeamFlagName(otherteam)));
+		HU_DoCEcho(va(M_GetText("%s%s\200\\captured the %s%s\200.\\\\\\\\"), GetChatColorForSkincolor(G_GetTeamColor(player->ctfteam)), player_names[player-players], GetChatColorForSkincolor(G_GetTeamColor(otherteam)), G_GetTeamFlagName(otherteam)));
 	}
 	else
 	{
 		char *buffer = NULL;
 		size_t buffer_size = 0;
 
-		const char *text = va(M_GetText("%s%s\200 captured the:\\"), GetChatColorForSkincolor(G_GetTeamColor(team)), player_names[player-players]);
+		const char *text = va(M_GetText("%s%s\200 captured the:\\"), GetChatColorForSkincolor(G_GetTeamColor(player->ctfteam)), player_names[player-players]);
 		buffer_size += strlen(text) + 1;
 		buffer = Z_Realloc(buffer, buffer_size, PU_STATIC, NULL);
 		strcpy(buffer, text);
-- 
GitLab