enum SubCell => int & Dictionary<SubCell, WVec> => WVec[]

This commit is contained in:
atlimit8
2014-07-29 08:33:46 -05:00
parent e3d85f29c9
commit 43478dd500
13 changed files with 41 additions and 46 deletions

View File

@@ -63,13 +63,12 @@ namespace OpenRA
public CPos Value(World world) { return value; } public CPos Value(World world) { return value; }
} }
public class SubCellInit : IActorInit<SubCell> public class SubCellInit : IActorInit<int>
{ {
[FieldFromYamlKey] public readonly int value = 0; [FieldFromYamlKey] public readonly int value = 0;
public SubCellInit() { } public SubCellInit() { }
public SubCellInit(int init) { value = init; } public SubCellInit(int init) { value = init; }
public SubCellInit(SubCell init) { value = (int)init; } public int Value(World world) { return value; }
public SubCell Value(World world) { return (SubCell)value; }
} }
public class CenterPositionInit : IActorInit<WPos> public class CenterPositionInit : IActorInit<WPos>

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Traits
{ {
WPos CenterPosition { get; } WPos CenterPosition { get; }
CPos TopLeft { get; } CPos TopLeft { get; }
IEnumerable<Pair<CPos, SubCell>> OccupiedCells(); IEnumerable<Pair<CPos, int>> OccupiedCells();
} }
public static class IOccupySpaceExts public static class IOccupySpaceExts

View File

