Add IPositionable.CanExistInCell

This is like CanEnterCell, but doesn't take into account conflicting
actors, etc.
This commit is contained in:
Chris Forbes
2018-04-06 20:37:56 -07:00
committed by abcdefg30
parent fba08cd066
commit dddd057e3d
6 changed files with 32 additions and 6 deletions

View File

@@ -81,15 +81,23 @@ namespace OpenRA.Mods.Common.Traits
self.QueueActivity(new Drag(self, CenterPosition, finalPosition, distance / dragSpeed));
}
public bool CanExistInCell(CPos cell)
{
if (!self.World.Map.Contains(cell))
return false;
if (!info.AllowedTerrain.Contains(self.World.Map.GetTerrainInfo(cell).Type))
return false;
return true;
}
public Pair<CPos, SubCell>[] OccupiedCells() { return new[] { Pair.New(TopLeft, SubCell.FullCell) }; }
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return false; }
public SubCell GetValidSubCell(SubCell preferred = SubCell.Any) { return SubCell.FullCell; }
public SubCell GetAvailableSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
{
if (!self.World.Map.Contains(cell))
return SubCell.Invalid;
if (!info.AllowedTerrain.Contains(self.World.Map.GetTerrainInfo(cell).Type))
if (!CanExistInCell(cell))
return SubCell.Invalid;
if (!checkTransientActors)