]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/teamplay.qc
Merge branch 'master' into terencehill/translate_colors_2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / teamplay.qc
index 0662aab68ece77f479b001efc99f4a11cee5c488..c275faa7c300b3d97c1115f47603f06317108388 100644 (file)
@@ -31,7 +31,7 @@ void LogTeamchange(float player_id, float team_number, float type)
        GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
 }
 
-void default_delayedinit()
+void default_delayedinit(entity this)
 {
        if(!scores_initialized)
                ScoreRules_generic();
@@ -44,23 +44,6 @@ void ActivateTeamplay()
        cvar_set("teamplay", "2");  // DP needs this for sending proper getstatus replies.
 }
 
-void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override)
-{
-       // enforce the server's universal frag/time limits
-       // set to -1 to not change value
-       if(!autocvar_g_campaign)
-       {
-               if(fraglimit_override >= 0)
-                       cvar_set("fraglimit", ftos(fraglimit_override));
-               if(timelimit_override >= 0)
-                       cvar_set("timelimit", ftos(timelimit_override));
-               if(leadlimit_override >= 0)
-                       cvar_set("leadlimit", ftos(leadlimit_override));
-               if(qualifying_override >= 0)
-                       cvar_set("g_race_qualifying_timelimit", ftos(qualifying_override));
-       }
-}
-
 void InitGameplayMode()
 {
        VoteReset();
@@ -89,8 +72,6 @@ void InitGameplayMode()
 
        MapInfo_ClearTemps();
 
-       // set both here, gamemode can override it later
-       SetLimits(autocvar_fraglimit_override, autocvar_leadlimit_override, autocvar_timelimit_override, -1);
        gamemode_name = MapInfo_Type_ToText(MapInfo_LoadedGametype);
 
        cache_mutatormsg = strzone("");
@@ -308,26 +289,24 @@ float PlayerValue(entity p)
 // teams that are allowed will now have their player counts stored in c1...c4
 void GetTeamCounts(entity ignore)
 {
-       entity head;
        float value, bvalue;
        // now count how many players are on each team already
 
        // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
        // also remember the lowest-scoring player
 
-       FOR_EACH_CLIENT(head)
-       {
+       FOREACH_CLIENT(true, LAMBDA(
                float t;
-               if(IS_PLAYER(head) || head.caplayer)
-                       t = head.team;
-               else if(head.team_forced > 0)
-                       t = head.team_forced; // reserve the spot
+               if(IS_PLAYER(it) || it.caplayer)
+                       t = it.team;
+               else if(it.team_forced > 0)
+                       t = it.team_forced; // reserve the spot
                else
                        continue;
-               if(head != ignore)// && head.netname != "")
+               if(it != ignore)// && it.netname != "")
                {
-                       value = PlayerValue(head);
-                       if(IS_BOT_CLIENT(head))
+                       value = PlayerValue(it);
+                       if(IS_BOT_CLIENT(it))
                                bvalue = value;
                        else
                                bvalue = 0;
@@ -364,7 +343,7 @@ void GetTeamCounts(entity ignore)
                                }
                        }
                }
-       }
+       ));
 
        // if the player who has a forced team has not joined yet, reserve the spot
        if(autocvar_g_campaign)
@@ -501,7 +480,7 @@ float FindSmallestTeam(entity pl, float ignore_pl)
        return RandomSelection_chosen_float;
 }
 
-float JoinBestTeam(entity pl, float only_return_best, float forcebestteam)
+int JoinBestTeam(entity pl, bool only_return_best, bool forcebestteam)
 {SELFPARAM();
        float smallest, selectedteam;
 
@@ -570,7 +549,7 @@ float JoinBestTeam(entity pl, float only_return_best, float forcebestteam)
 
                LogTeamchange(pl.playerid, pl.team, 2); // log auto join
 
-               if(pl.deadflag == DEAD_NO)
+               if(!IS_DEAD(pl))
                        Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE.m_id, pl.origin, '0 0 0');
        }
 
@@ -583,11 +562,19 @@ void SV_ChangeTeam(float _color)
        float scolor, dcolor, steam, dteam; //, dbotcount, scount, dcount;
 
        // in normal deathmatch we can just apply the color and we're done
-       if(!teamplay) {
+       if(!teamplay)
                SetPlayerColors(self, _color);
+
+       if(!IS_CLIENT(self))
+       {
+               // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_CONNECTING, self.netname);
                return;
        }
 
+       if(!teamplay)
+               return;
+
        scolor = self.clientcolors & 0x0F;
        dcolor = _color & 0x0F;
 
@@ -647,10 +634,6 @@ void SV_ChangeTeam(float _color)
                TeamchangeFrags(self);
        }
 
-       // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
-       if(!IS_CLIENT(self))
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_CONNECTING, self.netname);
-
        MUTATOR_CALLHOOK(Player_ChangeTeam, self, steam, dteam);
 
        SetPlayerTeam(self, dteam, steam, !IS_CLIENT(self));
@@ -658,7 +641,7 @@ void SV_ChangeTeam(float _color)
        if(IS_PLAYER(self) && steam != dteam)
        {
                // kill player when changing teams
-               if(self.deadflag == DEAD_NO)
+               if(!IS_DEAD(self))
                        Damage(self, self, self, 100000, DEATH_TEAMCHANGE.m_id, self.origin, '0 0 0');
        }
 }
@@ -667,7 +650,7 @@ void ShufflePlayerOutOfTeam (float source_team)
 {
        float smallestteam, smallestteam_count, steam;
        float lowest_bot_score, lowest_player_score;
-       entity head, lowest_bot, lowest_player, selected;
+       entity lowest_bot, lowest_player, selected;
 
        smallestteam = 0;
        smallestteam_count = 999999999;
@@ -714,28 +697,24 @@ void ShufflePlayerOutOfTeam (float source_team)
        lowest_player_score = 999999999;
 
        // find the lowest-scoring player & bot of that team
-       FOR_EACH_PLAYER(head)
-       {
-               if(head.team == steam)
+       FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, LAMBDA(
+               if(it.isbot)
                {
-                       if(head.isbot)
+                       if(it.totalfrags < lowest_bot_score)
                        {
-                               if(head.totalfrags < lowest_bot_score)
-                               {
-                                       lowest_bot = head;
-                                       lowest_bot_score = head.totalfrags;
-                               }
+                               lowest_bot = it;
+                               lowest_bot_score = it.totalfrags;
                        }
-                       else
+               }
+               else
+               {
+                       if(it.totalfrags < lowest_player_score)
                        {
-                               if(head.totalfrags < lowest_player_score)
-                               {
-                                       lowest_player = head;
-                                       lowest_player_score = head.totalfrags;
-                               }
+                               lowest_player = it;
+                               lowest_player_score = it.totalfrags;
                        }
                }
-       }
+       ));
 
        // prefers to move a bot...
        if(lowest_bot != world)
@@ -799,7 +778,7 @@ void ShufflePlayerOutOfTeam (float source_team)
        TeamchangeFrags(selected);
        SetPlayerTeam(selected, smallestteam, source_team, false);
 
-       if(selected.deadflag == DEAD_NO)
+       if(!IS_DEAD(selected))
                Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0');
        Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team);
 }