diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index 58a3aa4485..27237d0c70 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -37,7 +37,7 @@ namespace OpenRa.Game .Where(t => Game.IsCellBuildable(t, umt)) .Select(t => t + map.Offset); - var path = FindUnitPath(tilesInRange, DefaultEstimator(dest), umt); + var path = FindUnitPath(tilesInRange, DefaultEstimator(src), umt); path.Reverse(); return path; } diff --git a/OpenRa.Game/Traits/AttackTurreted.cs b/OpenRa.Game/Traits/AttackTurreted.cs index 73e85bfcbf..b3aa485a3c 100755 --- a/OpenRa.Game/Traits/AttackTurreted.cs +++ b/OpenRa.Game/Traits/AttackTurreted.cs @@ -89,6 +89,13 @@ namespace OpenRa.Game.Traits } public override void Apply() { + var mobile = Attacker.traits.GetOrDefault(); + if (mobile != null) + { + mobile.Cancel(Attacker); + mobile.QueueActivity(new Mobile.MoveTo(Target, 3)); /* todo: get range properly */ + } + Attacker.traits.Get().target = Target; } } diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index 9705e7123a..61f739dea1 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -120,14 +120,25 @@ namespace OpenRa.Game.Traits { public CurrentActivity NextActivity { get; set; } - int2 destination; - List path; + int2? destination; + List path; + Func> getPath; MovePart move; public MoveTo( int2 destination ) - { + { + this.getPath = (self, mobile) => Game.pathFinder.FindUnitPath(self.Location, destination, + mobile.GetMovementType()); this.destination = destination; + } + + public MoveTo(Actor target, int range) + { + this.getPath = (self, mobile) => Game.pathFinder.FindUnitPathToRange( + self.Location, target.Location, + mobile.GetMovementType(), range); + this.destination = null; } static bool CanEnterCell(int2 c, Actor self) @@ -150,13 +161,15 @@ namespace OpenRa.Game.Traits return; } - if( path == null ) - path = Game.pathFinder.FindUnitPath( self.Location, destination, mobile.GetMovementType() ); - if( path.Count == 0 ) - { - destination = mobile.toCell; - return; - } + if( path == null ) path = getPath(self, mobile); + + if (path.Count == 0) + { + destination = mobile.toCell; + return; + } + else + destination = path[0]; var nextCell = path[ path.Count - 1 ]; int2 dir = nextCell - mobile.fromCell;