diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 4c7554d89b..f841947000 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -170,7 +170,8 @@ namespace OpenRA.Traits Activity MoveTo(CPos cell, int nearEnough); Activity MoveTo(CPos cell, Actor ignoredActor); Activity MoveWithinRange(Target target, WRange range); - Activity MoveFollow(Actor self, Target target, WRange range); + Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange); + Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange); Activity MoveIntoWorld(Actor self, CPos cell); Activity VisualMove(Actor self, WPos fromPos, WPos toPos); CPos NearestMoveableCell(CPos target); diff --git a/OpenRA.Mods.RA/Activities/Attack.cs b/OpenRA.Mods.RA/Activities/Attack.cs index cf2958cc86..8df3bbce37 100755 --- a/OpenRA.Mods.RA/Activities/Attack.cs +++ b/OpenRA.Mods.RA/Activities/Attack.cs @@ -25,13 +25,10 @@ namespace OpenRA.Mods.RA.Activities const int delayBetweenPathingAttempts = 20; const int delaySpread = 5; - public Attack(Target target, WRange range) - : this(target, range, true) {} - - public Attack(Target target, WRange range, bool allowMovement) + public Attack(Actor self, Target target, WRange minRange, WRange maxRange, bool allowMovement) { Target = target; - Range = range; + Range = maxRange; AllowMovement = allowMovement; } diff --git a/OpenRA.Mods.RA/Activities/FlyFollow.cs b/OpenRA.Mods.RA/Activities/FlyFollow.cs index 2e62d3fdb1..83ea6a0fa1 100644 --- a/OpenRA.Mods.RA/Activities/FlyFollow.cs +++ b/OpenRA.Mods.RA/Activities/FlyFollow.cs @@ -17,13 +17,15 @@ namespace OpenRA.Mods.RA.Activities { Target target; Plane plane; - WRange range; + WRange minRange; + WRange maxRange; - public FlyFollow(Actor self, Target target, WRange range) + public FlyFollow(Actor self, Target target, WRange minRange, WRange maxRange) { this.target = target; plane = self.Trait(); - this.range = range; + this.minRange = minRange; + this.maxRange = maxRange; } public override Activity Tick(Actor self) @@ -31,13 +33,13 @@ namespace OpenRA.Mods.RA.Activities if (IsCanceled || !target.IsValidFor(self)) return NextActivity; - if (target.IsInRange(self.CenterPosition, range)) + if (target.IsInRange(self.CenterPosition, maxRange) && !target.IsInRange(self.CenterPosition, minRange)) { Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude); return this; } - return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), this); + return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), this); } } } diff --git a/OpenRA.Mods.RA/Activities/Follow.cs b/OpenRA.Mods.RA/Activities/Follow.cs index 3f74bf8621..a59706ecd2 100644 --- a/OpenRA.Mods.RA/Activities/Follow.cs +++ b/OpenRA.Mods.RA/Activities/Follow.cs @@ -22,11 +22,11 @@ namespace OpenRA.Mods.RA.Activities const int delayBetweenPathingAttempts = 20; const int delaySpread = 5; - public Follow(Actor self, Target target, WRange range) + public Follow(Actor self, Target target, WRange minRange, WRange maxRange) { this.target = target; move = self.Trait(); - this.range = range; + this.range = maxRange; } public override Activity Tick(Actor self) diff --git a/OpenRA.Mods.RA/Activities/Heal.cs b/OpenRA.Mods.RA/Activities/Heal.cs index 660337a952..b73cc59899 100755 --- a/OpenRA.Mods.RA/Activities/Heal.cs +++ b/OpenRA.Mods.RA/Activities/Heal.cs @@ -12,11 +12,10 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Activities { - /* non-turreted attack */ public class Heal : Attack { - public Heal(Target target, WRange range, bool allowMovement) - : base(target, range, allowMovement) { } + public Heal(Actor self, Target target, WRange minRange, WRange maxRange, bool allowMovement) + : base(self, target, minRange, maxRange, allowMovement) { } protected override Activity InnerTick(Actor self, AttackBase attack) { diff --git a/OpenRA.Mods.RA/Air/Helicopter.cs b/OpenRA.Mods.RA/Air/Helicopter.cs index 4d0a446b27..7dc9e46de0 100755 --- a/OpenRA.Mods.RA/Air/Helicopter.cs +++ b/OpenRA.Mods.RA/Air/Helicopter.cs @@ -165,7 +165,7 @@ namespace OpenRA.Mods.RA.Air public Activity MoveTo(CPos cell, Actor ignoredActor) { return new HeliFly(self, Target.FromCell(cell)); } public Activity MoveWithinRange(Target target, WRange range) { return new HeliFly(self, target, WRange.Zero, range); } public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new HeliFly(self, target, minRange, maxRange); } - public Activity MoveFollow(Actor self, Target target, WRange range) { return new Follow(self, target, range); } + public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); } public CPos NearestMoveableCell(CPos cell) { return cell; } public Activity MoveIntoWorld(Actor self, CPos cell) diff --git a/OpenRA.Mods.RA/Air/Plane.cs b/OpenRA.Mods.RA/Air/Plane.cs index 652df7166b..40f81c5b43 100755 --- a/OpenRA.Mods.RA/Air/Plane.cs +++ b/OpenRA.Mods.RA/Air/Plane.cs @@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Air public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(cell)), new FlyCircle()); } public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle()); } public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle()); } - public Activity MoveFollow(Actor self, Target target, WRange range) { return new FlyFollow(self, target, range); } + public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); } public CPos NearestMoveableCell(CPos cell) { return cell; } public Activity MoveIntoWorld(Actor self, CPos cell) { return new Fly(self, Target.FromCell(cell)); } diff --git a/OpenRA.Mods.RA/Attack/AttackFollow.cs b/OpenRA.Mods.RA/Attack/AttackFollow.cs index 2eb3bb3d10..4c8a548931 100644 --- a/OpenRA.Mods.RA/Attack/AttackFollow.cs +++ b/OpenRA.Mods.RA/Attack/AttackFollow.cs @@ -80,17 +80,16 @@ namespace OpenRA.Mods.RA if (self.IsDisabled()) return this; - const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */ var weapon = attack.ChooseArmamentForTarget(target); - if (weapon != null) { - var range = WRange.FromCells(Math.Max(0, weapon.Weapon.Range.Range / 1024 - RangeTolerance)); + // Try and sit at least one cell closer than the max range to give some leeway if the target stars moving. + var maxRange = new WRange(Math.Max(weapon.Weapon.MinRange.Range, weapon.Weapon.Range.Range - 1024)); attack.Target = target; if (move != null) - return Util.SequenceActivities(move.MoveFollow(self, target, range), this); + return Util.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this); } return NextActivity; diff --git a/OpenRA.Mods.RA/Attack/AttackFrontal.cs b/OpenRA.Mods.RA/Attack/AttackFrontal.cs index c46a2c8fae..ab0c1dd02a 100644 --- a/OpenRA.Mods.RA/Attack/AttackFrontal.cs +++ b/OpenRA.Mods.RA/Attack/AttackFrontal.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA if (a == null) return null; - return new Activities.Attack(newTarget, a.Weapon.Range, allowMove); + return new Activities.Attack(self, newTarget, a.Weapon.MinRange, a.Weapon.Range, allowMove); } } } diff --git a/OpenRA.Mods.RA/Attack/AttackMedic.cs b/OpenRA.Mods.RA/Attack/AttackMedic.cs index 4065582a42..1bf2b524e6 100644 --- a/OpenRA.Mods.RA/Attack/AttackMedic.cs +++ b/OpenRA.Mods.RA/Attack/AttackMedic.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA if (a == null) return null; - return new Activities.Heal(newTarget, a.Weapon.Range, allowMove); + return new Activities.Heal(self, newTarget, a.Weapon.MinRange, a.Weapon.Range, allowMove); } } } diff --git a/OpenRA.Mods.RA/Guard.cs b/OpenRA.Mods.RA/Guard.cs index 0e9e1b62f2..5472a61956 100644 --- a/OpenRA.Mods.RA/Guard.cs +++ b/OpenRA.Mods.RA/Guard.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA self.SetTargetLine(target, Color.Yellow); var range = WRange.FromCells(target.Actor.Info.Traits.Get().Range); - self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait().MoveFollow(self, target, range))); + self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait().MoveFollow(self, target, WRange.Zero, range))); } public string VoicePhraseForOrder(Actor self, Order order) diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index b698758ec0..1b7ea86359 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -592,7 +592,8 @@ namespace OpenRA.Mods.RA.Move public Activity MoveTo(CPos cell, int nearEnough) { return new Move(cell, nearEnough); } public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(cell, ignoredActor); } public Activity MoveWithinRange(Target target, WRange range) { return new Move(target, range); } - public Activity MoveFollow(Actor self, Target target, WRange range) { return new Follow(self, target, range); } + public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new Move(target, maxRange); } + public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); } public Activity MoveTo(Func> pathFunc) { return new Move(pathFunc); } public void OnNotifyBlockingMove(Actor self, Actor blocking)