]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/teamplay.qc
Merge branch 'master' into terencehill/scoreboard_panel_2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / teamplay.qc
index 7d31de0aeab695c2834d06c6bac51638cd9cdd06..56f85bd4689fd47a7f189dec8d57949435213adf 100644 (file)
@@ -5,7 +5,7 @@
 #include "scores.qh"
 #include "scores_rules.qh"
 
-#include "bot/bot.qh"
+#include "bot/api.qh"
 
 #include "command/vote.qh"
 
@@ -77,7 +77,7 @@ void InitGameplayMode()
        cache_mutatormsg = strzone("");
        cache_lastmutatormsg = strzone("");
 
-       InitializeEntity(world, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK);
+       InitializeEntity(NULL, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK);
 }
 
 string GetClientVersionMessage(entity this)
@@ -100,7 +100,7 @@ string getwelcomemessage(entity this)
        string s, modifications, motd;
 
        MUTATOR_CALLHOOK(BuildMutatorsPrettyString, "");
-       modifications = ret_string;
+       modifications = M_ARGV(0, string);
 
        if(g_weaponarena)
        {
@@ -147,7 +147,7 @@ string getwelcomemessage(entity this)
 
        string mutator_msg = "";
        MUTATOR_CALLHOOK(BuildGameplayTipsString, mutator_msg);
-       mutator_msg = ret_string;
+       mutator_msg = M_ARGV(0, string);
 
        s = strcat(s, mutator_msg); // trust that the mutator will do proper formatting
 
@@ -214,23 +214,21 @@ void CheckAllowedTeams (entity for_whom)
        string teament_name = string_null;
 
        bool mutator_returnvalue = MUTATOR_CALLHOOK(GetTeamCount, dm, teament_name);
-       teament_name = ret_string;
-       dm = ret_float;
+       dm = M_ARGV(0, float);
+       teament_name = M_ARGV(1, string);
 
        if(!mutator_returnvalue)
        {
-               if(dm >= 4)
-                       c1 = c2 = c3 = c4 = 0;
-               else if(dm >= 3)
-                       c1 = c2 = c3 = 0;
-               else
-                       c1 = c2 = 0;
+               if(dm & BIT(0)) c1 = 0;
+               if(dm & BIT(1)) c2 = 0;
+               if(dm & BIT(2)) c3 = 0;
+               if(dm & BIT(3)) c4 = 0;
        }
 
        // find out what teams are allowed if necessary
        if(teament_name)
        {
-               entity head = find(world, classname, teament_name);
+               entity head = find(NULL, classname, teament_name);
                while(head)
                {
                        switch(head.team)
@@ -246,24 +244,46 @@ void CheckAllowedTeams (entity for_whom)
        }
 
        // TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line)
-       if(c3==-1 && c4==-1)
+       if(AvailableTeams() == 2)
        if(autocvar_bot_vs_human && for_whom)
        {
                if(autocvar_bot_vs_human > 0)
                {
-                       // bots are all blue
+                       // find last team available
+
                        if(IS_BOT_CLIENT(for_whom))
-                               c1 = c3 = c4 = -1;
+                       {
+                               if(c4 >= 0) { c3 = c2 = c1 = -1; }
+                               else if(c3 >= 0) { c4 = c2 = c1 = -1; }
+                               else { c4 = c3 = c1 = -1; }
+                               // no further cases, we know at least 2 teams exist
+                       }
                        else
-                               c2 = -1;
+                       {
+                               if(c1 >= 0) { c2 = c3 = c4 = -1; }
+                               else if(c2 >= 0) { c1 = c3 = c4 = -1; }
+                               else { c1 = c2 = c4 = -1; }
+                               // no further cases, bots have one of the teams
+                       }
                }
                else
                {
-                       // bots are all red
+                       // find first team available
+
                        if(IS_BOT_CLIENT(for_whom))
-                               c2 = c3 = c4 = -1;
+                       {
+                               if(c1 >= 0) { c2 = c3 = c4 = -1; }
+                               else if(c2 >= 0) { c1 = c3 = c4 = -1; }
+                               else { c1 = c2 = c4 = -1; }
+                               // no further cases, we know at least 2 teams exist
+                       }
                        else
-                               c1 = -1;
+                       {
+                               if(c4 >= 0) { c3 = c2 = c1 = -1; }
+                               else if(c3 >= 0) { c4 = c2 = c1 = -1; }
+                               else { c4 = c3 = c1 = -1; }
+                               // no further cases, bots have one of the teams
+                       }
                }
        }
 
@@ -426,8 +446,12 @@ float TeamSmallerEqThanTeam(float ta, float tb, entity e)
 // NOTE: Assumes CheckAllowedTeams has already been called!
 float FindSmallestTeam(entity pl, float ignore_pl)
 {
-       float totalteams, t;
-       totalteams = 0;
+       int totalteams = 0;
+       int t = 1; // initialize with a random team?
+       if(c4 >= 0) t = 4;
+       if(c3 >= 0) t = 3;
+       if(c2 >= 0) t = 2;
+       if(c1 >= 0) t = 1;
 
        // find out what teams are available
        //CheckAllowedTeams();
@@ -457,11 +481,12 @@ float FindSmallestTeam(entity pl, float ignore_pl)
        if(ignore_pl)
                GetTeamCounts(pl);
        else
-               GetTeamCounts(world);
+               GetTeamCounts(NULL);
 
        RandomSelection_Init();
 
-       t = 1;
+       if(TeamSmallerEqThanTeam(1, t, pl))
+               t = 1;
        if(TeamSmallerEqThanTeam(2, t, pl))
                t = 2;
        if(TeamSmallerEqThanTeam(3, t, pl))
@@ -471,13 +496,13 @@ float FindSmallestTeam(entity pl, float ignore_pl)
 
        // now t is the minimum, or A minimum!
        if(t == 1 || TeamSmallerEqThanTeam(1, t, pl))
-               RandomSelection_Add(world, 1, string_null, 1, 1);
+               RandomSelection_Add(NULL, 1, string_null, 1, 1);
        if(t == 2 || TeamSmallerEqThanTeam(2, t, pl))
-               RandomSelection_Add(world, 2, string_null, 1, 1);
+               RandomSelection_Add(NULL, 2, string_null, 1, 1);
        if(t == 3 || TeamSmallerEqThanTeam(3, t, pl))
-               RandomSelection_Add(world, 3, string_null, 1, 1);
+               RandomSelection_Add(NULL, 3, string_null, 1, 1);
        if(t == 4 || TeamSmallerEqThanTeam(4, t, pl))
-               RandomSelection_Add(world, 4, string_null, 1, 1);
+               RandomSelection_Add(NULL, 4, string_null, 1, 1);
 
        return RandomSelection_chosen_float;
 }
@@ -559,8 +584,8 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
 }
 
 //void() ctf_playerchanged;
-void SV_ChangeTeam(float _color)
-{SELFPARAM();
+void SV_ChangeTeam(entity this, float _color)
+{
        float scolor, dcolor, steam, dteam; //, dbotcount, scount, dcount;
 
        // in normal deathmatch we can just apply the color and we're done
@@ -570,7 +595,7 @@ void SV_ChangeTeam(float _color)
        if(!IS_CLIENT(this))
        {
                // 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, this.netname);
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_CONNECTING, this.netname);
                return;
        }
 
@@ -693,9 +718,9 @@ void ShufflePlayerOutOfTeam (float source_team)
        else // if(source_team == 4)
                steam = NUM_TEAM_4;
 
-       lowest_bot = world;
+       lowest_bot = NULL;
        lowest_bot_score = 999999999;
-       lowest_player = world;
+       lowest_player = NULL;
        lowest_player_score = 999999999;
 
        // find the lowest-scoring player & bot of that team
@@ -719,7 +744,7 @@ void ShufflePlayerOutOfTeam (float source_team)
        ));
 
        // prefers to move a bot...
-       if(lowest_bot != world)
+       if(lowest_bot != NULL)
                selected = lowest_bot;
        // but it will move a player if it has to
        else