Skip to content

Commit

Permalink
bot_playercount appears to work as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
darkshade9 committed Sep 1, 2024
1 parent 049a064 commit 35dbfec
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/action/acesrc/bot_collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ qboolean BOTCOL_CanMoveSafely(edict_t *self, vec3_t angles)
// Calculate the distance between the bot's current position and the destination position
this_dist = sqrt(pow(dest2[0] - self->s.origin[0], 2) + pow(dest2[1] - self->s.origin[1], 2) + pow(dest2[2] - self->s.origin[2], 2));

gi.dprintf("Distance to destination: %f\n", this_dist);
if (bot_debug->value)
gi.dprintf("Distance to destination: %f\n", this_dist);
if( (trace.fraction == 1.0) // long drop!
|| (trace.contents & MASK_DEADLY) // avoid SLIME or LAVA
|| (this_dist > (NODE_MAX_FALL_HEIGHT * 3)) ) // avoid falling too far
Expand Down
4 changes: 2 additions & 2 deletions src/action/botlib/botlib_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ qboolean BOTLIB_SV_Cmds(void)
bot_connections.desire_bots = atoi(gi.argv(2)); // How many bots
bot_connections.auto_balance_bots = true;

if (bot_playercount->value > 0)
if (bot_playercount->value > 0 && !(gameSettings & GS_ROUNDBASED))
gi.dprintf("bot_playercount is set to %i, sv bots has no effect\n", (int)bot_playercount->value);

return true;
Expand Down Expand Up @@ -78,7 +78,7 @@ qboolean BOTLIB_SV_Cmds(void)
else if (teamplay->value)
gi.cprintf(NULL, PRINT_HIGH, "TP bots on T1[%d] T2[%d] Total[%d]\n", bot_connections.team1_bots, bot_connections.team2_bots, bot_connections.total_bots);

if (bot_playercount->value > 0) {
if (bot_playercount->value > 0 && !(gameSettings & GS_ROUNDBASED)) {
gi.cprintf(NULL, PRINT_HIGH, "**---------------------------**\n");
gi.cprintf(NULL, PRINT_HIGH, "bot_playercount is set to %i, sv bots has no effect\n", (int)bot_playercount->value);
}
Expand Down
68 changes: 43 additions & 25 deletions src/action/botlib/botlib_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,10 @@ void BOTLIB_CheckBotRules(void)
}

BOTLIB_GetTotalPlayers(&bot_connections);
//Com_Printf("%s hs[%d] ht1[%d] ht2[%d] ht3[%d] bs[%d] bt1[%d] bt2[%d] bt3[%d]\n", __func__, bot_connections.spec_humans, bot_connections.team1_humans, bot_connections.team2_humans, bot_connections.team3_humans, bot_connections.spec_bots, bot_connections.team1_bots, bot_connections.team2_bots, bot_connections.team3_bots);

// All bots are counted as being on team 1 if in DM mode

//gi.dprintf("%s hs[%d] ht1[%d] ht2[%d] ht3[%d] bs[%d] bt1[%d] bt2[%d] bt3[%d] tb[%d] th[%d]\n", __func__, bot_connections.spec_humans, bot_connections.team1_humans, bot_connections.team2_humans, bot_connections.team3_humans, bot_connections.spec_bots, bot_connections.team1_bots, bot_connections.team2_bots, bot_connections.team3_bots, bot_connections.total_bots, bot_connections.total_humans);

if (bot_connections.tried_adding_prev_bots == false)
{
Expand All @@ -1951,8 +1954,8 @@ void BOTLIB_CheckBotRules(void)
BOTLIB_GetTotalPlayers(&bot_connections); // Update connection stats
}

// Turn on team balance if bot_maxteam is used or use_balancer is enabled
if (bot_maxteam->value > 0 || use_balancer->value) bot_connections.auto_balance_bots = true;
// Turn on team balance if bot_maxteam is used
if (bot_maxteam->value > 0) bot_connections.auto_balance_bots = true;

// ========================================================================================================
// Manually add bots to a select team
Expand Down Expand Up @@ -2037,9 +2040,43 @@ void BOTLIB_CheckBotRules(void)
// ========================================================================================================


