#include "sv_clanarena.qh"
float autocvar_g_ca_damage2score = 100;
-bool autocvar_g_ca_prevent_stalemate;
+int autocvar_g_ca_prevent_stalemate;
float autocvar_g_ca_start_health = 200;
float autocvar_g_ca_start_armor = 200;
int CA_PreventStalemate()
{
- //LOG_INFO("PreventStalemate running");
- int winnerTeam = 0;
- int secondTeam = 0;
+ //bprint("PreventStalemate running\n");
- for(int i = 1; i <= AVAILABLE_TEAMS; i++)
+ // g_ca_prevent_stalemate:
+ // Run survivor count check with 1 aka bit 0b0001
+ // Run total health check with 2 aka bit 0b0010
+ // With a value like 3 which has both bits both are ran
+
+ bool prevent_stalemate_by_survivors = (autocvar_g_ca_prevent_stalemate & BIT(0));
+ bool prevent_stalemate_by_health = (autocvar_g_ca_prevent_stalemate & BIT(1));
+
+ // Check which team has more alive players
+ if (prevent_stalemate_by_survivors)
{
- if(!winnerTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)))
+ int winnerTeam = 0;
+ int secondTeam = 0;
+
+ for(int i = 1; i <= AVAILABLE_TEAMS; ++i)
{
- secondTeam = winnerTeam;
- winnerTeam = Team_IndexToTeam(i);
+ if(!winnerTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)))
+ {
+ secondTeam = winnerTeam;
+ winnerTeam = Team_IndexToTeam(i);
+ }
+ else
+ {
+ if(!secondTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam)))
+ secondTeam = Team_IndexToTeam(i);
+ }
}
- else
+
+ if(Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)) != Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam)))
{
- if(!secondTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam)))
- secondTeam = Team_IndexToTeam(i);
+ bprint(sprintf("Stalemate broken by alive players. Best team: %s%s (%d)^7 - Trailing team: %s%s (%d)\n",
+ Team_ColorCode(winnerTeam), Team_ColorName(winnerTeam), Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)),
+ Team_ColorCode(secondTeam), Team_ColorName(secondTeam), Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam))));
+ return winnerTeam;
}
}
- if(Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)) != Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam)))
+ // Check which team has more health
+ if (prevent_stalemate_by_health)
{
- LOG_INFOF("Stalemate broken by alive players. Best team: %s%s (%d)^7 - Trailing team: %s%s (%d)",
- Team_ColorCode(winnerTeam), Team_ColorName(winnerTeam), Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)),
- Team_ColorCode(secondTeam), Team_ColorName(secondTeam), Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam)));
- return winnerTeam;
- }
-
- // Equality. Let's check which team has more health now
- //LOG_INFO("Equality. Checking health now.");
- winnerTeam = 0;
- secondTeam = 0;
- int winnerTeamHealth = 0;
- int secondTeamHealth = 0;
- int teamIndex, teamHealth;
+ int winnerTeam = 0;
+ int secondTeam = 0;
+ int winnerTeamHealth = 0;
+ int secondTeamHealth = 0;
+ int teamIndex, teamHealth;
- for(int i = 1; i <= AVAILABLE_TEAMS; i++)
- {
- teamIndex = i;
- teamHealth = 0;
-
- // Add up health for the players in this team
- FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it) && it.team == Team_IndexToTeam(teamIndex),
+ for(int i = 1; i <= AVAILABLE_TEAMS; ++i)
{
- if (IS_DEAD(it))
- continue;
- teamHealth += GetResource(it, RES_HEALTH) + GetResource(it, RES_ARMOR);
- });
+ teamIndex = i;
+ teamHealth = 0;
- // Set the winner teams
- if(!winnerTeam || teamHealth > winnerTeamHealth)
- {
- secondTeam = winnerTeam;
- secondTeamHealth = winnerTeamHealth;
- winnerTeam = Team_IndexToTeam(i);
- winnerTeamHealth = teamHealth;
- }
- else
- {
- if(!secondTeam || teamHealth > secondTeamHealth)
+ // Add up health for the players in this team
+ FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it) && it.team == Team_IndexToTeam(teamIndex),
+ {
+ if (IS_DEAD(it))
+ continue;
+ teamHealth += GetResource(it, RES_HEALTH) + GetResource(it, RES_ARMOR);
+ });
+
+ // Set the winner teams
+ if(!winnerTeam || teamHealth > winnerTeamHealth)
+ {
+ secondTeam = winnerTeam;
+ secondTeamHealth = winnerTeamHealth;
+ winnerTeam = Team_IndexToTeam(i);
+ winnerTeamHealth = teamHealth;
+ }
+ else
{
- secondTeam = Team_IndexToTeam(i);
- secondTeamHealth = teamHealth;
+ if(!secondTeam || teamHealth > secondTeamHealth)
+ {
+ secondTeam = Team_IndexToTeam(i);
+ secondTeamHealth = teamHealth;
+ }
}
}
- }
- if(winnerTeamHealth != secondTeamHealth)
- {
- LOG_INFOF("Stalemate broken by team health. Best team: %s%s (%d)^7 - Trailing team: %s%s (%d)",
- Team_ColorCode(winnerTeam), Team_ColorName(winnerTeam), winnerTeamHealth,
- Team_ColorCode(secondTeam), Team_ColorName(secondTeam), secondTeamHealth);
- return winnerTeam;
+ if(winnerTeamHealth != secondTeamHealth)
+ {
+ bprint(sprintf("Stalemate broken by team health. Best team: %s%s (%d)^7 - Trailing team: %s%s (%d)\n",
+ Team_ColorCode(winnerTeam), Team_ColorName(winnerTeam), winnerTeamHealth,
+ Team_ColorCode(secondTeam), Team_ColorName(secondTeam), secondTeamHealth));
+ return winnerTeam;
+ }
}
- else
- return -2; // Equality. Can't avoid the stalemate.
+
+ return -2; // Equality. Can't avoid the stalemate.
}
float CA_CheckWinner()
if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
{
- if(autocvar_g_ca_prevent_stalemate)
+ // attempt to prevent stalemate by survivor count AND/OR total team health?
+ bool prevent_stalemate_by_survivors = (autocvar_g_ca_prevent_stalemate & BIT(0));
+ bool prevent_stalemate_by_health = (autocvar_g_ca_prevent_stalemate & BIT(1));
+
+ if(prevent_stalemate_by_survivors || prevent_stalemate_by_health)
winner_team = CA_PreventStalemate();
else
winner_team = -2;