Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class SM_ProjectileHandler : EventHandler
- {
- Array <Actor> ProjectileList;
- Override Void WorldThingSpawned(WorldEvent E)
- {
- //Add every spawned projectile to a big list.
- If (E.Thing && E.Thing.bMissile)
- {
- ProjectileList.Push(E.Thing);
- }
- }
- Override Void WorldThingDied (WorldEvent E)
- {
- //Delete any destroyed projectiles from the list.
- If (E.Thing && E.Thing.bMissile)
- ProjectileList.Delete(ProjectileList.Find(E.Thing));
- }
- }
- //Returns a pointer to the first enemy projectile that is in range of the marine.
- Bool SM_FindNearbyProjectile (Double Range = 144)
- {
- Static Const Name IgnoredProjectiles[] = //A list of enemy projectiles that they don't try avoiding.
- {
- "SM_Grenade",
- "ThrownGrenade1"
- };
- Static Const Name AlwaysAvoid[] = //A list of projectiles to always avoid, even if fired by a friend.
- {
- "Rocket"
- //"SM_Missile" //Future feature.
- };
- Let ProjectileHandler = SM_ProjectileHandler(EventHandler.Find("SM_ProjectileHandler"));
- If (ProjectileHandler)
- {
- For (Int I; I < ProjectileHandler.ProjectileList.Size(); I++)
- {
- Actor Projectile = ProjectileHandler.ProjectileList[I];
- //Null check.
- If (!Projectile) Continue;
- //Out of range.
- If (Distance3DSquared(Projectile) > Range*Range) Continue;
- //Projectile has no shooter, or the shooter isn't hostile to the marine.
- //This check is here to prevent them jumping all over the place for every projectile near them. Including ones fired by allies.
- If (Projectile.Target && !IsHostile(Projectile.Target))
- {
- //But if the projectile is on the AlwaysAvoid list, then try dodging it.
- For (Int I; I < AlwaysAvoid.Size(); I++)
- {
- If (Projectile.GetClassName() == AlwaysAvoid[I]) console.printf ("This projectile isn't kosher.");
- Else {console.printf ("This friendly projectile wasn't on the AlwaysAvoid list."); Continue;}
- }
- }
- //Don't keep dodging the same projectile.
- If (Projectile == PreviousProjectile) {console.printf ("I've seen this one. This is a classic !"); Continue;}
- //Don't return true if it's part of the blacklist.
- For (Int I; I < IgnoredProjectiles.Size(); I++)
- {
- If (Projectile.GetClassName() == IgnoredProjectiles[I]) {console.printf ("I shouldn't avoid this projectile.");Continue;}
- }
- //Don't return true if the projectile isn't visible at all, or is too far away from the marines' peripheral vision.
- If (!(IsVisible (Projectile,True) && AbsAngle (Angle,AngleTo(Projectile)) <= 220)) {console.printf ("Out of sight."); Continue;}
- //console.printf ("I found an enemy projectile.");
- NearbyProjectile = Projectile;
- Return True;
- }
- }
- console.printf ("No projectiles found.");
- Return False;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement