Advertisement
inkoalawetrust

First dynarray attempt.

May 15th, 2022
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. Class SM_ProjectileHandler : EventHandler
  2. {
  3. Array <Actor> ProjectileList;
  4.  
  5. Override Void WorldThingSpawned(WorldEvent E)
  6. {
  7. //Add every spawned projectile to a big list.
  8. If (E.Thing && E.Thing.bMissile)
  9. {
  10. ProjectileList.Push(E.Thing);
  11. }
  12. }
  13.  
  14. Override Void WorldThingDied (WorldEvent E)
  15. {
  16. //Delete any destroyed projectiles from the list.
  17. If (E.Thing && E.Thing.bMissile)
  18. ProjectileList.Delete(ProjectileList.Find(E.Thing));
  19. }
  20. }
  21.  
  22. //Returns a pointer to the first enemy projectile that is in range of the marine.
  23. Bool SM_FindNearbyProjectile (Double Range = 144)
  24. {
  25. Static Const Name IgnoredProjectiles[] = //A list of enemy projectiles that they don't try avoiding.
  26. {
  27. "SM_Grenade",
  28. "ThrownGrenade1"
  29. };
  30.  
  31. Static Const Name AlwaysAvoid[] = //A list of projectiles to always avoid, even if fired by a friend.
  32. {
  33. "Rocket"
  34. //"SM_Missile" //Future feature.
  35. };
  36.  
  37. Let ProjectileHandler = SM_ProjectileHandler(EventHandler.Find("SM_ProjectileHandler"));
  38.  
  39. If (ProjectileHandler)
  40. {
  41. For (Int I; I < ProjectileHandler.ProjectileList.Size(); I++)
  42. {
  43. Actor Projectile = ProjectileHandler.ProjectileList[I];
  44.  
  45. //Null check.
  46. If (!Projectile) Continue;
  47.  
  48. //Out of range.
  49. If (Distance3DSquared(Projectile) > Range*Range) Continue;
  50.  
  51. //Projectile has no shooter, or the shooter isn't hostile to the marine.
  52. //This check is here to prevent them jumping all over the place for every projectile near them. Including ones fired by allies.
  53. If (Projectile.Target && !IsHostile(Projectile.Target))
  54. {
  55. //But if the projectile is on the AlwaysAvoid list, then try dodging it.
  56. For (Int I; I < AlwaysAvoid.Size(); I++)
  57. {
  58. If (Projectile.GetClassName() == AlwaysAvoid[I]) console.printf ("This projectile isn't kosher.");
  59. Else {console.printf ("This friendly projectile wasn't on the AlwaysAvoid list."); Continue;}
  60. }
  61. }
  62.  
  63. //Don't keep dodging the same projectile.
  64. If (Projectile == PreviousProjectile) {console.printf ("I've seen this one. This is a classic !"); Continue;}
  65.  
  66. //Don't return true if it's part of the blacklist.
  67. For (Int I; I < IgnoredProjectiles.Size(); I++)
  68. {
  69. If (Projectile.GetClassName() == IgnoredProjectiles[I]) {console.printf ("I shouldn't avoid this projectile.");Continue;}
  70. }
  71.  
  72. //Don't return true if the projectile isn't visible at all, or is too far away from the marines' peripheral vision.
  73. If (!(IsVisible (Projectile,True) && AbsAngle (Angle,AngleTo(Projectile)) <= 220)) {console.printf ("Out of sight."); Continue;}
  74.  
  75. //console.printf ("I found an enemy projectile.");
  76.  
  77. NearbyProjectile = Projectile;
  78. Return True;
  79. }
  80. }
  81. console.printf ("No projectiles found.");
  82. Return False;
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement