Changes to map.cs, rename IPositionable.IsLeaving{ => Cell}, add IPositionable.GetValidSubCell

This commit is contained in:
atlimit8
2014-08-24 02:54:49 -05:00
parent 63c28ee4d7
commit e29b9edfc1
13 changed files with 68 additions and 43 deletions

View File

@@ -80,8 +80,9 @@ namespace OpenRA
[FieldLoader.Ignore]
public readonly WVec[] SubCellOffsets;
public readonly SubCell DefaultSubCell;
public readonly SubCell LastSubCell;
public WVec OffsetOf(SubCell subCell) { return SubCellOffsets[(int)subCell]; }
public WVec OffsetOfSubCell(SubCell subCell) { return SubCellOffsets[(int)subCell]; }
[FieldLoader.LoadUsing("LoadOptions")]
public MapOptions Options;
@@ -252,6 +253,7 @@ namespace OpenRA
MapResources = Exts.Lazy(() => LoadResourceTiles());
TileShape = Game.modData.Manifest.TileShape;
SubCellOffsets = Game.modData.Manifest.SubCellOffsets;
LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
DefaultSubCell = (SubCell)Game.modData.Manifest.SubCellDefaultIndex;
// The Uid is calculated from the data on-disk, so
@@ -496,7 +498,7 @@ namespace OpenRA
return new WPos(512 * (cell.X - cell.Y + 1), 512 * (cell.X + cell.Y + 1), 0);
}
public WPos CenterOf(CPos cell, SubCell subCell)
public WPos CenterOfSubCell(CPos cell, SubCell subCell)
{
var index = (int)subCell;
if (index >= 0 && index <= SubCellOffsets.Length)

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Traits
public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; }
public static Target FromCell(World w, CPos c, SubCell subCell = SubCell.FullCell)
{
return new Target { pos = w.Map.CenterOf(c, subCell), type = TargetType.Terrain };
return new Target { pos = w.Map.CenterOfSubCell(c, subCell), type = TargetType.Terrain };
}
public static Target FromOrder(World w, Order o)

View File

@@ -180,9 +180,10 @@ namespace OpenRA.Traits
public interface IPositionable : IOccupySpace
{
bool IsLeaving(CPos location, SubCell subCell = SubCell.AnySubCell);
bool IsLeavingCell(CPos location, SubCell subCell = SubCell.AnySubCell);
bool CanEnterCell(CPos location, Actor ignoreActor = null, bool checkTransientActors = true);
SubCell GetAvailableSubcell(CPos location, SubCell preferredSubCell = SubCell.AnySubCell, Actor ignoreActor = null, bool checkTransientActors = true);
SubCell GetValidSubCell(SubCell preferred = SubCell.AnySubCell);
SubCell GetAvailableSubCell(CPos location, SubCell preferredSubCell = SubCell.AnySubCell, Actor ignoreActor = null, bool checkTransientActors = true);
void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.AnySubCell);
void SetPosition(Actor self, WPos pos);
void SetVisualPosition(Actor self, WPos pos);

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Traits
return SubCell.InvalidSubCell;
}
// NOTE: does not check transients, but checks aircraft
// NOTE: always includes transients with influence
public bool AnyUnitsAt(CPos a)
{
return influence[a] != null;
@@ -132,7 +132,7 @@ namespace OpenRA.Traits
if (checkTransient)
return true;
var pos = i.Actor.TraitOrDefault<IPositionable>();
if (pos == null || !pos.IsLeaving(a, i.SubCell))
if (pos == null || !pos.IsLeavingCell(a, i.SubCell))
return true;
}