diff --git a/OpenRA.Mods.RA/Activities/Leap.cs b/OpenRA.Mods.RA/Activities/Leap.cs index d8f4537386..64898fa68b 100644 --- a/OpenRA.Mods.RA/Activities/Leap.cs +++ b/OpenRA.Mods.RA/Activities/Leap.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Linq; using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Render; @@ -17,16 +18,29 @@ namespace OpenRA.Mods.RA.Activities { class Leap : Activity { - Target target; - PPos initialLocation; + Mobile mobile; + + PPos from; + PPos to; int moveFraction; - const int delay = 6; + const int length = 6; public Leap(Actor self, Target target) { - this.target = target; - initialLocation = (PPos) self.Trait().PxPosition; + if (!target.IsActor) + throw new InvalidOperationException("Leap requires a target actor"); + + var targetMobile = target.Actor.TraitOrDefault(); + if (targetMobile == null) + throw new InvalidOperationException("Leap requires a target actor with the Mobile trait"); + + mobile = self.Trait(); + mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, targetMobile.fromCell, targetMobile.fromSubCell); + mobile.IsMoving = true; + + from = self.CenterLocation; + to = Util.CenterOfCell(targetMobile.fromCell) + MobileInfo.SubCellOffsets[targetMobile.fromSubCell]; self.Trait().Attacking(self, target); Sound.Play("dogg5p.aud", self.CenterLocation); @@ -34,23 +48,18 @@ namespace OpenRA.Mods.RA.Activities public override Activity Tick(Actor self) { - if( moveFraction == 0 && IsCanceled ) return NextActivity; - if (!target.IsValid) return NextActivity; + if (moveFraction == 0 && IsCanceled) + return NextActivity; - self.Trait().IsLeaping = true; - var mobile = self.Trait(); - ++moveFraction; - - mobile.PxPosition = PPos.Lerp(initialLocation, target.PxPosition, moveFraction, delay); - - if (moveFraction >= delay) + mobile.AdjustPxPosition(self, PPos.Lerp(from, to, moveFraction++, length - 1)); + if (moveFraction >= length) { - self.TraitsImplementing().FirstOrDefault() - .SetPosition(self, target.CenterLocation.ToCPos()); + mobile.SetLocation(mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell); + mobile.FinishedMoving(self); + mobile.IsMoving = false; - if (target.IsActor) - target.Actor.Kill(self); - self.Trait().IsLeaping = false; + // Kill whatever else is in our new cell + self.World.ActorMap.GetUnitsAt(mobile.toCell, mobile.toSubCell).Except(new []{self}).Do(a => a.Kill(self)); return NextActivity; } diff --git a/OpenRA.Mods.RA/Attack/AttackLeap.cs b/OpenRA.Mods.RA/Attack/AttackLeap.cs index 613d1da196..0dbf477093 100644 --- a/OpenRA.Mods.RA/Attack/AttackLeap.cs +++ b/OpenRA.Mods.RA/Attack/AttackLeap.cs @@ -22,8 +22,6 @@ namespace OpenRA.Mods.RA class AttackLeap : AttackFrontal, ISync { - [Sync] internal bool IsLeaping; - public AttackLeap(Actor self, AttackLeapInfo info) : base(self, info) {} diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index ad75f3f9cf..2fd6c1b279 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -170,7 +170,9 @@ namespace OpenRA.Mods.RA.Move public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub) { - if (fromCell == from && toCell == to) return; + if (fromCell == from && toCell == to && fromSubCell == fromSub && toSubCell == toSub) + return; + RemoveInfluence(); __fromCell = from; __toCell = to;