add INudge interface; Move tries to nudge things that are in the way as a good first option

This commit is contained in:
Chris Forbes
2010-07-21 19:24:45 +12:00
parent 2f9f539857
commit e426d50cc2
2 changed files with 19 additions and 0 deletions

View File

@@ -151,8 +151,19 @@ namespace OpenRA.Traits.Activities
}
bool hasWaited;
bool hasNudged;
int waitTicksRemaining;
void NudgeBlocker(Actor self, int2 nextCell)
{
var blocker = self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(nextCell).FirstOrDefault();
if (blocker == null) return;
var nudge = blocker.traits.GetOrDefault<INudge>();
if (nudge != null)
nudge.OnNudge(blocker);
}
int2? PopPath( Actor self, Mobile mobile )
{
if( path.Count == 0 ) return null;
@@ -165,6 +176,12 @@ namespace OpenRA.Traits.Activities
return null;
}
if (!hasNudged)
{
NudgeBlocker(self, nextCell);
hasNudged = true;
}
if (!hasWaited)
{
var info = self.Info.Traits.Get<MobileInfo>();
@@ -187,6 +204,7 @@ namespace OpenRA.Traits.Activities
return null;
}
hasNudged = false;
hasWaited = false;
path.RemoveAt( path.Count - 1 );
return nextCell;

View File

@@ -53,6 +53,7 @@ namespace OpenRA.Traits
public interface IDisable { bool Disabled { get; } }
public interface IExplodeModifier { bool ShouldExplode(Actor self); }
public interface INudge { bool OnNudge(Actor self); }
public interface IOccupySpace
{