Refactor MobileInfo.CanEnterCell
This commit is contained in:
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Crates
|
|||||||
|
|
||||||
for (var i = -3; i < 4; i++)
|
for (var i = -3; i < 4; i++)
|
||||||
for (var j = -3; j < 4; j++)
|
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);
|
yield return near + new CVec(i, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA.Crates
|
|||||||
|
|
||||||
for (var i = -1; i < 2; i++)
|
for (var i = -1; i < 2; i++)
|
||||||
for (var j = -1; j < 2; j++)
|
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);
|
yield return near + new CVec(i, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,15 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.RA.Move
|
namespace OpenRA.Mods.RA.Move
|
||||||
{
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum CellConditions
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
TransientActors,
|
||||||
|
BlockedByMovers,
|
||||||
|
All = TransientActors | BlockedByMovers
|
||||||
|
};
|
||||||
|
|
||||||
[Desc("Unit is able to move.")]
|
[Desc("Unit is able to move.")]
|
||||||
public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, IMoveInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
|
public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, IMoveInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
|
||||||
{
|
{
|
||||||
@@ -151,12 +160,22 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
return true;
|
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)
|
if (MovementCostForCell(world, cell) == int.MaxValue)
|
||||||
return false;
|
return false;
|
||||||
@@ -164,9 +183,9 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
|
if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
|
||||||
return true;
|
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;
|
var needsCellExclusively = self == null || Crushes == null;
|
||||||
foreach(var a in world.ActorMap.GetUnitsAt(cell))
|
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)
|
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)
|
public void EnteringCell(Actor self)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
// This assumes that the SubCell does not change during the path traversal
|
// This assumes that the SubCell does not change during the path traversal
|
||||||
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Range / 1024 + 1)
|
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Range / 1024 + 1)
|
||||||
.Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= rangeSquared
|
.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
|
// 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
|
// Really, we only need to check the circle perimeter, but it's not clear that would be a performance win
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
if (costHere == int.MaxValue)
|
if (costHere == int.MaxValue)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!mobileInfo.CanEnterCell(world, self, newHere, IgnoreBuilding, CheckForBlocked, false))
|
if (!mobileInfo.CanEnterCell(world, self, newHere, IgnoreBuilding, CheckForBlocked ? CellConditions.TransientActors : CellConditions.None))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (customBlock != null && customBlock(newHere))
|
if (customBlock != null && customBlock(newHere))
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
|
|
||||||
return mobileInfo == null ||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user