Removed INudge in favor of INotifyBlockingMove.

This commit is contained in:
James Dunne
2012-06-24 19:27:57 -05:00
parent 1f0da42a15
commit 1fa70d259f
5 changed files with 23 additions and 27 deletions

View File

@@ -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
{

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA
public void WarnCrush(Actor crusher)
{
if (self.World.SharedRandom.Next(100) <= Info.WarnProbability)
self.Trait<Mobile>().OnNudge(self, crusher, true);
self.Trait<Mobile>().Nudge(self, crusher, true);
}
public void OnCrush(Actor crusher)

View File

@@ -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<Mobile>();
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);

View File

@@ -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)

View File

@@ -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<INudge>();
if (nudge != null)
nudge.OnNudge(blocker, self, false);
// Notify the blocker that he's blocking our move:
INotifyBlockingMove moveBlocked;
if ((moveBlocked = blocker.TraitOrDefault<INotifyBlockingMove>()) != null)
moveBlocked.OnNotifyBlockingMove(blocker, self, nextCell);
// Notify the blocker that he's blocking our move:
var moveBlocked = blocker.TraitOrDefault<INotifyBlockingMove>();
if (moveBlocked != null)
moveBlocked.OnNotifyBlockingMove(blocker, self);
}
}
Pair<CPos, SubCell>? 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 );