Skip to content
Browse files

Path planning no longer considers moving friendly units as blockers.

  • Loading branch information...
1 parent 3d8e215 commit 9c9a16d80e01142c6a430a12a9605d4edb6471cc @JamesDunne JamesDunne committed Jul 5, 2012
View
2 OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs
@@ -66,7 +66,7 @@ IEnumerable<CPos> GetSuitableCells(CPos near)
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)
- if (mi.CanEnterCell(self.World, self.Owner, near + new CVec(i, j), null, true))
+ if (mi.CanEnterCell(self.World, self.Owner, near + new CVec(i, j), null, true, true))
yield return near + new CVec(i, j);
}
View
13 OpenRA.Mods.RA/Move/Mobile.cs
@@ -77,23 +77,28 @@ public int MovementCostForCell(World world, CPos cell)
{SubCell.FullCell, new PVecInt(0,0)},
};
- public bool CanEnterCell(World world, Player owner, CPos cell, Actor ignoreActor, bool checkTransientActors)
+ public bool CanEnterCell(World world, Player owner, CPos cell, Actor ignoreActor, bool checkTransientActors, bool blockedByMovers)
{
if (MovementCostForCell(world, cell) == int.MaxValue)
return false;
if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
return true;
- var blockingActors = world.ActorMap.GetUnitsAt(cell).Where(x => x != ignoreActor).ToList();
+ var blockingActors = world.ActorMap.GetUnitsAt(cell)
+ .Where(x => x != ignoreActor)
+ // Neutral/enemy units are blockers. Allied units that are moving are not blockers.
+ .Where(x => blockedByMovers || ((owner.Stances[x.Owner] != Stance.Ally) || !x.IsMoving()))
+ .ToList();
+
if (checkTransientActors && blockingActors.Count > 0)
{
// Non-sharable unit can enter a cell with shareable units only if it can crush all of them
if (Crushes == null)
return false;
if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() &&
- a.TraitsImplementing<ICrushable>().Any(b => b.CrushableBy(Crushes, owner)))))
+ a.TraitsImplementing<ICrushable>().Any(b => b.CrushableBy(Crushes, owner)))))
return false;
}
@@ -342,7 +347,7 @@ public bool CanEnterCell(CPos p)
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
{
- return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors);
+ return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors, true);
}
public void EnteringCell(Actor self)
View
19 OpenRA.Mods.RA/Move/Move.cs
@@ -388,4 +388,23 @@ protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
}
}
}
+
+ public static class ActorExtensionsForMove
+ {
+ public static bool IsMoving(this Actor self)
+ {
+ if (self.IsIdle) return false;
+
+ Activity a = self.GetCurrentActivity();
+ Debug.Assert(a != null);
+
+ // Dirty, but it suffices until we do something better:
+ if (a.GetType() == typeof(Move)) return true;
+ if (a.GetType() == typeof(MoveAdjacentTo)) return true;
+ if (a.GetType() == typeof(AttackMove)) return true;
+
+ // Not a move:
+ return false;
+ }
+ }
}
View
2 OpenRA.Mods.RA/Move/PathFinder.cs
@@ -73,7 +73,7 @@ public List<CPos> FindUnitPathToRange(CPos src, CPos target, int range, Actor se
{
var mi = self.Info.Traits.Get<MobileInfo>();
var tilesInRange = world.FindTilesInCircle(target, range)
- .Where(t => mi.CanEnterCell(self.World, self.Owner, t, null, true));
+ .Where(t => mi.CanEnterCell(self.World, self.Owner, t, null, true, true));
var path = FindBidiPath(
PathSearch.FromPoints(world, mi, self.Owner, tilesInRange, src, true),
View
2 OpenRA.Mods.RA/Move/PathSearch.cs
@@ -120,7 +120,7 @@ public CPos Expand(World world)
if (costHere == int.MaxValue)
continue;
- if (!mobileInfo.CanEnterCell(world, owner, newHere, ignoreBuilding, checkForBlocked))
+ if (!mobileInfo.CanEnterCell(world, owner, newHere, ignoreBuilding, checkForBlocked, false))
continue;
if (customBlock != null && customBlock(newHere))
View
2 OpenRA.Mods.RA/Production.cs
@@ -129,7 +129,7 @@ static bool CanUseExit(Actor self, ActorInfo producee, ExitInfo s)
var mobileInfo = producee.Traits.GetOrDefault<MobileInfo>();
return mobileInfo == null ||
- mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCellVector, self, true);
+ mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCellVector, self, true, true);
}
}
}

0 comments on commit 9c9a16d

Please sign in to comment.
Something went wrong with that request. Please try again.