]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/bot.qc
Merge branch 'Mario/teams_bitflag' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / bot.qc
index 1b69658245781cc202cf826382145e21b6945f13..308cd95101ab09aa8ccb1203dcc6cc07af3e2504 100644 (file)
@@ -43,8 +43,8 @@ entity bot_spawn()
        {
                currentbots = currentbots + 1;
                bot_setnameandstuff(bot);
-               WITH(entity, self, bot, ClientConnect());
-               WITH(entity, self, bot, PutClientInServer());
+               ClientConnect(bot);
+               PutClientInServer(bot);
        }
        return bot;
 }
@@ -80,7 +80,7 @@ void bot_think(entity this)
 
        this.dmg_take = 0;
        this.dmg_save = 0;
-       this.dmg_inflictor = world;
+       this.dmg_inflictor = NULL;
 
        // calculate an aiming latency based on the skill setting
        // (simulated network latency + naturally delayed reflexes)
@@ -173,7 +173,7 @@ void bot_setnameandstuff(entity this)
                                        break;
                                }
                        ));
-                       RandomSelection_Add(world, 0, readfile, 1, prio);
+                       RandomSelection_Add(NULL, 0, readfile, 1, prio);
                }
                readfile = RandomSelection_chosen_string;
                fclose(file);
@@ -250,7 +250,7 @@ void bot_setnameandstuff(entity this)
        this.playermodel = this.playermodel_freeme = strzone(strcat("models/player/", bot_model));
        this.playerskin = this.playerskin_freeme = strzone(bot_skin);
 
-       this.cvar_cl_accuracy_data_share = 1;  // share the bots weapon accuracy data with the world
+       this.cvar_cl_accuracy_data_share = 1;  // share the bots weapon accuracy data with the NULL
        this.cvar_cl_accuracy_data_receive = 0;  // don't receive any weapon accuracy data
 }
 
@@ -346,31 +346,28 @@ void bot_endgame()
 
 void bot_relinkplayerlist()
 {
-       entity e;
-       entity prevbot;
        player_count = 0;
        currentbots = 0;
-       player_list = e = findchainflags(flags, FL_CLIENT);
-       bot_list = world;
-       prevbot = world;
-       while (e)
+       bot_list = NULL;
+
+       entity prevbot = NULL;
+       FOREACH_CLIENT(true,
        {
-               player_count = player_count + 1;
-               e.nextplayer = e.chain;
-               if (IS_BOT_CLIENT(e))
+               ++player_count;
+
+               if(IS_BOT_CLIENT(it))
                {
-                       if (prevbot)
-                               prevbot.nextbot = e;
+                       if(prevbot)
+                               prevbot.nextbot = it;
                        else
                        {
-                               bot_list = e;
-                               bot_list.nextbot = world;
+                               bot_list = it;
+                               bot_list.nextbot = NULL;
                        }
-                       prevbot = e;
-                       currentbots = currentbots + 1;
+                       prevbot = it;
+                       ++currentbots;
                }
-               e = e.chain;
-       }
+       });
        LOG_TRACE(strcat("relink: ", ftos(currentbots), " bots seen.\n"));
        bot_strategytoken = bot_list;
        bot_strategytoken_taken = true;
@@ -396,7 +393,7 @@ void bot_clientdisconnect(entity this)
        if(this.bot_cmd_current)
                remove(this.bot_cmd_current);
        if(bot_waypoint_queue_owner==this)
-               bot_waypoint_queue_owner = world;
+               bot_waypoint_queue_owner = NULL;
 }
 
 void bot_clientconnect(entity this)
