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 class SubCellInit : IActorInit<SubCell>
public class SubCellInit : IActorInit<int>
{
[FieldFromYamlKey] public readonly int value = 0;
public SubCellInit() { }
public SubCellInit(int init) { value = init; }
public SubCellInit(SubCell init) { value = (int)init; }
public SubCell Value(World world) { return (SubCell)value; }
public int Value(World world) { return value; }
}
public class CenterPositionInit : IActorInit<WPos>

View File

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

View File

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

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Activities
var exitCell = ChooseExitCell(actor);
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>())
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
{
static readonly Pair<CPos, SubCell>[] NoCells = { };
static readonly Pair<CPos, int>[] NoCells = { };
readonly AircraftInfo info;
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)
{

View File

@@ -133,14 +133,14 @@ namespace OpenRA.Mods.RA.Buildings
this.Info = info;
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);
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
}
Pair<CPos, SubCell>[] occupiedCells;
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
Pair<CPos, int>[] occupiedCells;
public IEnumerable<Pair<CPos, int>> OccupiedCells() { return occupiedCells; }
public void Created(Actor self)
{

View File

@@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA
}
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 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));
}
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)
{
if (!self.World.Map.Contains(cell))

View File

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

View File

@@ -133,14 +133,14 @@ namespace OpenRA.Mods.RA.Move
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)},
{SubCell.TopRight, new WVec(256, -256, 0)},
{SubCell.Center, new WVec(0, 0, 0)},
{SubCell.BottomLeft, new WVec(-299, 256, 0)},
{SubCell.BottomRight, new WVec(256, 256, 0)},
{SubCell.FullCell, new WVec(0, 0, 0)},
new WVec(0, 0, 0),
new WVec(-299, -256, 0),
new WVec(256, -256, 0),
new WVec(0, 0, 0),
new WVec(-299, 256, 0),
new WVec(256, 256, 0),
};
static bool IsMovingInMyDirection(Actor self, Actor other)
@@ -208,7 +208,7 @@ namespace OpenRA.Mods.RA.Move
int __facing;
CPos __fromCell, __toCell;
public SubCell fromSubCell, toSubCell;
public int fromSubCell, toSubCell;
//int __altitude;
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.RA.Move
[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)
return;
@@ -248,10 +248,11 @@ namespace OpenRA.Mods.RA.Move
this.self = init.self;
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>())
{
this.fromSubCell = this.toSubCell = init.Get<SubCellInit, SubCell>();
this.fromSubCell = this.toSubCell = init.Get<SubCellInit, int>();
}
if (init.Contains<LocationInit>())
@@ -414,7 +415,7 @@ namespace OpenRA.Mods.RA.Move
public CPos TopLeft { get { return toCell; } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells()
public IEnumerable<Pair<CPos, int>> OccupiedCells()
{
if (fromCell == toCell)
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)
return SubCell.FullCell;
return 0;
// Prioritise the current subcell
return new[]{ fromSubCell, SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
SubCell.BottomLeft, SubCell.BottomRight}.First(b =>
return new[]{ fromSubCell, 1, 2, 3, 4, 5}.First(b =>
{
var blockingActors = self.World.ActorMap.GetUnitsAt(a, b).Where(c => c != ignoreActor);
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)
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"))
{

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA
throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));
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
{