From 5aad31dab6d60f39ad77a5759b214d7d1a595173 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 14 Jan 2024 04:54:00 +0200 Subject: [PATCH 01/11] remove state changing to BOT_IDLE on bot thinking --- dlls/bot/bot.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/dlls/bot/bot.cpp b/dlls/bot/bot.cpp index 90f0ddd2d4..188dc99710 100644 --- a/dlls/bot/bot.cpp +++ b/dlls/bot/bot.cpp @@ -251,7 +251,7 @@ void BotCreate(const char *skin, const char *name, const char *skill) for (j = i; j < length; j++) // shuffle chars left (and null) c_name[j] = c_name[j+1]; length--; - } + } } skill_level = 0; @@ -577,7 +577,7 @@ float CBot::BotChangeYaw( float speed ) // turn from the current v_angle yaw to the ideal_yaw by selecting // the quickest way to turn to face that direction - + current = pev->v_angle.y; ideal = pev->ideal_yaw; @@ -1768,7 +1768,7 @@ void CBot::BotThink( void ) pev->deadflag = DEAD_DEAD; // make the kicked bot be dead bot_respawn[respawn_index].is_used = FALSE; // this slot is now free - bot_respawn[respawn_index].state = BOT_IDLE; + respawn_index = -1; // indicate no slot used // fall through to next if statement (respawn_index will be -1) @@ -1985,7 +1985,7 @@ void CBot::BotThink( void ) { // if there was a wall on the left over 1/2 a second ago then // 20% of the time randomly turn between 45 and 60 degrees - + if ((f_wall_on_left != 0) && (f_wall_on_left <= gpGlobals->time - 0.5) && (RANDOM_LONG(1, 100) <= 20)) @@ -2045,7 +2045,7 @@ void CBot::BotThink( void ) else if ((moved_distance <= 1) && (!bot_was_paused)) { // the bot must be stuck! - + if (BotCanJumpUp( )) // can the bot jump onto something? { pev->button |= IN_JUMP; // jump up and move forward @@ -2106,4 +2106,3 @@ void CBot::BotThink( void ) gpGlobals->frametime * 1000 ); // TheFatal - END } - From caccdd942c1f2ccb2c35161265cbd84f17eeed6b Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 14 Jan 2024 04:54:46 +0200 Subject: [PATCH 02/11] fix respawn state check --- dlls/client.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index 4dea7ce8eb..358a989a5e 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -127,7 +127,7 @@ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddres sprintf( cmd, "kick \"%s\"\n", bot_respawn[i].name ); - bot_respawn[i].state = BOT_IDLE; + bot_respawn[i].state = BOT_NEED_TO_RESPAWN; SERVER_COMMAND( cmd ); // kick the bot using (kick "name") break; @@ -1372,8 +1372,11 @@ void StartFrame( void ) { for( i = 0; i < 32; i++ ) { - if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_IDLE) + if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_NEED_TO_RESPAWN) { + bot_respawn[index].state = BOT_IS_RESPAWNING; + bot_respawn[index].is_used = FALSE; // free up this slot + BotCreate( bot_respawn[i].skin, bot_respawn[i].name, bot_respawn[i].skill ); break; } From fa7f7cc729841494cda439753a1f36042afa5983 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 14 Jan 2024 06:51:21 +0200 Subject: [PATCH 03/11] fix index name --- dlls/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index 358a989a5e..3e8897aee8 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1374,8 +1374,8 @@ void StartFrame( void ) { if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_NEED_TO_RESPAWN) { - bot_respawn[index].state = BOT_IS_RESPAWNING; - bot_respawn[index].is_used = FALSE; // free up this slot + bot_respawn[i].state = BOT_IS_RESPAWNING; + bot_respawn[i].is_used = FALSE; // free up this slot BotCreate( bot_respawn[i].skin, bot_respawn[i].name, bot_respawn[i].skill ); break; From c9c01c7da7e8d71e1be02c855489d544b0e4956e Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 14 Jan 2024 07:24:14 +0200 Subject: [PATCH 04/11] add respawn delay to prevent server crash --- dlls/client.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index 3e8897aee8..11fe195dcf 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1372,12 +1372,16 @@ void StartFrame( void ) { for( i = 0; i < 32; i++ ) { - if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_NEED_TO_RESPAWN) + if( !bot_respawn[i].is_used && + bot_respawn[i].state == BOT_NEED_TO_RESPAWN && + gpGlobals->time >= respawn_time) { bot_respawn[i].state = BOT_IS_RESPAWNING; bot_respawn[i].is_used = FALSE; // free up this slot BotCreate( bot_respawn[i].skin, bot_respawn[i].name, bot_respawn[i].skill ); + + respawn_time = gpGlobals->time + 1.0; // set next respawn time (to prevent server crash) break; } } From 281f0241f639422768972998df05df64ee5cf536 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 14 Jan 2024 20:27:43 +0200 Subject: [PATCH 05/11] add players count condition --- dlls/client.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index 11fe195dcf..f093253824 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1024,6 +1024,9 @@ void StartFrame( void ) // END BOT // START BOT + int count = 0; + + // count total players if( ( g_fGameOver ) && ( respawn_time < 1.0 ) ) { // if the game is over (time/frag limit) set the respawn time... @@ -1037,13 +1040,15 @@ void StartFrame( void ) if( !pPlayer ) continue; // if invalid then continue with next index... - if( pPlayer->pBotCam ) + if( pPlayer->pBotCam ) // check if any players are using the botcam... pPlayer->pBotCam->Disconnect(); + + count++; // count the number of bots and players } } // check if a map was changed via "map" without kicking bots... - if( previous_time > gpGlobals->time ) + if( ( count < max_bots ) && ( previous_time > gpGlobals->time ) ) { bot_check_time = gpGlobals->time + 10.0; From 13bc2b0a497655b80309551031ae1005805d147d Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 15 Jan 2024 01:45:42 +0200 Subject: [PATCH 06/11] fix players online counter, make optimization --- dlls/client.cpp | 84 +++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 59 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index f093253824..aba4047227 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -127,6 +127,7 @@ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddres sprintf( cmd, "kick \"%s\"\n", bot_respawn[i].name ); + bot_respawn[i].is_used = FALSE; bot_respawn[i].state = BOT_NEED_TO_RESPAWN; SERVER_COMMAND( cmd ); // kick the bot using (kick "name") @@ -1000,6 +1001,7 @@ void StartFrame( void ) static float respawn_time = 0; static float previous_time = 0.0; char msg[120]; + int online = 0; // END BOT // START BOT - thanks Jehannum! @@ -1012,6 +1014,9 @@ void StartFrame( void ) if( !pPlayer ) // if invalid then continue with next index... continue; + if( pPlayer->pev->takedamage == DAMAGE_NO ) + continue; // solution to detect player not in the game + // check if this is a FAKECLIENT (i.e. is it a bot?) if( FBitSet( pPlayer->pev->flags, FL_FAKECLIENT ) ) { @@ -1020,19 +1025,20 @@ void StartFrame( void ) // call the think function for the bot... pBot->BotThink(); } + + // increase online of bots and players + online++; } // END BOT // START BOT - int count = 0; - // count total players + // check if any players are using the botcam... if( ( g_fGameOver ) && ( respawn_time < 1.0 ) ) { // if the game is over (time/frag limit) set the respawn time... respawn_time = 5.0; - // check if any players are using the botcam... for( i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i ); @@ -1040,15 +1046,13 @@ void StartFrame( void ) if( !pPlayer ) continue; // if invalid then continue with next index... - if( pPlayer->pBotCam ) // check if any players are using the botcam... + if( pPlayer->pBotCam ) pPlayer->pBotCam->Disconnect(); - - count++; // count the number of bots and players } } // check if a map was changed via "map" without kicking bots... - if( ( count < max_bots ) && ( previous_time > gpGlobals->time ) ) + if( previous_time > gpGlobals->time ) { bot_check_time = gpGlobals->time + 10.0; @@ -1066,38 +1070,6 @@ void StartFrame( void ) } } - // is new game started and time to respawn bots yet? - if( ( !g_fGameOver ) && ( respawn_time > 1.0 ) && - ( gpGlobals->time >= respawn_time ) ) - { - int index = 0; - bot_check_time = gpGlobals->time + 5.0; - - // find bot needing to be respawned... - while( ( index < 32 ) && - ( bot_respawn[index].state != BOT_NEED_TO_RESPAWN ) ) - index++; - - if( index < 32 ) - { - bot_respawn[index].state = BOT_IS_RESPAWNING; - bot_respawn[index].is_used = FALSE; // free up this slot - - // respawn 1 bot then wait a while (otherwise engine crashes) - BotCreate( bot_respawn[index].skin, - bot_respawn[index].name, - bot_respawn[index].skill ); - - respawn_time = gpGlobals->time + 1.0; // set next respawn time - } - else - { - respawn_time = 0.0; - } - } - // END BOT - //ALERT( at_console, "SV_Physics( %g, frametime %g )\n", gpGlobals->time, gpGlobals->frametime ); - if( g_pGameRules ) { g_pGameRules->Think(); @@ -1197,6 +1169,9 @@ void StartFrame( void ) { BotCreate( arg1, arg2, arg3 ); + // increase online of bots and players + online++; + // have to delay here or engine gives "Tried to write to // uninitialized sizebuf_t" error and crashes... pause_time = gpGlobals->time + 1; @@ -1314,6 +1289,9 @@ void StartFrame( void ) printf( "adding new bot...\n" ); BotCreate( arg1, arg2, arg3 ); + + // increase online of bots and players + online++; } else if( strcmp( cmd, "botskill" ) == 0 ) { @@ -1354,43 +1332,31 @@ void StartFrame( void ) // check if time to see if a bot needs to be created... if( bot_check_time < gpGlobals->time ) { - int count = 0; - - bot_check_time = gpGlobals->time + 5.0; - - for( i = 1; i <= gpGlobals->maxClients; i++ ) - { - CBaseEntity *pPlayer = UTIL_PlayerByIndex( i ); - - if( !pPlayer ) - continue; // if invalid then continue with next index... - - if( pPlayer->pev->takedamage == DAMAGE_NO ) - continue; // if bot was kicked, don't count as a player... - - count++; // count the number of bots and players - } - // if there are currently less than the maximum number of "players" // then add another bot using the default skill level... - if( count < max_bots ) + if ( online < max_bots ) { for( i = 0; i < 32; i++ ) { if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_NEED_TO_RESPAWN && - gpGlobals->time >= respawn_time) + gpGlobals->time >= respawn_time ) { + bot_respawn[i].is_used = TRUE; bot_respawn[i].state = BOT_IS_RESPAWNING; - bot_respawn[i].is_used = FALSE; // free up this slot BotCreate( bot_respawn[i].skin, bot_respawn[i].name, bot_respawn[i].skill ); + online++; // increase online of bots and players + respawn_time = gpGlobals->time + 1.0; // set next respawn time (to prevent server crash) + break; } } } + + bot_check_time = gpGlobals->time + 10.0; } previous_time = gpGlobals->time; // keep track of last time in StartFrame() From e4b15dd1e89b8163bfc253f5a766e66deff2decc Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 15 Jan 2024 08:07:51 +0200 Subject: [PATCH 07/11] fix bot meta on initial spawn --- dlls/bot/bot.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dlls/bot/bot.cpp b/dlls/bot/bot.cpp index 188dc99710..19b76dd3a2 100644 --- a/dlls/bot/bot.cpp +++ b/dlls/bot/bot.cpp @@ -337,7 +337,8 @@ void CBot::Spawn( ) // get the bot's name and save it in respawn array... strcpy(bot_respawn[respawn_index].name, STRING(pev->netname)); - bot_respawn[respawn_index].state = BOT_IDLE; + bot_respawn[respawn_index].is_used = TRUE; + bot_respawn[respawn_index].state = BOT_IS_RESPAWNING; pev->ideal_yaw = pev->v_angle.y; pev->yaw_speed = BOT_YAW_SPEED; From c7420cfc3ef3ec266deb9024c45c0ff6271977cd Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 15 Jan 2024 08:09:40 +0200 Subject: [PATCH 08/11] fix bots quantity on map rotate, add respawn initiation --- dlls/client.cpp | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index aba4047227..09cfc82157 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1054,18 +1054,17 @@ void StartFrame( void ) // check if a map was changed via "map" without kicking bots... if( previous_time > gpGlobals->time ) { + respawn_time = 5.0; + bot_check_time = gpGlobals->time + 10.0; - for( index = 0; index < 32; index++ ) + // find bots used in previous session and add them to respawn queue + for( i = 0; i < 32; i++ ) { - if( ( bot_respawn[index].is_used) && // is this slot used? - ( bot_respawn[index].state != BOT_NEED_TO_RESPAWN ) ) + if( bot_respawn[i].is_used ) { - // bot has already been "kicked" by server so just set flag - bot_respawn[index].state = BOT_NEED_TO_RESPAWN; - - // if the map was changed set the respawn time... - respawn_time = 5.0; + bot_respawn[i].is_used = FALSE; + bot_respawn[i].state = BOT_NEED_TO_RESPAWN; } } } @@ -1330,29 +1329,19 @@ void StartFrame( void ) // START BOT // check if time to see if a bot needs to be created... - if( bot_check_time < gpGlobals->time ) + if( online < max_bots && bot_check_time < gpGlobals->time && respawn_time <= gpGlobals->time ) { - // if there are currently less than the maximum number of "players" - // then add another bot using the default skill level... - if ( online < max_bots ) + for( i = 0; i < 32; i++ ) { - for( i = 0; i < 32; i++ ) + if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_NEED_TO_RESPAWN ) { - if( !bot_respawn[i].is_used && - bot_respawn[i].state == BOT_NEED_TO_RESPAWN && - gpGlobals->time >= respawn_time ) - { - bot_respawn[i].is_used = TRUE; - bot_respawn[i].state = BOT_IS_RESPAWNING; - - BotCreate( bot_respawn[i].skin, bot_respawn[i].name, bot_respawn[i].skill ); + BotCreate( bot_respawn[i].skin, bot_respawn[i].name, bot_respawn[i].skill ); - online++; // increase online of bots and players + online++; // increase online of bots and players - respawn_time = gpGlobals->time + 1.0; // set next respawn time (to prevent server crash) + respawn_time = gpGlobals->time + 1.0; // set next respawn time (to prevent server crash) - break; - } + break; } } From ebb2b9bcbe9033e18d07b2fdfc0ec0ec9219494a Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 16 Jan 2024 19:10:00 +0200 Subject: [PATCH 09/11] group constructions --- dlls/client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index 09cfc82157..6b1252438f 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -127,10 +127,11 @@ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddres sprintf( cmd, "kick \"%s\"\n", bot_respawn[i].name ); + SERVER_COMMAND( cmd ); // kick the bot using (kick "name") + bot_respawn[i].is_used = FALSE; bot_respawn[i].state = BOT_NEED_TO_RESPAWN; - SERVER_COMMAND( cmd ); // kick the bot using (kick "name") break; } } From 7e45ded64dd54f73ef2de9bf96438b2bb526404e Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 16 Jan 2024 21:36:35 +0200 Subject: [PATCH 10/11] add BOT_IS_RESPAWNING state on BotCreate --- dlls/bot/bot.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dlls/bot/bot.cpp b/dlls/bot/bot.cpp index 19b76dd3a2..83962c2270 100644 --- a/dlls/bot/bot.cpp +++ b/dlls/bot/bot.cpp @@ -294,6 +294,7 @@ void BotCreate(const char *skin, const char *name, const char *skill) sprintf(c_index, "%d", index); bot_respawn[index].is_used = TRUE; // this slot is used + bot_respawn[index].state = BOT_IS_RESPAWNING; // don't store the name here, it might change if same as another strcpy(bot_respawn[index].skin, c_skin); From 8ae4c9bea6d4b73013036de5c12b518fe59c36f8 Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 16 Jan 2024 21:39:32 +0200 Subject: [PATCH 11/11] remove is_used status update --- dlls/bot/bot.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/dlls/bot/bot.cpp b/dlls/bot/bot.cpp index 83962c2270..c6e363b8d3 100644 --- a/dlls/bot/bot.cpp +++ b/dlls/bot/bot.cpp @@ -1769,8 +1769,6 @@ void CBot::BotThink( void ) pev->health = 0; pev->deadflag = DEAD_DEAD; // make the kicked bot be dead - bot_respawn[respawn_index].is_used = FALSE; // this slot is now free - respawn_index = -1; // indicate no slot used // fall through to next if statement (respawn_index will be -1)