Skip to content

Commit

Permalink
fixed ac130/chopper angles,
Browse files Browse the repository at this point in the history
bots properly use pred missiles
  • Loading branch information
ineed bots committed Apr 30, 2024
1 parent 755541e commit 72526aa
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 77 deletions.
30 changes: 24 additions & 6 deletions maps/mp/bots/_bot.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ init()
level.bots_fullautoguns[ "peacekeeper" ] = true;

level thread fixGamemodes();
level thread fixPredMissile();

level thread onPlayerConnect();
level thread addNotifyOnAirdrops();
Expand All @@ -286,6 +287,23 @@ init()
level thread onPlayerChat();
}

/*
Change func pointer to ours, so that we can link the player ref to the rocket
*/
fixPredMissile()
{
for ( i = 0; i < 19; i++ )
{
if ( isdefined( level.killstreakfuncs ) && isdefined( level.killstreakfuncs[ "predator_missile" ] ) )
{
level.killstreakfuncs[ "predator_missile" ] = ::tryUsePredatorMissileFix;
break;
}

wait 0.05;
}
}

/*
Starts the threads for bots.
*/
Expand Down Expand Up @@ -606,7 +624,7 @@ watchScrabler()
onDisconnectPlayer()
{
name = self.name;

self waittill( "disconnect" );
waittillframeend;

Expand Down Expand Up @@ -1168,11 +1186,11 @@ addBots_loop()
if ( fillMode == 0 || fillMode == 2 )
{
amount += players;
}

if ( getdvarint( "bots_manage_fill_spec" ) )
{
amount += spec;
if ( getdvarint( "bots_manage_fill_spec" ) )
{
amount += spec;
}
}

if ( amount < fillAmount )
Expand Down
209 changes: 200 additions & 9 deletions maps/mp/bots/_bot_internal.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,6 @@ onWeaponChange()
{
first = false;
newWeapon = self getcurrentweapon();

// hack fix for botstop overridding weapon
if ( newWeapon != "none" )
{
self switchtoweapon( newWeapon );
}
}
else
{
Expand Down Expand Up @@ -375,11 +369,208 @@ watchUsingRemote()
self watchUsingAc130();
}

if ( isdefined( self.rocket ) )
{
self watchUsingPred();
self BotBuiltinBotAction( "-remote" );
}

self.bot.targets = [];
self notify( "kill_goal" );
}
}

/*
Returns the angle delta
*/
getRemoteAngleSpeed( len )
{
furthest = 10.0;
max_speed = 127;

switch ( self.pers[ "bots" ][ "skill" ][ "base" ] )
{
case 1:
furthest = 5.0;
max_speed = 20;
break;

case 2:
furthest = 6.0;
max_speed = 35;
break;

case 3:
furthest = 7.0;
max_speed = 55;
break;

case 4:
furthest = 8.0;
max_speed = 65;
break;

case 5:
furthest = 9.0;
max_speed = 75;
break;

case 6:
furthest = 10.0;
max_speed = 100;
break;

case 7:
furthest = 15.0;
max_speed = 127;
break;
}

if ( len >= furthest )
{
return max_speed;
}

if ( len <= 0.0 )
{
return 0;
}

return Round( ( len / furthest ) * max_speed );
}

/*
time to boost the rocket
*/
getRemoteBoostTime()
{
switch ( self.pers[ "bots" ][ "skill" ][ "base" ] )
{
case 1:
return 99999;

case 2:
return 15000;

case 3:
return 10000;

case 4:
return 5000;

case 5:
return 2500;

case 6:
return 1000;

case 7:
return 500;

default:
return 500;
}
}

/*
While in rocket
*/
watchUsingPred()
{
self.rocket endon( "death" );

self BotBuiltinBotRemoteAngles( 0, 0 );
self BotBuiltinBotAction( "+remote" );

pressedFire = false;
sTime = gettime();

while ( isdefined( self.rocket ) )
{
self.bot.targets = []; // dont want to fire from aim thread
// because geteye doesnt return the eye of the missile

target = undefined;
myeye = self.rocket.origin;
myangles = self.rocket.angles;
bestfov = 0.0;

for ( i = level.players.size - 1; i >= 0; i-- )
{
player = level.players[ i ];

if ( !isdefined( player ) || !isdefined( player.team ) )
{
continue;
}

if ( player == self || ( level.teambased && player.team == self.team ) )
{
continue;
}

if ( player.sessionstate != "playing" || !isreallyalive( player ) )
{
continue;
}

if ( player _hasperk( "specialty_coldblooded" ) )
{
continue;
}

if ( !bullettracepassed( myeye, player.origin + ( 0, 0, 25 ), false, self.rocket ) )
{
continue;
}

thisfov = getConeDot( player.origin, myeye, myangles );

if ( thisfov < 0.75 )
{
continue;
}

if ( isdefined( target ) && thisfov < bestfov )
{
continue;
}

target = player;
bestfov = thisfov;
}

if ( isdefined( target ) )
{
if ( !pressedFire && gettime() - sTime > self getRemoteBoostTime() )
{
pressedFire = true;
self thread pressFire();
}

if ( bestfov < 0.999995 && distancesquared( target.origin, myeye ) > 256 * 256 )
{
angles = vectortoangles( ( target.origin - myeye ) - anglestoforward( myangles ) );
angles -= myangles;
angles = ( angleclamp180( angles[ 0 ] ), angleclamp180( angles[ 1 ] ), 0 );
angles = vectornormalize( angles ) * self getRemoteAngleSpeed( length( angles ) );

self BotBuiltinBotRemoteAngles( int( angles[ 0 ] ), int( angles[ 1 ] ) );
}
else
{
self BotBuiltinBotRemoteAngles( 0, 0 );
}
}
else
{
self BotBuiltinBotRemoteAngles( 0, 0 );
}

wait 0.05;
}
}

