diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index d7b966e92d..5ef0602331 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -75,7 +75,6 @@ namespace OpenRA.Traits public interface IDisable { bool Disabled { get; } } public interface IExplodeModifier { bool ShouldExplode(Actor self); } public interface IHuskModifier { string HuskActor(Actor self); } - public interface INudge { void OnNudge(Actor self, Actor nudger, bool force); } public interface IRadarSignature { @@ -132,7 +131,7 @@ namespace OpenRA.Traits } public interface IMove : ITeleportable { int Altitude { get; set; } } - public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking, CPos cell); } + public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking); } public interface IFacing { diff --git a/OpenRA.Mods.RA/CrushableInfantry.cs b/OpenRA.Mods.RA/CrushableInfantry.cs index ef93503292..907e3148cb 100644 --- a/OpenRA.Mods.RA/CrushableInfantry.cs +++ b/OpenRA.Mods.RA/CrushableInfantry.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA public void WarnCrush(Actor crusher) { if (self.World.SharedRandom.Next(100) <= Info.WarnProbability) - self.Trait().OnNudge(self, crusher, true); + self.Trait().Nudge(self, crusher, true); } public void OnCrush(Actor crusher) diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 385bf5c459..a1aa65a180 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -159,16 +159,17 @@ namespace OpenRA.Mods.RA } } - public void OnNotifyBlockingMove(Actor self, Actor blocking, CPos cell) + public void OnNotifyBlockingMove(Actor self, Actor blocking) { // I'm blocking someone else from moving to my location: Activity act = self.GetCurrentActivity(); - // If I'm just waiting around, then get out of the way: + // If I'm just waiting around then get out of the way: if (act.GetType() == typeof(Wait)) { self.CancelActivity(); var mobile = self.Trait(); + var cell = self.Location; var moveTo = mobile.NearestMoveableCell(cell, 2, 5); self.QueueActivity(mobile.MoveTo(moveTo, 0)); self.SetTargetLine(Target.FromCell(moveTo), Color.Gray, false); diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 6344d604f1..6b68c8d1f4 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA.Move } } - public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IOccupySpace, IMove, IFacing, INudge, ISync + public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IOccupySpace, IMove, IFacing, ISync { public readonly Actor self; public readonly MobileInfo Info; @@ -280,7 +280,7 @@ namespace OpenRA.Mods.RA.Move self.CancelActivity(); if (order.OrderString == "Scatter") - OnNudge(self, self, true); + Nudge(self, self, true); } public string VoicePhraseForOrder(Actor self, Order order) @@ -392,7 +392,7 @@ namespace OpenRA.Mods.RA.Move self.World.ActorMap.Remove(self, this); } - public void OnNudge(Actor self, Actor nudger, bool force) + public void Nudge(Actor self, Actor nudger, bool force) { /* initial fairly braindead implementation. */ if (!force && self.Owner.Stances[nudger.Owner] != Stance.Ally) diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index 820ea0fcdf..1428961438 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -164,25 +164,21 @@ namespace OpenRA.Mods.RA.Move } bool hasWaited; - bool hasNudged; + bool hasNotifiedBlocker; int waitTicksRemaining; - void NudgeBlocker(Actor self, CPos nextCell) + void NotifyBlocker(Actor self, CPos nextCell) { - var blocker = self.World.ActorMap.GetUnitsAt(nextCell).FirstOrDefault(); - if (blocker == null) return; + foreach (var blocker in self.World.ActorMap.GetUnitsAt(nextCell)) + { + Log.Write("debug", "NotifyBlocker #{0} nudges #{1} at {2} from {3}", + self.ActorID, blocker.ActorID, nextCell, self.Location); - Log.Write("debug", "NudgeBlocker #{0} nudges #{1} at {2} from {3}", - self.ActorID, blocker.ActorID, nextCell, self.Location); - - var nudge = blocker.TraitOrDefault(); - if (nudge != null) - nudge.OnNudge(blocker, self, false); - - // Notify the blocker that he's blocking our move: - INotifyBlockingMove moveBlocked; - if ((moveBlocked = blocker.TraitOrDefault()) != null) - moveBlocked.OnNotifyBlockingMove(blocker, self, nextCell); + // Notify the blocker that he's blocking our move: + var moveBlocked = blocker.TraitOrDefault(); + if (moveBlocked != null) + moveBlocked.OnNotifyBlockingMove(blocker, self); + } } Pair? PopPath(Actor self, Mobile mobile) @@ -197,10 +193,10 @@ namespace OpenRA.Mods.RA.Move return null; } - if (!hasNudged) + if (!hasNotifiedBlocker) { - NudgeBlocker(self, nextCell); - hasNudged = true; + NotifyBlocker(self, nextCell); + hasNotifiedBlocker = true; } if (!hasWaited) @@ -228,7 +224,7 @@ namespace OpenRA.Mods.RA.Move return null; } - hasNudged = false; + hasNotifiedBlocker = false; hasWaited = false; path.RemoveAt( path.Count - 1 );