// Auto balance bots
if (bot_connections.auto_balance_bots == false)
return;
// Manage bot counts in DM mode
int bots_to_spawn = 0;
if (bot_playercount->value > 0 && (gameSettings & GS_DEATHMATCH)) {
// Calculate the desired number of bots based on bot_playercount and total_humans
bot_connections.desire_bots = (int)bot_playercount->value - bot_connections.total_humans;

// Ensure desire_bots does not exceed maxclients - total_humans
if (bot_connections.desire_bots + bot_connections.total_humans > maxclients->value) {
bot_connections.desire_bots = (int)(maxclients->value - bot_connections.total_humans);
}

// Sanity check - safety limits
if (bot_connections.desire_bots < 0) bot_connections.desire_bots = 0;
int bots_adj = 0;
int total_players = bot_connections.total_bots + bot_connections.total_humans;

if (total_players > bot_playercount->value) {
//gi.dprintf("I should remove a bot\n");
bots_adj = -1;
} else if (total_players < bot_playercount->value) {
// gi.dprintf("I should add a bot\n");
// gi.dprintf("total_players: %d, bot_playercount->value: %d\n", total_players, bot_playercount->value);
bots_adj = 1;
} else {
bots_to_spawn = (int)bot_playercount->value;
bot_connections.desire_bots = bots_to_spawn;
}

bots_to_spawn = bots_adj; // Set bots_to_spawn to +1 or -1 based on the adjustment needed
//gi.dprintf("bots_adj: %d\n", bots_to_spawn);
} else {
bots_to_spawn = bot_connections.desire_bots - bot_connections.total_bots;
}

// // Auto balance bots
// if (bot_connections.auto_balance_bots == false)
// return;


//bot_connections.desire_bots += (bot_connections.desire_team1 + bot_connections.desire_team2 + bot_connections.desire_team3);
Expand Down Expand Up @@ -2094,25 +2131,6 @@ void BOTLIB_CheckBotRules(void)

//int bots_to_spawn = abs(bot_connections.total_bots - bot_connections.desire_bots);

int bots_to_spawn = 0;

// Only proceed if bot_playercount is greater than 0
if (bot_playercount->value > 0) {
// Calculate the desired number of bots based on bot_playercount and total_humans
bot_connections.desire_bots = (int)bot_playercount->value - bot_connections.total_humans;

// Ensure desire_bots does not exceed maxclients - total_humans
if (bot_connections.desire_bots + bot_connections.total_humans > maxclients->value) {
bot_connections.desire_bots = (int)(maxclients->value - bot_connections.total_humans);
}

// Sanity check - safety limits
if (bot_connections.desire_bots < 0) bot_connections.desire_bots = 0;

bots_to_spawn = bot_connections.desire_bots - bot_connections.total_bots;
} else {
bots_to_spawn = bot_connections.desire_bots - bot_connections.total_bots;
}
// Shuffle bots around
if (teamplay->value && bot_connections.auto_balance_bots)
BOTLIB_TeamBotShuffle();
Expand Down
2 changes: 1 addition & 1 deletion src/action/g_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ cvar_t* bot_skill; // Skill setting for bots, range 0-10. 0 = easy, 10 = aimbot
cvar_t* bot_skill_threshold; // Dynamic skill adjustment kicks in if a threshold has been hit
cvar_t* bot_remember; // How long (in seconds) the bot remembers an enemy after visibility has been lost
cvar_t* bot_reaction; // How long (in seconds) until the bot reacts to an enemy in sight
cvar_t* bot_maxteam; // Max bots allowed in autoteam
cvar_t* bot_maxteam; // Max bots allowed in autoteam, default 10 (10 max bots per team)
cvar_t* bot_playercount; // Preferred number of total clients (bots + humans) on the server
cvar_t* bot_rush; // Bots rush players by going directly for them
cvar_t* bot_randvoice; // Bots use random user voice wavs - percentage [min: 0 max: 100]
Expand Down
2 changes: 1 addition & 1 deletion src/action/g_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ void InitGame( void )
bot_remember = gi.cvar("bot_remember", "15", 0); // How long (in seconds) the bot remembers an enemy after visibility has been lost
bot_reaction = gi.cvar("bot_reaction", "0.5", 0); // How long (in seconds) until the bot reacts to an enemy in sight
bot_showpath = gi.cvar("bot_showpath", "0", 0);
bot_maxteam = gi.cvar("bot_maxteam", "0", 0);
bot_maxteam = gi.cvar("bot_maxteam", "10", 0);
bot_playercount = gi.cvar("bot_playercount", "0", 0);
bot_rush = gi.cvar("bot_rush", "0", 0);
bot_randvoice = gi.cvar("bot_randvoice", "5", 0);
Expand Down

0 comments on commit 35dbfec

Please sign in to comment.