]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator/gamemode_ca.qc
Cleanup server mutator #includes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_ca.qc
index ebd964077984c9caa12b30dc6dfcdaa418e33934..209c8b85673b09a587379821121c72fe69daf7ca 100644 (file)
@@ -36,7 +36,15 @@ REGISTER_MUTATOR(ca, false)
                if (ca_teams < 2) ca_teams = autocvar_g_ca_teams;
                ca_teams = bound(2, ca_teams, 4);
 
-        ScoreRules_basics(ca_teams, SFL_SORT_PRIO_PRIMARY, 0, true);
+               int teams = 0;
+               if(ca_teams >= 1) teams |= BIT(0);
+               if(ca_teams >= 2) teams |= BIT(1);
+               if(ca_teams >= 3) teams |= BIT(2);
+               if(ca_teams >= 4) teams |= BIT(3);
+
+               ca_teams = teams; // now set it?
+
+        ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
         ScoreInfo_SetLabel_TeamScore(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY);
         ScoreRules_basics_end();
 
@@ -117,13 +125,13 @@ float CA_GetWinnerTeam()
 void nades_Clear(entity player);
 
 #define CA_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
-#define CA_ALIVE_TEAMS_OK() (CA_ALIVE_TEAMS() == ca_teams)
+#define CA_ALIVE_TEAMS_OK() (CA_ALIVE_TEAMS() == NumTeams(ca_teams))
 float CA_CheckWinner()
 {
        if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
        {
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
+               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
                allowed_to_spawn = false;
                round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
                FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(nades_Clear(it)));
@@ -137,14 +145,14 @@ float CA_CheckWinner()
        int winner_team = CA_GetWinnerTeam();
        if(winner_team > 0)
        {
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
+               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));
                TeamScore_AddToTeam(winner_team, ST_CA_ROUNDS, +1);
        }
        else if(winner_team == -1)
        {
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
        }
 
        allowed_to_spawn = false;
@@ -168,23 +176,29 @@ bool CA_CheckTeams()
        if(CA_ALIVE_TEAMS_OK())
        {
                if(prev_missing_teams_mask > 0)
-                       Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
+                       Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
                prev_missing_teams_mask = -1;
                return true;
        }
        if(total_players == 0)
        {
                if(prev_missing_teams_mask > 0)
-                       Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
+                       Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
                prev_missing_teams_mask = -1;
                return false;
        }
-       int missing_teams_mask = (!redalive) + (!bluealive) * 2;
-       if(ca_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
-       if(ca_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
+       int missing_teams_mask = 0;
+       if(ca_teams & BIT(0))
+               missing_teams_mask += (!redalive) * 1;
+       if(ca_teams & BIT(1))
+               missing_teams_mask += (!bluealive) * 2;
+       if(ca_teams & BIT(2))
+               missing_teams_mask += (!yellowalive) * 4;
+       if(ca_teams & BIT(3))
+               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);
+               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
                prev_missing_teams_mask = missing_teams_mask;
        }
        return false;
@@ -254,7 +268,7 @@ MUTATOR_HOOKFUNCTION(ca, reset_map_players)
                {
                        TRANSMUTE(Player, it);
                        it.caplayer = 1;
-                       WITHSELF(it, PutClientInServer());
+                       PutClientInServer(it);
                }
        });
        return true;
@@ -279,9 +293,8 @@ MUTATOR_HOOKFUNCTION(ca, GetTeamCount, CBC_ORDER_EXCLUSIVE)
        M_ARGV(0, float) = ca_teams;
 }
 
-entity ca_LastPlayerForTeam()
+entity ca_LastPlayerForTeam(entity this)
 {
-    SELFPARAM();
        entity last_pl = NULL;
        FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
                if (!IS_DEAD(it))
@@ -294,12 +307,12 @@ entity ca_LastPlayerForTeam()
        return last_pl;
 }
 
