From e52801164890f37bae87abed155de558bb1d5a61 Mon Sep 17 00:00:00 2001 From: z411 Date: Wed, 28 Sep 2022 22:55:20 -0300 Subject: [PATCH] Using teamids instead of indexes for preventStalemate --- .../gamemode/clanarena/sv_clanarena.qc | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc b/qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc index 2b7f76def..00540060f 100644 --- a/qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc +++ b/qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc @@ -54,22 +54,20 @@ int CA_PreventStalemate() // https://gitlab.com/xonotic/xonotic-data.pk3dir/-/merge_requests/1022/ for(int i = 1; i <= AvailableTeams(); i++) { - if(!winnerTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(winnerTeam))) + if(!winnerTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam))) { secondTeam = winnerTeam; - winnerTeam = i; + winnerTeam = Team_IndexToTeam(i); } else { - if(!secondTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(secondTeam))) - { - secondTeam = i; - } + if(!secondTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam))) + secondTeam = Team_IndexToTeam(i); } } - if(Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(winnerTeam)) != Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(secondTeam))) - return Team_IndexToTeam(winnerTeam); + if(Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)) != Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam))) + return winnerTeam; // Equality. Let's check which team has more health now winnerTeam = 0; @@ -84,10 +82,8 @@ int CA_PreventStalemate() teamHealth = 0; // Add up health for the players in this team - FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it), + FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it) && it.team == Team_IndexToTeam(teamIndex), { - if (it.team != Team_IndexToTeam(teamIndex)) - continue; if (IS_DEAD(it)) continue; teamHealth += GetResource(it, RES_HEALTH) + GetResource(it, RES_ARMOR); @@ -98,21 +94,21 @@ int CA_PreventStalemate() { secondTeam = winnerTeam; secondTeamHealth = winnerTeamHealth; - winnerTeam = i; + winnerTeam = Team_IndexToTeam(i); winnerTeamHealth = teamHealth; } else { if(!secondTeam || teamHealth > secondTeamHealth) { - secondTeam = i; + secondTeam = Team_IndexToTeam(i); secondTeamHealth = teamHealth; } } } if(winnerTeamHealth != secondTeamHealth) - return Team_IndexToTeam(winnerTeam); + return winnerTeam; else return -2; // Equality. Can't avoid the stalemate. } -- 2.39.2