/*
WHen it uses the helicopter minigun
*/
Expand Down Expand Up @@ -1736,7 +1927,7 @@ aim_loop()
{
self thread bot_lookat( target gettagorigin( "j_spine4" ), 0.05 );
}
else if ( !nadeAimOffset && conedot > 0.999 && lengthsquared( aimoffset ) < 0.05 )
else if ( !nadeAimOffset && conedot > 0.999995 && lengthsquared( aimoffset ) < 0.05 )
{
self thread bot_lookat( aimpos, 0.05 );
}
Expand All @@ -1754,7 +1945,7 @@ aim_loop()

conedot = getConeDot( aimpos, eyePos, angles );

if ( !nadeAimOffset && conedot > 0.999 && lengthsquared( aimoffset ) < 0.05 )
if ( !nadeAimOffset && conedot > 0.999995 && lengthsquared( aimoffset ) < 0.05 )
{
self thread bot_lookat( aimpos, 0.05 );
}
Expand Down Expand Up @@ -3127,7 +3318,7 @@ bot_lookat( pos, time, vel, doAimPredict )
for ( i = 0; i < steps; i++ )
{
myAngle = ( angleclamp180( myAngle[ 0 ] + X ), angleclamp180( myAngle[ 1 ] + Y ), 0 );
self setplayerangles( myAngle );
self BotBuiltinBotAngles( myAngle );
wait 0.05;
}
}
69 changes: 7 additions & 62 deletions maps/mp/bots/_bot_script.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -5024,27 +5024,6 @@ getKillstreakTargetLocation()
return location;
}

/*
Clears remote usage when bot dies
*/
clear_remote_on_death( isac130 )
{
self endon( "bot_clear_remote_on_death" );
level endon( "game_ended" );

self waittill_either( "death", "disconnect" );

if ( isdefined( isac130 ) && isac130 )
{
level.ac130inuse = false;
}

if ( isdefined( self ) )
{
self clearusingremote();
}
}

/*
Returns if any harriers exists that is an enemy
*/
Expand Down Expand Up @@ -5142,6 +5121,11 @@ bot_killstreak_think_loop( data )
self thread BotPressAttack( 0.05 );
}

if ( iskillstreakweapon( curWeap ) )
{
self thread changeToWeapon( self getlastweapon() );
return;
}

streakName = self.pers[ "killstreaks" ][ 0 ].streakname;

Expand Down Expand Up @@ -5246,50 +5230,11 @@ bot_killstreak_think_loop( data )
self BotNotifyBotEvent( "killstreak", "call", streakName, location );

self BotRandomStance();
self setusingremote( "remotemissile" );
self thread clear_remote_on_death();
self BotStopMoving( true );
self changeToWeapon( ksWeap );

if ( !self changeToWeapon( ksWeap ) )
{
self clearusingremote();
self notify( "bot_clear_remote_on_death" );
self BotStopMoving( false );
return;
}

wait 0.05;
self thread changeToWeapon( ksWeap ); // prevent script from changing back

wait 1;
self notify( "bot_clear_remote_on_death" );
wait 3;
self BotStopMoving( false );

if ( self isemped() )
{
self clearusingremote();
self thread changeToWeapon( curWeap );
return;
}

self BotFreezeControls( true );

self maps\mp\killstreaks\_killstreaks::usedkillstreak( "predator_missile", true );
self maps\mp\killstreaks\_killstreaks::shufflekillstreaksfilo( "predator_missile" );
self maps\mp\killstreaks\_killstreaks::giveownedkillstreakitem();

rocket = magicbullet( "remotemissile_projectile_mp", self.origin + ( 0.0, 0.0, 7000.0 - ( self.pers[ "bots" ][ "skill" ][ "base" ] * 400 ) ), location, self );
rocket.lifeid = lifeId;
rocket.type = "remote";

rocket thread maps\mp\gametypes\_weapons::addmissiletosighttraces( self.pers[ "team" ] );
rocket thread maps\mp\killstreaks\_remotemissile::handledamage();
thread maps\mp\killstreaks\_remotemissile::missileeyes( self, rocket );

self waittill( "stopped_using_remote" );

wait 1;
self BotFreezeControls( false );
}
else if ( streakName == "ac130" )
{
Expand Down
Loading

0 comments on commit 72526aa

Please sign in to comment.