@@ -427,70 +424,84 @@ void bot_clientconnect(entity this)
 
 void bot_removefromlargestteam()
 {
-       float besttime, bestcount, thiscount;
-       entity best, head;
-       CheckAllowedTeams(world);
-       GetTeamCounts(world);
-       head = findchainfloat(isbot, true);
-       if (!head)
-               return;
-       best = head;
-       besttime = head.createdtime;
-       bestcount = 0;
-       while (head)
+       CheckAllowedTeams(NULL);
+       GetTeamCounts(NULL);
+
+       entity best = NULL;
+       float besttime = 0;
+       int bestcount = 0;
+
+       int bcount = 0;
+       FOREACH_ENTITY_FLOAT(isbot, true,
        {
-               if(head.team == NUM_TEAM_1)
-                       thiscount = c1;
-               else if(head.team == NUM_TEAM_2)
-                       thiscount = c2;
-               else if(head.team == NUM_TEAM_3)
-                       thiscount = c3;
-               else if(head.team == NUM_TEAM_4)
-                       thiscount = c4;
-               else
-                       thiscount = 0;
-               if (thiscount > bestcount)
+               ++bcount;
+
+               if(!best)
+               {
+                       best = it;
+                       besttime = it.createdtime;
+               }
+
+               int thiscount = 0;
+
+               switch(it.team)
+               {
+                       case NUM_TEAM_1: thiscount = c1; break;
+                       case NUM_TEAM_2: thiscount = c2; break;
+                       case NUM_TEAM_3: thiscount = c3; break;
+                       case NUM_TEAM_4: thiscount = c4; break;
+               }
+
+               if(thiscount > bestcount)
                {
                        bestcount = thiscount;
-                       besttime = head.createdtime;
-                       best = head;
+                       besttime = it.createdtime;
+                       best = it;
                }
-               else if (thiscount == bestcount && besttime < head.createdtime)
+               else if(thiscount == bestcount && besttime < it.createdtime)
                {
-                       besttime = head.createdtime;
-                       best = head;
+                       besttime = it.createdtime;
+                       best = it;
                }
-               head = head.chain;
-       }
+       });
+       if(!bcount)
+               return; // no bots to remove
        currentbots = currentbots - 1;
        dropclient(best);
 }
 
 void bot_removenewest()
 {
-       float besttime;
-       entity best, head;
-
        if(teamplay)
        {
                bot_removefromlargestteam();
                return;
        }
 
-       head = findchainfloat(isbot, true);
-       if (!head)
-               return;
-       best = head;
-       besttime = head.createdtime;
-       while (head)
+       float besttime = 0;
+       entity best = NULL;
+       int bcount = 0;
+
+       FOREACH_ENTITY_FLOAT(isbot, true,
        {
-               if (besttime < head.createdtime)
+               ++bcount;
+
+               if(!best)
                {
-                       besttime = head.createdtime;
-                       best = head;
+                       best = it;
+                       besttime = it.createdtime;
                }
-               head = head.chain;
-       }
+
+               if(besttime < it.createdtime)
+               {
+                       besttime = it.createdtime;
+                       best = it;
+               }
+       });
+
+       if(!bcount)
+               return; // no bots to remove
+
        currentbots = currentbots - 1;
        dropclient(best);
 }
@@ -557,8 +568,8 @@ float bot_fixcount()
        int activerealplayers = 0;
        int realplayers = 0;
        if (MUTATOR_CALLHOOK(Bot_FixCount, activerealplayers, realplayers)) {
-               activerealplayers = bot_activerealplayers;
-               realplayers = bot_realplayers;
+               activerealplayers = M_ARGV(0, int);
+               realplayers = M_ARGV(1, int);
        } else {
                FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
                        if(IS_PLAYER(it))
@@ -573,7 +584,7 @@ float bot_fixcount()
        // But don't remove bots immediately on level change, as the real players
        // usually haven't rejoined yet
        bots_would_leave = false;
-       if (teamplay && autocvar_bot_vs_human && (c3==-1 && c4==-1))
+       if (teamplay && autocvar_bot_vs_human && AvailableTeams() == 2)
                bots = min(ceil(fabs(autocvar_bot_vs_human) * activerealplayers), maxclients - realplayers);
        else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
        {
@@ -601,7 +612,7 @@ float bot_fixcount()
                //dprint(ftos(bots), " ? ", ftos(currentbots), "\n");
                while (currentbots < bots)
                {
-                       if (bot_spawn() == world)
+                       if (bot_spawn() == NULL)
                        {
                                bprint("Can not add bot, server full.\n");
                                return false;
@@ -659,9 +670,11 @@ void bot_serverframe()
                else
                {
                        // TODO: Make this check cleaner
-                       entity wp = findchain(classname, "waypoint");
-                       if(time - wp.nextthink > 10)
+                       IL_EACH(g_waypoints, time - it.nextthink > 10,
+                       {
                                waypoint_save_links();
+                               break;
+                       });
                }
        }
        else