]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc
Merge branch 'master' into z411/bai-server
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / clanarena / sv_clanarena.qc
index 8ee0a676569b8364f931e52b7a976c87d2f858ef..2c4a097d6f5fe4dde48b81bcc46ca9ba8d93d331 100644 (file)
@@ -20,15 +20,22 @@ void CA_count_alive_players()
        for (int i = 1; i <= NUM_TEAMS; ++i)
        {
                Team_SetNumberOfAlivePlayers(Team_GetTeamFromIndex(i), 0);
+               Team_SetNumberOfPlayers(Team_GetTeamFromIndex(i), 0);
        }
-       FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it),
+       FOREACH_CLIENT(Entity_HasValidTeam(it),
        {
                ++total_players;
-               if (IS_DEAD(it))
+               entity team_ = Entity_GetTeam(it);
+               
+               int num_total = Team_GetNumberOfPlayers(team_);
+               ++num_total;
+               Team_SetNumberOfPlayers(team_, num_total);
+               
+               if (IS_DEAD(it) || !IS_PLAYER(it))
                {
                        continue;
                }
-               entity team_ = Entity_GetTeam(it);
+               
                int num_alive = Team_GetNumberOfAlivePlayers(team_);
                ++num_alive;
                Team_SetNumberOfAlivePlayers(team_, num_alive);
@@ -44,6 +51,22 @@ void CA_count_alive_players()
 
 void nades_Clear(entity player);
 
+entity ca_LastPlayer(float tm)
+{
+       entity last_pl = NULL;
+       FOREACH_CLIENT(IS_PLAYER(it) && it.team == tm, {
+               if (!IS_DEAD(it))
+               {
+                       if (!last_pl)
+                               last_pl = it;
+                       else
+                               return NULL;
+               }
+       });
+       return last_pl;
+}
+
+
 int CA_PreventStalemate()
 {
        //bprint("PreventStalemate running\n");
@@ -159,28 +182,59 @@ float CA_CheckWinner()
        if (!winner_team)
                return 0;
 
+       bool perfect = false;
        if(winner_team > 0)
        {
+               entity tm = Team_GetTeam(winner_team);
+               entity last_pl = ca_LastPlayer(winner_team);
+               
+               if(last_pl && Team_GetNumberOfPlayers(tm) >= 3) {
+                       Give_Medal(last_pl, DEFENSE);
+               }
+               
                Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
                Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
+               if(fragsleft > 1) Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, APP_TEAM_NUM(winner_team, ANNCE_ROUND_TEAM_WIN));
                TeamScore_AddToTeam(winner_team, ST_CA_ROUNDS, +1);
+               
+               if (Team_GetNumberOfPlayers(tm) >= 3 &&
+                       Team_GetNumberOfAlivePlayers(tm) == Team_GetNumberOfPlayers(tm))
+                               perfect = true;
        }
        else if(winner_team == -1)
        {
                Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
                Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_ROUND_TIED);
        }
        else if(winner_team == -2)
        {
                Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
                Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
+               Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_ROUND_OVER);
        }
 
        allowed_to_spawn = false;
-       game_stopped = true;
+       if(autocvar_g_ca_round_stop)
+               game_stopped = true;
        round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
 
-       FOREACH_CLIENT(IS_PLAYER(it), { nades_Clear(it); });
+       FOREACH_CLIENT(IS_PLAYER(it), {
+               nades_Clear(it);
+               
+               // Give perfect medal if everyone in the winner team is alive
+               if(perfect && it.team == winner_team) {
+                       Give_Medal(it, PERFECT);
+               }
+               
+               // Give accuracy medal for each weapon above 50%
+               entity ra = it.roundaccuracy;
+               for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w) {
+                       if(ra.accuracy_fired[w] > 1 && (ra.accuracy_hit[w] / ra.accuracy_fired[w]) > 0.5) {
+                               Give_Medal(it, ACCURACY);
+                       }
+               }
+       });
 
        return 1;
 }
@@ -313,6 +367,12 @@ MUTATOR_HOOKFUNCTION(ca, reset_map_players)
        return true;
 }
 
+MUTATOR_HOOKFUNCTION(ca, Scores_CountFragsRemaining)
+{
+       // announce remaining frags
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(ca, reset_map_global)
 {
        allowed_to_spawn = true;
@@ -345,8 +405,10 @@ void ca_LastPlayerForTeam_Notify(entity this)
        if (!warmup_stage && round_handler_IsActive() && round_handler_IsRoundStarted())
        {
                entity pl = ca_LastPlayerForTeam(this);
-               if (pl)
+               if (pl) {
                        Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
+                       Send_Notification(NOTIF_ONE, pl, MSG_ANNCE, ANNCE_ALONE);
+               }
        }
 }
 
@@ -526,12 +588,6 @@ MUTATOR_HOOKFUNCTION(ca, PlayerRegen)
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(ca, Scores_CountFragsRemaining)
-{
-       // announce remaining frags
-       return true;
-}
-
 MUTATOR_HOOKFUNCTION(ca, SpectateSet)
 {
        entity client = M_ARGV(0, entity);