mirror of
https://github.com/JezuzLizard/t4sp_bot_warfare.git
synced 2025-06-30 08:11:53 +00:00
Add target handling code.
This commit is contained in:
@ -161,4 +161,58 @@ bot_lookatgoal_on_postpone()
|
||||
bot_lookatgoal_priority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bot_lookat( pos, time, vel, doAimPredict )
|
||||
{
|
||||
self notify( "bots_aim_overlap" );
|
||||
self endon( "bots_aim_overlap" );
|
||||
self endon( "disconnect" );
|
||||
self endon( "player_downed" );
|
||||
level endon( "end_game" );
|
||||
|
||||
if ( level.gameEnded || level.inPrematchPeriod || self.bot.isfrozen || !getDvarInt( "bots_play_aim" ) )
|
||||
return;
|
||||
|
||||
if ( !isDefined( pos ) )
|
||||
return;
|
||||
|
||||
if ( !isDefined( doAimPredict ) )
|
||||
doAimPredict = false;
|
||||
|
||||
if ( !isDefined( time ) )
|
||||
time = 0.05;
|
||||
|
||||
if ( !isDefined( vel ) )
|
||||
vel = ( 0, 0, 0 );
|
||||
|
||||
steps = int( time * 20 );
|
||||
|
||||
if ( steps < 1 )
|
||||
steps = 1;
|
||||
|
||||
myEye = self GetEyePos(); // get our eye pos
|
||||
|
||||
if ( doAimPredict )
|
||||
{
|
||||
myEye += ( self getVelocity() * 0.05 ) * ( steps - 1 ); // account for our velocity
|
||||
|
||||
pos += ( vel * 0.05 ) * ( steps - 1 ); // add the velocity vector
|
||||
}
|
||||
|
||||
myAngle = self getPlayerAngles();
|
||||
angles = VectorToAngles( ( pos - myEye ) - anglesToForward( myAngle ) );
|
||||
|
||||
X = AngleClamp180( angles[0] - myAngle[0] );
|
||||
X = X / steps;
|
||||
|
||||
Y = AngleClamp180( angles[1] - myAngle[1] );
|
||||
Y = Y / steps;
|
||||
|
||||
for ( i = 0; i < steps; i++ )
|
||||
{
|
||||
myAngle = ( AngleClamp180(myAngle[0] + X), AngleClamp180(myAngle[1] + Y), 0 );
|
||||
self setPlayerAngles( myAngle );
|
||||
wait 0.05;
|
||||
}
|
||||
}
|
93
scripts/sp/bots/bot_target_common.gsc
Normal file
93
scripts/sp/bots/bot_target_common.gsc
Normal file
@ -0,0 +1,93 @@
|
||||
register_bot_target_type( target_group )
|
||||
{
|
||||
if ( !isDefined( level.zbot_target_glob ) )
|
||||
{
|
||||
level.zbot_target_glob = [];
|
||||
level.zbot_target_glob_ids = [];
|
||||
}
|
||||
if ( !isDefined( level.zbot_target_glob[ target_group ] ) )
|
||||
{
|
||||
level.zbot_target_glob_ids[ target_group ] = 0;
|
||||
level.zbot_target_glob[ target_group ] = spawnStruct();
|
||||
level.zbot_target_glob[ target_group ].active_targets = [];
|
||||
}
|
||||
}
|
||||
|
||||
add_possible_bot_target( target_group, id, target_ent )
|
||||
{
|
||||
assert( isDefined( level.zbot_target_glob ), "Trying to add target before calling register_bot_target_type" );
|
||||
|
||||
assert( isDefined( level.zbot_target_glob[ target_group ] ), "Trying to add target to group " + target_group + " before calling register_bot_target_type" );
|
||||
|
||||
target_struct = spawnStruct();
|
||||
target_struct.group = target_group;
|
||||
target_struct.id = id;
|
||||
target_struct.damaged_by = [];
|
||||
target_struct.targeted_by = [];
|
||||
target_struct.target_ent = target_ent;
|
||||
target_struct.is_target = true;
|
||||
|
||||
level.zbot_target_glob[ target_group ].active_targets[ "targ_id_" + id ] = target_struct;
|
||||
}
|
||||
|
||||
get_bot_target_by_id( target_group, id )
|
||||
{
|
||||
active_targets = level.zbot_target_glob[ target_group ].active_targets;
|
||||
|
||||
target = active_targets[ "targ_id_" + id ];
|
||||
|
||||
assert( isDefined( target ), "Target with " + id + " id does not point to a target in group " + target_group );
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
get_all_targets_for_group( target_group )
|
||||
{
|
||||
return level.zbot_target_glob[ target_group ].active_targets;
|
||||
}
|
||||
|
||||
set_target_for_bot( target_group, id )
|
||||
{
|
||||
possible_targets = level.zbot_target_glob[ primary_target_group ].active_targets;
|
||||
|
||||
target = possible_targets[ "targ_id_" + id ];
|
||||
|
||||
target_exists = isDefined( primary_target );
|
||||
|
||||
assert( target_exists, "Target with " + id + " id does not point to a target in group " + target_group );
|
||||
if ( !target_exists )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self.zbot_current_target = target;
|
||||
|
||||
for ( i = 0; i < target.targeted_by.size; i++ )
|
||||
{
|
||||
if ( target.targeted_by[ i ] == self )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
target.targeted_by[ target.targeted_by.size ] = self;
|
||||
}
|
||||
|
||||
free_bot_target( target_group, id )
|
||||
{
|
||||
active_targets = level.zbot_global_shared_target_glob[ target_group ].active_targets;
|
||||
|
||||
target = active_targets[ "targ_id_" + id ];
|
||||
|
||||
target_exists = isDefined( target );
|
||||
assert( target_exists, "Target with " + id + " id number does not point to a target in group " + target_group );
|
||||
if ( !target_exists )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
target.damaged_by = undefined;
|
||||
target.targeted_by = undefined;
|
||||
|
||||
target = undefined;
|
||||
}
|
Reference in New Issue
Block a user