mirror of
https://github.com/JezuzLizard/t4sp_bot_warfare.git
synced 2025-04-23 06:55:44 +00:00
Add target handling code.
This commit is contained in:
parent
a6ce1e1923
commit
bdf933b907
@ -78,6 +78,9 @@ main()
|
||||
//register_bot_objective( "part" );
|
||||
register_bot_objective( "powerup" );
|
||||
|
||||
register_bot_target_type( "zombie" );
|
||||
register_bot_target_type( "zombie_dog" );
|
||||
|
||||
level.bot_weapon_quality_poor = 0;
|
||||
level.bot_weapon_quality_fair = 1;
|
||||
level.bot_weapon_quality_good = 2;
|
||||
@ -136,6 +139,7 @@ on_player_connect()
|
||||
//TODO: Add the ability to check if a bot is at an objective to start the action think
|
||||
//TODO: Add atobjective movement handler to let objectives control movement temporarily
|
||||
//TODO: Allow bots to still do actions while down if possible
|
||||
//TODO: Track zombies targetting players
|
||||
|
||||
init()
|
||||
{
|
||||
@ -190,7 +194,7 @@ init()
|
||||
{
|
||||
for ( i = 0; i < zombie_debris.size; i++ )
|
||||
{
|
||||
zombie_debris.id = i;
|
||||
zombie_debris[ i ].id = i;
|
||||
add_possible_bot_objective( "debris", i, true, zombie_debris[ i ] );
|
||||
}
|
||||
level thread watch_debris_objectives( zombie_debris );
|
||||
@ -207,6 +211,9 @@ init()
|
||||
}
|
||||
}
|
||||
|
||||
level.callbackActorSpawned = ::zbots_actor_spawned;
|
||||
level.callbackActorKilled = ::zbots_actor_killed;
|
||||
|
||||
level thread watch_for_downed_players();
|
||||
|
||||
level thread store_powerups_dropped();
|
||||
@ -214,6 +221,29 @@ init()
|
||||
parse_bot_weapon_stats_from_table();
|
||||
}
|
||||
|
||||
zbots_actor_spawned()
|
||||
{
|
||||
self thread add_actor_to_target_glob();
|
||||
}
|
||||
|
||||
add_actor_to_target_glob()
|
||||
{
|
||||
wait 1; //Wait long enough for the actor to be initialized in script
|
||||
assert( isDefined( self.targetname ), "Actor doesn't have a targetname set" );
|
||||
if ( !isDefined( self.targetname ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
add_possible_bot_target( self.targetname, level.zbot_target_glob_ids[ self.targetname ], self );
|
||||
self.target_id = level.zbot_target_glob_ids[ self.targetname ];
|
||||
level.zbot_target_glob_ids[ self.targetname ]++;
|
||||
}
|
||||
|
||||
zbots_actor_killed( eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, iTimeOffset )
|
||||
{
|
||||
free_bot_target( self.targetname, self.target_id );
|
||||
}
|
||||
|
||||
spawn_bots()
|
||||
{
|
||||
level waittill( "connected", player );
|
||||
|
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user