]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Separated `g_ca_prevent_stalemate`'s survivor count and health checking.
authorDr. Jaska <drjaska83@gmail.com>
Fri, 9 Feb 2024 01:42:19 +0000 (01:42 +0000)
committerDr. Jaska <drjaska83@gmail.com>
Fri, 9 Feb 2024 01:42:19 +0000 (01:42 +0000)
gamemodes-server.cfg
qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc

index 01d297e084a27827809150fc6aa2cfd705b9bc7b..a859acbded174ebaf334b8725ea30439b342c45a 100644 (file)
@@ -265,7 +265,7 @@ set g_ca_round_timelimit 180 "round time limit in seconds"
 set g_ca_teams_override 0
 set g_ca_team_spawns 0 "when 1, players spawn from the team spawnpoints of the map, if any"
 set g_ca_teams 0
-set g_ca_prevent_stalemate 0 "when round time ends instead of instant stalemate give round win to the team with most survivors or with the most total health"
+set g_ca_prevent_stalemate 0 "When round time ends instead of instant stalemate give round win to the team with 1: most survivors. 2: most total health. 3: most survivors or if equal then most total health"
 set g_ca_weaponarena "most" "starting weapons - takes the same options as g_weaponarena"
 
 
index f0a793afd50f4d39aa2d28fe1e3bfc313e438e43..8ee0a676569b8364f931e52b7a976c87d2f858ef 100644 (file)
@@ -1,7 +1,7 @@
 #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;
@@ -46,80 +46,95 @@ void nades_Clear(entity player);
 
 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()
@@ -128,7 +143,11 @@ 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;