]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
cmd setbots: add more than one bot at once.
authorRudolf Polzer <divVerent@gmail.com>
Tue, 1 Mar 2022 03:31:54 +0000 (22:31 -0500)
committerRudolf Polzer <divVerent@gmail.com>
Tue, 1 Mar 2022 03:31:54 +0000 (22:31 -0500)
We now have logic to normally only add one bot per frame. This is all nice,
but breaks the Xonotic Bot Orchestra.

So, let's make it so that the XBO has special privileges to spawn more than
one bot per frame; in normal gameplay bot spawns remain spaced out.

qcsrc/server/bot/api.qh
qcsrc/server/bot/default/bot.qc
qcsrc/server/bot/default/bot.qh
qcsrc/server/bot/null/bot_null.qc
qcsrc/server/command/sv_cmd.qc

index 0759d46365f14e65d9e227fb17b18468f6d5c42c..65ab46bad95a642a76c9c7e981994fe1bfb4627d 100644 (file)
@@ -70,7 +70,7 @@ void bot_clientconnect(entity this);
 void bot_clientdisconnect(entity this);
 void bot_cmdhelp(string scmd);
 void bot_endgame();
-bool bot_fixcount();
+bool bot_fixcount(bool multiple_per_frame);
 void bot_list_commands();
 void bot_queuecommand(entity bot, string cmdstring);
 void bot_relinkplayerlist();
index f487ca4c9fd75fcc0c38b755aecb882d89aa84cf..79f939196debf87b07d548e39ca96870261b2e0e 100644 (file)
@@ -588,7 +588,7 @@ void bot_calculate_stepheightvec()
        jumpheight_time = autocvar_sv_jumpvelocity / autocvar_sv_gravity;
 }
 
-bool bot_fixcount()
+bool bot_fixcount(bool multiple_per_frame)
 {
        int activerealplayers = 0;
        int realplayers = 0;
@@ -636,13 +636,17 @@ bool bot_fixcount()
        // only add one bot per frame to avoid utter chaos
        if(time > botframe_nextthink)
        {
-               if (currentbots < bots)
+               while (currentbots < bots)
                {
                        if (bot_spawn() == NULL)
                        {
                                bprint("Can not add bot, server full.\n");
                                return false;
                        }
+                       if (!multiple_per_frame)
+                       {
+                               break;
+                       }
                }
                while (currentbots > bots && bots >= 0)
                        bot_removenewest();
@@ -713,7 +717,7 @@ void bot_serverframe()
 
        if(time > botframe_nextthink)
        {
-               if(!bot_fixcount())
+               if(!bot_fixcount(false))
                        botframe_nextthink = time + 10;
        }
 
index 618a766b8098aad90ce59c1b07acc76e1f5b5c21..74f7e0fa944e67d3ef270b0709b2db7548993463 100644 (file)
@@ -90,7 +90,7 @@ int _content_type;
  */
 
 entity bot_spawn();
-bool bot_fixcount();
+bool bot_fixcount(bool multiple_per_frame);
 
 void bot_think(entity this);
 void bot_setnameandstuff(entity this);
index a7f8e99f1d7cb7bdc9c9cc6780aae9f5d4fd4883..a27e00c42a24a386f372758bd2ca5ea9e23727c5 100644 (file)
@@ -6,7 +6,7 @@ void bot_clientconnect(entity this) { }
 void bot_clientdisconnect(entity this) { }
 void bot_cmdhelp(string scmd) { }
 void bot_endgame() { }
-bool bot_fixcount() { return true; }
+bool bot_fixcount(bool multiple_per_frame) { return true; }
 void bot_list_commands() { }
 void bot_queuecommand(entity bot, string cmdstring) { }
 void bot_relinkplayerlist() { }
index e09458f79a1ab1590a7186a14cadf1fbc1c343fe..b35f4fb53ae4e6ad52687a964a8782a58889d701 100644 (file)
@@ -333,9 +333,9 @@ void GameCommand_bot_cmd(int request, int argc, string command)
                                cvar_settemp("minplayers", "0");
                                cvar_settemp("minplayers_per_team", "0");
                                cvar_settemp("bot_number", "0");
-                               bot_fixcount();
+                               bot_fixcount(false);  // Kill all bots.
                                cvar_settemp("bot_number", argv(2));
-                               if (!bot_fixcount()) LOG_INFO("Sorry, could not set requested bot count");
+                               if (!bot_fixcount(true)) LOG_INFO("Sorry, could not set requested bot count");
                                return;
                        }
                        else if (argv(1) == "load" && argc == 3)
@@ -366,9 +366,9 @@ void GameCommand_bot_cmd(int request, int argc, string command)
                                                        cvar_settemp("minplayers", "0");
                                                        cvar_settemp("minplayers_per_team", "0");
                                                        cvar_settemp("bot_number", "0");
-                                                       bot_fixcount();
+                                                       bot_fixcount(false);  // Kill all bots.
                                                        cvar_settemp("bot_number", argv(3));
-                                                       if (!bot_fixcount()) LOG_INFO("Sorry, could not set requested bot count");
+                                                       if (!bot_fixcount(true)) LOG_INFO("Sorry, could not set requested bot count");
                                                }
                                                else
                                                {
@@ -1225,7 +1225,7 @@ void GameCommand_setbots(int request, int argc)
                                cvar_settemp("minplayers", "0");
                                cvar_settemp("minplayers_per_team", "0");
                                cvar_settemp("bot_number", argv(1));
-                               bot_fixcount();
+                               bot_fixcount(true);
                                return;
                        }
                }