diff --git a/OpenRA.Mods.RA/AI/Squad.cs b/OpenRA.Mods.RA/AI/Squad.cs index 84da2e26d0..e3db95a91c 100644 --- a/OpenRA.Mods.RA/AI/Squad.cs +++ b/OpenRA.Mods.RA/AI/Squad.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.FileFormats; using OpenRA.Traits; using XRandom = OpenRA.Thirdparty.Random; @@ -78,5 +79,7 @@ namespace OpenRA.Mods.RA.AI get { return (target != null && !target.IsDead() && !target.Destroyed && target.IsInWorld && !target.HasTrait()); } } + + public WPos CenterPosition { get { return units.Select(u => u.CenterPosition).Average(); } } } } diff --git a/OpenRA.Mods.RA/AI/States/ProtectionStates.cs b/OpenRA.Mods.RA/AI/States/ProtectionStates.cs index 06e954ab87..ff40ec8219 100644 --- a/OpenRA.Mods.RA/AI/States/ProtectionStates.cs +++ b/OpenRA.Mods.RA/AI/States/ProtectionStates.cs @@ -32,9 +32,7 @@ namespace OpenRA.Mods.RA.AI if (!owner.TargetIsValid) { - var circaPostion = AverageUnitsPosition(owner.units); - if (circaPostion == null) return; - owner.Target = owner.bot.FindClosestEnemy(circaPostion.Value.CenterPosition, WRange.FromCells(8)); + owner.Target = owner.bot.FindClosestEnemy(owner.CenterPosition, WRange.FromCells(8)); if (owner.Target == null) { @@ -42,6 +40,7 @@ namespace OpenRA.Mods.RA.AI return; } } + foreach (var a in owner.units) owner.world.IssueOrder(new Order("AttackMove", a, false) { TargetLocation = owner.Target.Location }); } diff --git a/OpenRA.Mods.RA/AI/States/StateBase.cs b/OpenRA.Mods.RA/AI/States/StateBase.cs index 4f4ebda24e..7a03cb9872 100644 --- a/OpenRA.Mods.RA/AI/States/StateBase.cs +++ b/OpenRA.Mods.RA/AI/States/StateBase.cs @@ -21,23 +21,6 @@ namespace OpenRA.Mods.RA.AI { protected const int DangerRadius = 10; - protected static CPos? AverageUnitsPosition(List units) - { - int x = 0; - int y = 0; - int countUnits = 0; - foreach (var u in units) - { - x += u.Location.X; - y += u.Location.Y; - countUnits++; - } - - x = x / countUnits; - y = y / countUnits; - return (x != 0 && y != 0) ? new CPos?(new CPos(x, y)) : null; - } - protected static void GoToRandomOwnBuilding(Squad squad) { var loc = RandomBuildingLocation(squad);