diff --git a/OpenRA.Mods.RA/Crates/DuplicateUnitCrateAction.cs b/OpenRA.Mods.RA/Crates/DuplicateUnitCrateAction.cs index 797bdf6276..7e526969c1 100644 --- a/OpenRA.Mods.RA/Crates/DuplicateUnitCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/DuplicateUnitCrateAction.cs @@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Crates for (var i = -3; i < 4; i++) for (var j = -3; j < 4; j++) - if (mi.CanEnterCell(self.World, self, near + new CVec(i, j), null, true, true)) + if (mi.CanEnterCell(self.World, self, near + new CVec(i, j))) yield return near + new CVec(i, j); } diff --git a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs index b9f42d047f..360060f8a6 100644 --- a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs @@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA.Crates for (var i = -1; i < 2; i++) for (var j = -1; j < 2; j++) - if (mi.CanEnterCell(self.World, self, near + new CVec(i, j), null, true, true)) + if (mi.CanEnterCell(self.World, self, near + new CVec(i, j))) yield return near + new CVec(i, j); } diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 8fd1e6569c..f768946088 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -18,6 +18,15 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Move { + [Flags] + public enum CellConditions + { + None = 0, + TransientActors, + BlockedByMovers, + All = TransientActors | BlockedByMovers + }; + [Desc("Unit is able to move.")] public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, IMoveInfo, UsesInit, UsesInit, UsesInit { @@ -151,12 +160,22 @@ namespace OpenRA.Mods.RA.Move return true; } - public bool CanEnterCell(World world, CPos cell) + public bool CanEnterCell(World world, CPos cell, int subCell = -1, CellConditions check = CellConditions.All) { - return CanEnterCell(world, null, cell, null, true, true); + return CanEnterCell(world, null, cell, subCell, null, check); } - public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor, bool checkTransientActors, bool blockedByMovers) + public bool CanEnterCell(World world, Actor self, CPos cell, int subCell, CellConditions check) + { + return CanEnterCell(world, self, cell, subCell, null, check); + } + + public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor, CellConditions check = CellConditions.All) + { + return CanEnterCell(world, self, cell, -1, ignoreActor, check); + } + + public bool CanEnterCell(World world, Actor self, CPos cell, int subCell = -1, Actor ignoreActor = null, CellConditions check = CellConditions.All) { if (MovementCostForCell(world, cell) == int.MaxValue) return false; @@ -164,9 +183,9 @@ namespace OpenRA.Mods.RA.Move if (SharesCell && world.ActorMap.HasFreeSubCell(cell)) return true; - if (checkTransientActors) + if (check.HasFlag(CellConditions.TransientActors)) { - var canIgnoreMovingAllies = self != null && !blockedByMovers; + var canIgnoreMovingAllies = self != null && !check.HasFlag(CellConditions.BlockedByMovers); var needsCellExclusively = self == null || Crushes == null; foreach(var a in world.ActorMap.GetUnitsAt(cell)) { @@ -457,7 +476,7 @@ namespace OpenRA.Mods.RA.Move public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) { - return Info.CanEnterCell(self.World, self, cell, ignoreActor, checkTransientActors, true); + return Info.CanEnterCell(self.World, self, cell, ignoreActor, checkTransientActors ? CellConditions.All : CellConditions.BlockedByMovers); } public void EnteringCell(Actor self) diff --git a/OpenRA.Mods.RA/Move/PathFinder.cs b/OpenRA.Mods.RA/Move/PathFinder.cs index 6b09cf6892..dc19424d6b 100644 --- a/OpenRA.Mods.RA/Move/PathFinder.cs +++ b/OpenRA.Mods.RA/Move/PathFinder.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA.Move // This assumes that the SubCell does not change during the path traversal var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Range / 1024 + 1) .Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= rangeSquared - && mi.CanEnterCell(self.World, self, t, null, true, true)); + && mi.CanEnterCell(self.World, self, t)); // See if there is any cell within range that does not involve a cross-domain request // Really, we only need to check the circle perimeter, but it's not clear that would be a performance win diff --git a/OpenRA.Mods.RA/Move/PathSearch.cs b/OpenRA.Mods.RA/Move/PathSearch.cs index 93a3ccb2fb..ce23ab2b60 100755 --- a/OpenRA.Mods.RA/Move/PathSearch.cs +++ b/OpenRA.Mods.RA/Move/PathSearch.cs @@ -190,7 +190,7 @@ namespace OpenRA.Mods.RA.Move if (costHere == int.MaxValue) continue; - if (!mobileInfo.CanEnterCell(world, self, newHere, IgnoreBuilding, CheckForBlocked, false)) + if (!mobileInfo.CanEnterCell(world, self, newHere, IgnoreBuilding, CheckForBlocked ? CellConditions.TransientActors : CellConditions.None)) continue; if (customBlock != null && customBlock(newHere)) diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index 21745cf5c1..c08f01cbe1 100755 --- a/OpenRA.Mods.RA/Production.cs +++ b/OpenRA.Mods.RA/Production.cs @@ -136,7 +136,7 @@ namespace OpenRA.Mods.RA } return mobileInfo == null || - mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self, true, true); + mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self); } } }