diff --git a/OpenRA.Mods.RA/HackyAI.cs b/OpenRA.Mods.RA/HackyAI.cs index 0559ef5991..136aa05836 100644 --- a/OpenRA.Mods.RA/HackyAI.cs +++ b/OpenRA.Mods.RA/HackyAI.cs @@ -282,7 +282,7 @@ namespace OpenRA.Mods.RA return; foreach (var a in unitsHangingAroundTheBase) - if (TryToMove(a, attackTarget.Value)) + if (TryToAttackMove(a, attackTarget.Value)) attackForce.Add(a); unitsHangingAroundTheBase.Clear(); @@ -339,6 +339,28 @@ namespace OpenRA.Mods.RA return true; } + //try very hard to find a valid move destination near the target. + //(Don't accept a move onto the subject's current position. maybe this is already not allowed? ) + bool TryToAttackMove(Actor a, int2 desiredMoveTarget) + { + if (!a.HasTrait()) + return false; + + int2 xy; + int loopCount = 0; //avoid infinite loops. + int range = 2; + do + { + //loop until we find a valid move location + xy = new int2(desiredMoveTarget.X + random.Next(-range, range), desiredMoveTarget.Y + random.Next(-range, range)); + loopCount++; + range = Math.Max(range, loopCount / 2); + if (loopCount > 10) return false; + } while (!a.Trait().CanEnterCell(xy) && xy != a.Location); + world.IssueOrder(new Order("AttackMove", a, xy)); + return true; + } + void DeployMcv(Actor self) { /* find our mcv and deploy it */