Prep for bot chatt

This commit is contained in:
ineed bots 2022-04-20 12:51:39 -06:00
parent 774e8c0987
commit 4236e83079
3 changed files with 115 additions and 18 deletions

View File

@ -71,6 +71,12 @@ init()
if ( getCvar( "bots_skill_allies_med" ) == "" ) if ( getCvar( "bots_skill_allies_med" ) == "" )
setCvar( "bots_skill_allies_med", 0 ); setCvar( "bots_skill_allies_med", 0 );
if ( getCvar( "bots_skill_min" ) == "" )
setCvar( "bots_skill_min", 1 );
if ( getCvar( "bots_skill_max" ) == "" )
setCvar( "bots_skill_max", 7 );
if ( getCvar( "bots_loadout_rank" ) == "" ) // what rank the bots should be around, -1 is around the players, 0 is all random if ( getCvar( "bots_loadout_rank" ) == "" ) // what rank the bots should be around, -1 is around the players, 0 is all random
setCvar( "bots_loadout_rank", -1 ); setCvar( "bots_loadout_rank", -1 );
@ -474,6 +480,26 @@ connected()
self thread onDisconnect(); self thread onDisconnect();
level notify( "bot_connected", self ); level notify( "bot_connected", self );
self thread watchBotDebugEvent();
}
/*
DEBUG
*/
watchBotDebugEvent()
{
self endon( "disconnect" );
for ( ;; )
{
self waittill( "bot_event", msg, str, b, c, d, e, f, g );
if ( msg == "debug" && GetCvarInt( "bots_main_debug" ) )
{
print( "Bot Warfare debug: " + self.name + ": " + str );
}
}
} }
/* /*
@ -578,6 +604,20 @@ diffBots_loop()
player.pers["bots"]["skill"]["base"] = var_skill; player.pers["bots"]["skill"]["base"] = var_skill;
} }
} }
playercount = level.players.size;
min_diff = GetCvarInt( "bots_skill_min" );
max_diff = GetCvarInt( "bots_skill_max" );
for ( i = 0; i < playercount; i++ )
{
player = level.players[i];
if ( !player is_bot() )
continue;
player.pers["bots"]["skill"]["base"] = int( clamp( player.pers["bots"]["skill"]["base"], min_diff, max_diff ) );
}
} }
/* /*

View File

@ -1605,6 +1605,7 @@ doWalkScriptNotify()
*/ */
doWalk( goal, dist, isScriptGoal ) doWalk( goal, dist, isScriptGoal )
{ {
level endon ( "game_ended" );
self endon( "kill_goal" ); self endon( "kill_goal" );
self endon( "goal_internal" ); //so that the watchOnGoal notify can happen same frame, not a frame later self endon( "goal_internal" ); //so that the watchOnGoal notify can happen same frame, not a frame later
@ -1697,6 +1698,8 @@ movetowards( goal )
randomDir = self getRandomLargestStafe( stucks ); randomDir = self getRandomLargestStafe( stucks );
self BotNotifyBotEvent( "stuck" );
self botMoveTo( randomDir ); self botMoveTo( randomDir );
wait stucks; wait stucks;
self stand(); self stand();
@ -1721,7 +1724,7 @@ movetowards( goal )
if ( distanceSquared( self.origin, lastOri ) < 32 * 32 ) if ( distanceSquared( self.origin, lastOri ) < 32 * 32 )
{ {
// check if directly above or below // check if directly above or below
if ( abs( goal[2] - self.origin[2] ) > 64 && getConeDot( goal + ( 1, 1, 0 ), self.origin + ( -1, -1, 0 ), VectorToAngles( ( goal[0], goal[1], self.origin[2] ) - self.origin ) ) < 0.64 && DistanceSquared2D(self.origin, goal) < 32 * 32 ) if ( abs( goal[2] - self.origin[2] ) > 64 && getConeDot( goal + ( 1, 1, 0 ), self.origin + ( -1, -1, 0 ), VectorToAngles( ( goal[0], goal[1], self.origin[2] ) - self.origin ) ) < 0.64 && DistanceSquared2D( self.origin, goal ) < 32 * 32 )
{ {
stucks = 2; stucks = 2;
} }
@ -2095,29 +2098,31 @@ bot_lookat( pos, time, vel, doAimPredict )
myAngle = self getPlayerAngles(); myAngle = self getPlayerAngles();
angles = VectorToAngles( ( pos - myEye ) - anglesToForward( myAngle ) ); angles = VectorToAngles( ( pos - myEye ) - anglesToForward( myAngle ) );
X = ( angles[0] - myAngle[0] ); X = AngleClamp180( angles[0] - myAngle[0] );
while ( X > 170.0 )
X = X - 360.0;
while ( X < -170.0 )
X = X + 360.0;
X = X / steps; X = X / steps;
Y = ( angles[1] - myAngle[1] ); Y = AngleClamp180( angles[1] - myAngle[1] );
while ( Y > 180.0 )
Y = Y - 360.0;
while ( Y < -180.0 )
Y = Y + 360.0;
Y = Y / steps; Y = Y / steps;
for ( i = 0; i < steps; i++ ) for ( i = 0; i < steps; i++ )
{ {
myAngle = ( myAngle[0] + X, myAngle[1] + Y, 0 ); newX = myAngle[0] + X;
while ( newX < 0 )
newX += 360.0;
while ( newX >= 360.0 )
newX -= 360.0;
newY = myAngle[1] + Y;
while ( newY < 0 )
newY += 360.0;
while ( newY >= 360.0 )
newY -= 360.0;
myAngle = ( newX, newY, 0 );
self setPlayerAngles( myAngle ); self setPlayerAngles( myAngle );
wait 0.05; wait 0.05;
} }

View File

@ -205,6 +205,14 @@ BotStopMoving( what )
self notify( "kill_goal" ); self notify( "kill_goal" );
} }
/*
Notify the bot chat message
*/
BotNotifyBotEvent( msg, a, b, c, d, e, f, g )
{
self notify( "bot_event", msg, a, b, c, d, e, f, g );
}
/* /*
Returns if the bot has a script goal. Returns if the bot has a script goal.
(like t5 gsc bot) (like t5 gsc bot)
@ -886,6 +894,50 @@ RoundUp( floatVal )
return i; return i;
} }
/*
clamps angle between -180 and 180
*/
AngleClamp180( angle )
{
angleFrac = angle / 360.0;
angle = ( angleFrac - int( angleFrac ) ) * 360.0;
if ( angle > 180.0 )
return angle - 360.0;
return angle;
}
/*
no max, really??
*/
max( a, b )
{
if ( a > b )
return a;
return b;
}
/*
no min, really??
*/
min( a, b )
{
if ( a > b )
return b;
return a;
}
/*
Clamps between value
*/
Clamp( a, minv, maxv )
{
return max( min( a, maxv ), minv );
}
/* /*
Matches a num to a char Matches a num to a char
*/ */