-void ca_LastPlayerForTeam_Notify()
+void ca_LastPlayerForTeam_Notify(entity this)
 {
        if (round_handler_IsActive())
        if (round_handler_IsRoundStarted())
        {
-               entity pl = ca_LastPlayerForTeam();
+               entity pl = ca_LastPlayerForTeam(this);
                if (pl)
                        Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
        }
@@ -308,13 +321,13 @@ void ca_LastPlayerForTeam_Notify()
 MUTATOR_HOOKFUNCTION(ca, PlayerDies)
 {
        entity frag_target = M_ARGV(2, entity);
-       
-       ca_LastPlayerForTeam_Notify();
+
+       ca_LastPlayerForTeam_Notify(frag_target);
        if (!allowed_to_spawn)
                frag_target.respawn_flags =  RESPAWN_SILENT;
        if (!warmup_stage)
                eliminatedPlayers.SendFlags |= 1;
-       return 1;
+       return true;
 }
 
 MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
@@ -322,13 +335,13 @@ MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
     entity player = M_ARGV(0, entity);
 
        if (player.caplayer == 1)
-               ca_LastPlayerForTeam_Notify();
+               ca_LastPlayerForTeam_Notify(player);
        return true;
 }
 
 MUTATOR_HOOKFUNCTION(ca, ForbidPlayerScore_Clear)
 {
-       return 1;
+       return true;
 }
 
 MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver)
@@ -336,11 +349,13 @@ MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver)
     entity player = M_ARGV(0, entity);
 
        if (!IS_DEAD(player))
-               ca_LastPlayerForTeam_Notify();
+               ca_LastPlayerForTeam_Notify(player);
        if (player.killindicator_teamchange == -2)
                player.caplayer = 0;
        if (player.caplayer)
                player.frags = FRAGS_LMS_LOSER;
+    else
+        player.frags = FRAGS_SPECTATOR;
        if (!warmup_stage)
                eliminatedPlayers.SendFlags |= 1;
        return true;  // prevent team reset
@@ -368,8 +383,6 @@ MUTATOR_HOOKFUNCTION(ca, SetStartItems)
        start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_lms_start_ammo_cells");
        start_ammo_plasma  = warmup_start_ammo_plasma  = cvar("g_lms_start_ammo_plasma");
        start_ammo_fuel    = warmup_start_ammo_fuel    = cvar("g_lms_start_ammo_fuel");
-
-       return 0;
 }
 
 MUTATOR_HOOKFUNCTION(ca, PlayerDamage_Calculate)
@@ -389,8 +402,6 @@ MUTATOR_HOOKFUNCTION(ca, PlayerDamage_Calculate)
 
        M_ARGV(4, float) = frag_damage;
        M_ARGV(5, float) = frag_mirrordamage;
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(ca, FilterItem)
@@ -403,8 +414,6 @@ MUTATOR_HOOKFUNCTION(ca, FilterItem)
 
        if (autocvar_g_pickup_items <= 0)
                return true;
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor)
@@ -441,21 +450,18 @@ MUTATOR_HOOKFUNCTION(ca, SpectateSet)
        if (!autocvar_g_ca_spectate_enemies && client.caplayer)
        if (DIFF_TEAM(targ, client))
                return true;
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(ca, SpectateNext)
 {
     entity client = M_ARGV(0, entity);
-    entity targ = M_ARGV(1, entity);
 
        if (!autocvar_g_ca_spectate_enemies && client.caplayer)
        {
-               targ = CA_SpectateNext(client, targ);
+               entity targ = M_ARGV(1, entity);
+               M_ARGV(1, entity) = CA_SpectateNext(client, targ);
                return true;
        }
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(ca, SpectatePrev)
@@ -478,6 +484,8 @@ MUTATOR_HOOKFUNCTION(ca, SpectatePrev)
                }
        }
 
+       M_ARGV(1, entity) = targ;
+
        return MUT_SPECPREV_FOUND;
 }