This commit is contained in:
d47081 2024-04-02 20:27:54 +03:00 committed by GitHub
commit 94a40fe3a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 78 deletions

View File

@ -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) for (j = i; j < length; j++) // shuffle chars left (and null)
c_name[j] = c_name[j+1]; c_name[j] = c_name[j+1];
length--; length--;
} }
} }
skill_level = 0; skill_level = 0;
@ -294,6 +294,7 @@ void BotCreate(const char *skin, const char *name, const char *skill)
sprintf(c_index, "%d", index); sprintf(c_index, "%d", index);
bot_respawn[index].is_used = TRUE; // this slot is used 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 // don't store the name here, it might change if same as another
strcpy(bot_respawn[index].skin, c_skin); strcpy(bot_respawn[index].skin, c_skin);
@ -337,7 +338,8 @@ void CBot::Spawn( )
// get the bot's name and save it in respawn array... // get the bot's name and save it in respawn array...
strcpy(bot_respawn[respawn_index].name, STRING(pev->netname)); 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->ideal_yaw = pev->v_angle.y;
pev->yaw_speed = BOT_YAW_SPEED; pev->yaw_speed = BOT_YAW_SPEED;
@ -577,7 +579,7 @@ float CBot::BotChangeYaw( float speed )
// turn from the current v_angle yaw to the ideal_yaw by selecting // turn from the current v_angle yaw to the ideal_yaw by selecting
// the quickest way to turn to face that direction // the quickest way to turn to face that direction
current = pev->v_angle.y; current = pev->v_angle.y;
ideal = pev->ideal_yaw; ideal = pev->ideal_yaw;
@ -1767,8 +1769,6 @@ void CBot::BotThink( void )
pev->health = 0; pev->health = 0;
pev->deadflag = DEAD_DEAD; // make the kicked bot be dead 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 respawn_index = -1; // indicate no slot used
// fall through to next if statement (respawn_index will be -1) // 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 // 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 // 20% of the time randomly turn between 45 and 60 degrees
if ((f_wall_on_left != 0) && if ((f_wall_on_left != 0) &&
(f_wall_on_left <= gpGlobals->time - 0.5) && (f_wall_on_left <= gpGlobals->time - 0.5) &&
(RANDOM_LONG(1, 100) <= 20)) (RANDOM_LONG(1, 100) <= 20))
@ -2045,7 +2045,7 @@ void CBot::BotThink( void )
else if ((moved_distance <= 1) && (!bot_was_paused)) else if ((moved_distance <= 1) && (!bot_was_paused))
{ {
// the bot must be stuck! // the bot must be stuck!
if (BotCanJumpUp( )) // can the bot jump onto something? if (BotCanJumpUp( )) // can the bot jump onto something?
{ {
pev->button |= IN_JUMP; // jump up and move forward pev->button |= IN_JUMP; // jump up and move forward
@ -2106,4 +2106,3 @@ void CBot::BotThink( void )
gpGlobals->frametime * 1000 ); gpGlobals->frametime * 1000 );
// TheFatal - END // TheFatal - END
} }

View File

