]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_freezetag.qc
Merge branch 'terencehill/misc_cleanups' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_freezetag.qc
index 83ec8573c0863f6c8851f0a430abe29a7382078f..f5c76f16f93e6591b238c25ab5c4701324afd58d 100644 (file)
@@ -33,31 +33,36 @@ void freezetag_count_alive_players()
                e.yellowalive_stat = yellowalive;
                e.pinkalive_stat = pinkalive;
        }
+
+       eliminatedPlayers.SendFlags |= 1;
 }
 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
 
-float prev_total_players;
+float prev_missing_teams_mask;
 float freezetag_CheckTeams()
 {
        if(FREEZETAG_ALIVE_TEAMS_OK())
        {
-               if(prev_total_players > 0)
+               if(prev_missing_teams_mask > 0)
                        Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
-               prev_total_players = -1;
+               prev_missing_teams_mask = -1;
                return 1;
        }
-       if(prev_total_players != total_players)
+       if(total_players == 0)
+       {
+               if(prev_missing_teams_mask > 0)
+                       Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
+               prev_missing_teams_mask = -1;
+               return 0;
+       }
+       float missing_teams_mask = (!redalive) + (!bluealive) * 2;
+       if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
+       if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
+       if(prev_missing_teams_mask != missing_teams_mask)
        {
-               float p1 = 0, p2 = 0, p3 = 0, p4 = 0;
-               if(!redalive) p1 = NUM_TEAM_1;
-               if(!bluealive) p2 = NUM_TEAM_2;
-               if(freezetag_teams >= 3)
-               if(!yellowalive) p3 = NUM_TEAM_3;
-               if(freezetag_teams >= 4)
-               if(!pinkalive) p4 = NUM_TEAM_4;
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, p1, p2, p3, p4);
-               prev_total_players = total_players;
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
+               prev_missing_teams_mask = missing_teams_mask;
        }
        return 0;
 }
@@ -129,6 +134,34 @@ float freezetag_CheckWinner()
        return 1;
 }
 
+entity freezetag_LastPlayerForTeam()
+{
+       entity pl, last_pl = world;
+       FOR_EACH_PLAYER(pl)
+       {
+               if(pl.health >= 1)
+               if(!pl.frozen)
+               if(pl != self)
+               if(pl.team == self.team)
+               if(!last_pl)
+                       last_pl = pl;
+               else
+                       return world;
+       }
+       return last_pl;
+}
+
+void freezetag_LastPlayerForTeam_Notify()
+{
+       if(round_handler_IsActive())
+       if(round_handler_IsRoundStarted())
+       {
+               entity pl = freezetag_LastPlayerForTeam();
+               if(pl)
+                       Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
+       }
+}
+
 void freezetag_Add_Score(entity attacker)
 {
        if(attacker == self)
@@ -170,6 +203,13 @@ void freezetag_Unfreeze(entity attacker)
        Unfreeze(self);
 }
 
+float freezetag_isEliminated(entity e)
+{
+       if(e.frozen == 1 || e.deadflag != DEAD_NO)
+               return TRUE;
+       return FALSE;
+}
+
 
 // ================
 // Bot player logic
@@ -282,6 +322,8 @@ void havocbot_role_ft_freeing()
 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
 {
        self.health = 0; // neccessary to update correctly alive stats
+       if(!self.frozen)
+               freezetag_LastPlayerForTeam_Notify();
        freezetag_Unfreeze(world);
        freezetag_count_alive_players();
        return 1;
@@ -308,6 +350,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
                {
                        freezetag_Add_Score(frag_attacker);
                        freezetag_count_alive_players();
+                       freezetag_LastPlayerForTeam_Notify();
                }
                else
                        freezetag_Unfreeze(world); // remove ice
@@ -320,6 +363,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
                return 1;
 
        freezetag_Freeze(frag_attacker);
+       freezetag_LastPlayerForTeam_Notify();
 
        if(frag_attacker == frag_target || frag_attacker == world)
        {
@@ -516,6 +560,8 @@ void freezetag_Initialize()
        addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
        addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
        addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
+
+       EliminatedPlayers_Init(freezetag_isEliminated);
 }
 
 MUTATOR_DEFINITION(gamemode_freezetag)