@@ -29,15 +29,11 @@ namespace OpenRA.Traits
class InfluenceNode class InfluenceNode
{ {
public InfluenceNode Next; public InfluenceNode Next;
public SubCell SubCell; public int SubCell;
public Actor Actor; public Actor Actor;
} }
static readonly SubCell[] SubCells = static readonly int[] SubCells = { 1, 2, 3, 4, 5 };
{
SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
SubCell.BottomLeft, SubCell.BottomRight
};
readonly ActorMapInfo info; readonly ActorMapInfo info;
readonly Map map; readonly Map map;
@@ -79,13 +75,13 @@ namespace OpenRA.Traits
yield return i.Actor; yield return i.Actor;
} }
public IEnumerable<Actor> GetUnitsAt(CPos a, SubCell sub) public IEnumerable<Actor> GetUnitsAt(CPos a, int sub)
{ {
if (!map.Contains(a)) if (!map.Contains(a))
yield break; yield break;
for (var i = influence[a]; i != null; i = i.Next) for (var i = influence[a]; i != null; i = i.Next)
if (!i.Actor.Destroyed && (i.SubCell == sub || i.SubCell == SubCell.FullCell)) if (!i.Actor.Destroyed && (i.SubCell == sub || i.SubCell == 0))
yield return i.Actor; yield return i.Actor;
} }
@@ -97,7 +93,7 @@ namespace OpenRA.Traits
return SubCells.Any(b => !AnyUnitsAt(a, b)); return SubCells.Any(b => !AnyUnitsAt(a, b));
} }
public SubCell? FreeSubCell(CPos a) public int? FreeSubCell(CPos a)
{ {
if (!HasFreeSubCell(a)) if (!HasFreeSubCell(a))
return null; return null;
@@ -110,10 +106,10 @@ namespace OpenRA.Traits
return influence[a] != null; return influence[a] != null;
} }
public bool AnyUnitsAt(CPos a, SubCell sub) public bool AnyUnitsAt(CPos a, int sub)
{ {
for (var i = influence[a]; i != null; i = i.Next) for (var i = influence[a]; i != null; i = i.Next)
if (i.SubCell == sub || i.SubCell == SubCell.FullCell) if (i.SubCell == sub || i.SubCell == 0)
return true; return true;
return false; return false;

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Activities
var exitCell = ChooseExitCell(actor); var exitCell = ChooseExitCell(actor);
if (exitCell == null) if (exitCell == null)
{ {
foreach (var blocker in BlockedExitCells(actor).SelectMany(self.World.ActorMap.GetUnitsAt)) foreach (var blocker in BlockedExitCells(actor).SelectMany(p => self.World.ActorMap.GetUnitsAt(p)))
{ {
foreach (var nbm in blocker.TraitsImplementing<INotifyBlockingMove>()) foreach (var nbm in blocker.TraitsImplementing<INotifyBlockingMove>())
nbm.OnNotifyBlockingMove(blocker, self); nbm.OnNotifyBlockingMove(blocker, self);

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Air
public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld
{ {
static readonly Pair<CPos, SubCell>[] NoCells = { }; static readonly Pair<CPos, int>[] NoCells = { };
readonly AircraftInfo info; readonly AircraftInfo info;
readonly Actor self; readonly Actor self;
@@ -210,7 +210,7 @@ namespace OpenRA.Mods.RA.Air
} }
} }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return NoCells; } public IEnumerable<Pair<CPos, int>> OccupiedCells() { return NoCells; }
public WVec FlyStep(int facing) public WVec FlyStep(int facing)
{ {

View File

@@ -133,14 +133,14 @@ namespace OpenRA.Mods.RA.Buildings
this.Info = info; this.Info = info;
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft ) occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); .Select(c => Pair.New(c, 0)).ToArray();
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info); CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>(); SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
} }
Pair<CPos, SubCell>[] occupiedCells; Pair<CPos, int>[] occupiedCells;
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; } public IEnumerable<Pair<CPos, int>> OccupiedCells() { return occupiedCells; }
public void Created(Actor self) public void Created(Actor self)
{ {

View File

@@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA
} }
public CPos TopLeft { get { return Location; } } public CPos TopLeft { get { return Location; } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(Location, SubCell.FullCell); } public IEnumerable<Pair<CPos, int>> OccupiedCells() { yield return Pair.New(Location, 0); }
public WPos CenterPosition { get; private set; } public WPos CenterPosition { get; private set; }
public void SetPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); } public void SetPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); }

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA
self.QueueActivity(new Drag(CenterPosition, finalPos, distance / speed)); self.QueueActivity(new Drag(CenterPosition, finalPos, distance / speed));
} }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } public IEnumerable<Pair<CPos, int>> OccupiedCells() { yield return Pair.New(TopLeft, 0); }
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
{ {
if (!self.World.Map.Contains(cell)) if (!self.World.Map.Contains(cell))

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
{ {
[Sync] readonly CPos location; [Sync] readonly CPos location;
[Sync] readonly WPos position; [Sync] readonly WPos position;
readonly IEnumerable<Pair<CPos, SubCell>> occupied; readonly IEnumerable<Pair<CPos, int>> occupied;
public Immobile(ActorInitializer init, ImmobileInfo info) public Immobile(ActorInitializer init, ImmobileInfo info)
{ {
@@ -32,14 +32,14 @@ namespace OpenRA.Mods.RA
position = init.world.Map.CenterOfCell(location); position = init.world.Map.CenterOfCell(location);
if (info.OccupiesSpace) if (info.OccupiesSpace)
occupied = new [] { Pair.New(TopLeft, SubCell.FullCell) }; occupied = new [] { Pair.New(TopLeft, 0) };
else else
occupied = new Pair<CPos, SubCell>[0]; occupied = new Pair<CPos, int>[0];
} }
public CPos TopLeft { get { return location; } } public CPos TopLeft { get { return location; } }
public WPos CenterPosition { get { return position; } } public WPos CenterPosition { get { return position; } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupied; } public IEnumerable<Pair<CPos, int>> OccupiedCells() { return occupied; }
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {

View File

@@ -133,14 +133,14 @@ namespace OpenRA.Mods.RA.Move
return TilesetMovementClass[tileset]; return TilesetMovementClass[tileset];
} }
public static readonly Dictionary<SubCell, WVec> SubCellOffsets = new Dictionary<SubCell, WVec>() public static readonly WVec[] SubCellOffsets =
{ {
{SubCell.TopLeft, new WVec(-299, -256, 0)}, new WVec(0, 0, 0),
{SubCell.TopRight, new WVec(256, -256, 0)}, new WVec(-299, -256, 0),
{SubCell.Center, new WVec(0, 0, 0)}, new WVec(256, -256, 0),
{SubCell.BottomLeft, new WVec(-299, 256, 0)}, new WVec(0, 0, 0),
{SubCell.BottomRight, new WVec(256, 256, 0)}, new WVec(-299, 256, 0),
{SubCell.FullCell, new WVec(0, 0, 0)}, new WVec(256, 256, 0),
}; };
static bool IsMovingInMyDirection(Actor self, Actor other) static bool IsMovingInMyDirection(Actor self, Actor other)
@@ -208,7 +208,7 @@ namespace OpenRA.Mods.RA.Move
int __facing; int __facing;
CPos __fromCell, __toCell; CPos __fromCell, __toCell;
public SubCell fromSubCell, toSubCell; public int fromSubCell, toSubCell;
//int __altitude; //int __altitude;
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.RA.Move
[Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap. [Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub) public void SetLocation(CPos from, int fromSub, CPos to, int toSub)
{ {
if (fromCell == from && toCell == to && fromSubCell == fromSub && toSubCell == toSub) if (fromCell == from && toCell == to && fromSubCell == fromSub && toSubCell == toSub)
return; return;
@@ -248,10 +248,11 @@ namespace OpenRA.Mods.RA.Move
this.self = init.self; this.self = init.self;
this.Info = info; this.Info = info;
toSubCell = fromSubCell = info.SharesCell ? SubCell.Center : SubCell.FullCell; // TODO replace 3 w/ SubCellDefaultIndex
toSubCell = fromSubCell = info.SharesCell ? 3 : 0;
if (init.Contains<SubCellInit>()) if (init.Contains<SubCellInit>())
{ {
this.fromSubCell = this.toSubCell = init.Get<SubCellInit, SubCell>(); this.fromSubCell = this.toSubCell = init.Get<SubCellInit, int>();
} }
if (init.Contains<LocationInit>()) if (init.Contains<LocationInit>())
@@ -414,7 +415,7 @@ namespace OpenRA.Mods.RA.Move
public CPos TopLeft { get { return toCell; } } public CPos TopLeft { get { return toCell; } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() public IEnumerable<Pair<CPos, int>> OccupiedCells()
{ {
if (fromCell == toCell) if (fromCell == toCell)
yield return Pair.New(fromCell, fromSubCell); yield return Pair.New(fromCell, fromSubCell);
@@ -427,14 +428,13 @@ namespace OpenRA.Mods.RA.Move
} }
} }
public SubCell GetDesiredSubcell(CPos a, Actor ignoreActor) public int GetDesiredSubcell(CPos a, Actor ignoreActor)
{ {
if (!Info.SharesCell) if (!Info.SharesCell)
return SubCell.FullCell; return 0;
// Prioritise the current subcell // Prioritise the current subcell
return new[]{ fromSubCell, SubCell.TopLeft, SubCell.TopRight, SubCell.Center, return new[]{ fromSubCell, 1, 2, 3, 4, 5}.First(b =>
SubCell.BottomLeft, SubCell.BottomRight}.First(b =>
{ {
var blockingActors = self.World.ActorMap.GetUnitsAt(a, b).Where(c => c != ignoreActor); var blockingActors = self.World.ActorMap.GetUnitsAt(a, b).Where(c => c != ignoreActor);
if (blockingActors.Any()) if (blockingActors.Any())

View File

@@ -180,7 +180,7 @@ namespace OpenRA.Mods.RA.Move
} }
} }
Pair<CPos, SubCell>? PopPath(Actor self, Mobile mobile) Pair<CPos, int>? PopPath(Actor self, Mobile mobile)
{ {
if (path.Count == 0) if (path.Count == 0)
return null; return null;

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA.Move
} }
} }
public List<CPos> FindUnitPathToRange(CPos src, SubCell srcSub, WPos target, WRange range, Actor self) public List<CPos> FindUnitPathToRange(CPos src, int srcSub, WPos target, WRange range, Actor self)
{ {
using (new PerfSample("Pathfinder")) using (new PerfSample("Pathfinder"))
{ {

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA
throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s)); throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));
var cell = validCells.Random(w.SharedRandom); var cell = validCells.Random(w.SharedRandom);
var subCell = mi.SharesCell ? w.ActorMap.FreeSubCell(cell).Value : SubCell.FullCell; var subCell = mi.SharesCell ? w.ActorMap.FreeSubCell(cell).Value : 0;
w.CreateActor(s.ToLowerInvariant(), new TypeDictionary w.CreateActor(s.ToLowerInvariant(), new TypeDictionary
{ {