@ -123,9 +123,11 @@ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddres
sprintf( cmd, "kick \"%s\"\n", bot_respawn[i].name ); sprintf( cmd, "kick \"%s\"\n", bot_respawn[i].name );
bot_respawn[i].state = BOT_IDLE;
SERVER_COMMAND( cmd ); // kick the bot using (kick "name") SERVER_COMMAND( cmd ); // kick the bot using (kick "name")
bot_respawn[i].is_used = FALSE;
bot_respawn[i].state = BOT_NEED_TO_RESPAWN;
break; break;
} }
} }
@ -997,6 +999,7 @@ void StartFrame( void )
static float respawn_time = 0; static float respawn_time = 0;
static float previous_time = 0.0; static float previous_time = 0.0;
char msg[120]; char msg[120];
int online = 0;
// END BOT // END BOT
// START BOT - thanks Jehannum! // START BOT - thanks Jehannum!
@ -1009,6 +1012,9 @@ void StartFrame( void )
if( !pPlayer ) // if invalid then continue with next index... if( !pPlayer ) // if invalid then continue with next index...
continue; 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?) // check if this is a FAKECLIENT (i.e. is it a bot?)
if( FBitSet( pPlayer->pev->flags, FL_FAKECLIENT ) ) if( FBitSet( pPlayer->pev->flags, FL_FAKECLIENT ) )
{ {
@ -1017,16 +1023,20 @@ void StartFrame( void )
// call the think function for the bot... // call the think function for the bot...
pBot->BotThink(); pBot->BotThink();
} }
// increase online of bots and players
online++;
} }
// END BOT // END BOT
// START BOT // START BOT
// check if any players are using the botcam...
if( ( g_fGameOver ) && ( respawn_time < 1.0 ) ) if( ( g_fGameOver ) && ( respawn_time < 1.0 ) )
{ {
// if the game is over (time/frag limit) set the respawn time... // if the game is over (time/frag limit) set the respawn time...
respawn_time = 5.0; respawn_time = 5.0;
// check if any players are using the botcam...
for( i = 1; i <= gpGlobals->maxClients; i++ ) for( i = 1; i <= gpGlobals->maxClients; i++ )
{ {
CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i ); CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i );
@ -1042,54 +1052,21 @@ void StartFrame( void )
// check if a map was changed via "map" without kicking bots... // check if a map was changed via "map" without kicking bots...
if( previous_time > gpGlobals->time ) if( previous_time > gpGlobals->time )
{ {
respawn_time = 5.0;
bot_check_time = gpGlobals->time + 10.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? if( bot_respawn[i].is_used )
( bot_respawn[index].state != BOT_NEED_TO_RESPAWN ) )
{ {
// bot has already been "kicked" by server so just set flag bot_respawn[i].is_used = FALSE;
bot_respawn[index].state = BOT_NEED_TO_RESPAWN; bot_respawn[i].state = BOT_NEED_TO_RESPAWN;
// if the map was changed set the respawn time...
respawn_time = 5.0;
} }
} }
} }
// 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 ) if( g_pGameRules )
{ {
g_pGameRules->Think(); g_pGameRules->Think();
@ -1189,6 +1166,9 @@ void StartFrame( void )
{ {
BotCreate( arg1, arg2, arg3 ); BotCreate( arg1, arg2, arg3 );
// increase online of bots and players
online++;
// have to delay here or engine gives "Tried to write to // have to delay here or engine gives "Tried to write to
// uninitialized sizebuf_t" error and crashes... // uninitialized sizebuf_t" error and crashes...
pause_time = gpGlobals->time + 1; pause_time = gpGlobals->time + 1;
@ -1306,6 +1286,9 @@ void StartFrame( void )
printf( "adding new bot...\n" ); printf( "adding new bot...\n" );
BotCreate( arg1, arg2, arg3 ); BotCreate( arg1, arg2, arg3 );
// increase online of bots and players
online++;
} }
else if( strcmp( cmd, "botskill" ) == 0 ) else if( strcmp( cmd, "botskill" ) == 0 )
{ {
@ -1344,38 +1327,23 @@ void StartFrame( void )
// START BOT // START BOT
// check if time to see if a bot needs to be created... // 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 )
{ {
int count = 0; for( i = 0; i < 32; i++ )
bot_check_time = gpGlobals->time + 5.0;
for( i = 1; i <= gpGlobals->maxClients; i++ )
{ {
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i ); if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_NEED_TO_RESPAWN )
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 )
{
for( i = 0; i < 32; i++ )
{ {
if( !bot_respawn[i].is_used && bot_respawn[i].state == BOT_IDLE) 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
break;
} 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() previous_time = gpGlobals->time; // keep track of last time in StartFrame()