Advertisement
Guest User

counterattack

a guest
Aug 29th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. if (e.Attacker != null && e.Damage > 0)
  2.             {
  3.                 // Maybe this whole part should go somewhere else to avoid too much CounterAttack
  4.                 var allyUnits = world.FindUnitsInCircle(e.Attacker.CenterLocation, Game.CellSize * 6).Where(a => a.Owner == p && !a.HasTrait<Harvester>()).ToList();
  5.                 var enemyUnits = world.FindUnitsInCircle(e.Attacker.CenterLocation, Game.CellSize * 6).Where(a => a.Owner == e.Attacker.Owner).ToList();
  6.                 var allyUnitsAway = self.World.ActorsWithTrait<IMove>().Where(a => a.Actor.Owner == p && !a.Actor.HasTrait<BaseBuilding>()).Select(a => a.Actor).ToArray();
  7.                 BotDebug("Bot {2} noticed damage {0}, counter attack with {1} unit(s)", self, allyUnits.Count(), p.PlayerName);
  8.  
  9.                 var assaultUnits = allyUnits;
  10.  
  11.                 if (enemyUnits > allyUnits * 2) // TOTAL OVERRUN
  12.                     assaultUnits = allyUnitsAway;
  13.  
  14.                 foreach (var a in assaultUnits) // Fast Counter attack
  15.                     if (a.GetCurrentActivity().GetType() != typeof(OpenRA.Mods.RA.Activities.Rearm))
  16.                         if (a.HasTrait<Helicopter>() || a.HasTrait<Plane>() && a.TraitOrDefault<LimitedAmmo>().HasAmmo()) // Copters and planes should not take off without ammo
  17.                             TryToMove(a, e.Attacker.CenterLocation.ToCPos(), false);
  18.                         else
  19.                             TryToMove(a, e.Attacker.CenterLocation.ToCPos(), true);
  20.                 aggro[e.Attacker.Owner].Aggro += e.Damage;
  21.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement