]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_ca.qc
CA and Freezetag: centerprint "^F4You are now alone!" to the last alive player of...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_ca.qc
index 8a6315c4236bd1673758253449af1889fe2e35e8..5236889adc0bae395e2c533d0d95100fdba3ce89 100644 (file)
@@ -106,29 +106,32 @@ void CA_RoundStart()
                allowed_to_spawn = FALSE;
 }
 
-float prev_total_players;
+float prev_missing_teams_mask;
 float CA_CheckTeams()
 {
        allowed_to_spawn = TRUE;
        CA_count_alive_players();
        if(CA_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)
        {
-               float p1 = 0, p2 = 0, p3 = 0, p4 = 0;
-               if(!redalive) p1 = NUM_TEAM_1;
-               if(!bluealive) p2 = NUM_TEAM_2;
-               if(ca_teams >= 3)
-               if(!yellowalive) p3 = NUM_TEAM_3;
-               if(ca_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;
+               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(ca_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
+       if(ca_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
+       if(prev_missing_teams_mask != missing_teams_mask)
+       {
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
+               prev_missing_teams_mask = missing_teams_mask;
        }
        return 0;
 }
@@ -142,6 +145,7 @@ MUTATOR_HOOKFUNCTION(ca_PlayerSpawn)
 MUTATOR_HOOKFUNCTION(ca_PutClientInServer)
 {
        if(!allowed_to_spawn)
+       if(IS_PLAYER(self)) // this is true even when player is trying to join
        {
                self.classname = "observer";
                if(self.jointime != time) //not when connecting
@@ -160,6 +164,11 @@ MUTATOR_HOOKFUNCTION(ca_reset_map_players)
        FOR_EACH_CLIENT(self)
        {
                self.killcount = 0;
+               if(!self.caplayer && IS_BOT_CLIENT(self))
+               {
+                       self.team = -1;
+                       self.caplayer = 1;
+               }
                if(self.caplayer)
                {
                        self.classname = "player";
@@ -188,13 +197,48 @@ MUTATOR_HOOKFUNCTION(ca_GetTeamCount)
        return 0;
 }
 
+entity ca_LastPlayerForTeam()
+{
+       entity pl, last_pl = world;
+       FOR_EACH_PLAYER(pl)
+       {
+               if(pl.health >= 1)
+               if(pl != self)
+               if(pl.team == self.team)
+               if(!last_pl)
+                       last_pl = pl;
+               else
+                       return world;
+       }
+       return last_pl;
+}
+
+void ca_LastPlayerForTeam_Notify()
+{
+       if(round_handler_IsActive())
+       if(round_handler_IsRoundStarted())
+       {
+               entity pl = ca_LastPlayerForTeam();
+               if(pl)
+                       Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
+       }
+}
+
 MUTATOR_HOOKFUNCTION(ca_PlayerDies)
 {
+       ca_LastPlayerForTeam_Notify();
        if(!allowed_to_spawn)
                self.respawn_flags =  RESPAWN_SILENT;
        return 1;
 }
 
+MUTATOR_HOOKFUNCTION(ca_ClientDisconnect)
+{
+       if(self.caplayer == 1)
+               ca_LastPlayerForTeam_Notify();
+       return 1;
+}
+
 MUTATOR_HOOKFUNCTION(ca_ForbidPlayerScore_Clear)
 {
        return 1;
@@ -202,6 +246,8 @@ MUTATOR_HOOKFUNCTION(ca_ForbidPlayerScore_Clear)
 
 MUTATOR_HOOKFUNCTION(ca_MakePlayerObserver)
 {
+       if(self.caplayer == 1)
+               ca_LastPlayerForTeam_Notify();
        if(self.killindicator_teamchange == -2)
                self.caplayer = 0;
        if(self.caplayer)
@@ -304,6 +350,7 @@ MUTATOR_DEFINITION(gamemode_ca)
        MUTATOR_HOOK(reset_map_players, ca_reset_map_players, CBC_ORDER_ANY);
        MUTATOR_HOOK(GetTeamCount, ca_GetTeamCount, CBC_ORDER_EXCLUSIVE);
        MUTATOR_HOOK(PlayerDies, ca_PlayerDies, CBC_ORDER_ANY);
+       MUTATOR_HOOK(ClientDisconnect, ca_ClientDisconnect, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidPlayerScore_Clear, ca_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidThrowCurrentWeapon, ca_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
        MUTATOR_HOOK(GiveFragsForKill, ca_GiveFragsForKill, CBC_ORDER_FIRST);