From 1ff9406153bdff3668432a1c9a89bee04fda5381 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Mon, 28 Feb 2022 22:31:54 -0500 Subject: [PATCH] cmd setbots: add more than one bot at once. 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 | 2 +- qcsrc/server/bot/default/bot.qc | 10 +++++++--- qcsrc/server/bot/default/bot.qh | 2 +- qcsrc/server/bot/null/bot_null.qc | 2 +- qcsrc/server/command/sv_cmd.qc | 10 +++++----- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/qcsrc/server/bot/api.qh b/qcsrc/server/bot/api.qh index 0759d4636..65ab46bad 100644 --- a/qcsrc/server/bot/api.qh +++ b/qcsrc/server/bot/api.qh @@ -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(); diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index f487ca4c9..79f939196 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -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; } diff --git a/qcsrc/server/bot/default/bot.qh b/qcsrc/server/bot/default/bot.qh index 618a766b8..74f7e0fa9 100644 --- a/qcsrc/server/bot/default/bot.qh +++ b/qcsrc/server/bot/default/bot.qh @@ -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); diff --git a/qcsrc/server/bot/null/bot_null.qc b/qcsrc/server/bot/null/bot_null.qc index a7f8e99f1..a27e00c42 100644 --- a/qcsrc/server/bot/null/bot_null.qc +++ b/qcsrc/server/bot/null/bot_null.qc @@ -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() { } diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index e09458f79..b35f4fb53 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -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; } } -- 2.39.2