From 43478dd500566ae96c43347e806be27c5ab6b4ba Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Tue, 29 Jul 2014 08:33:46 -0500 Subject: [PATCH] enum SubCell => int & Dictionary => WVec[] --- OpenRA.Game/Map/ActorInitializer.cs | 5 ++-- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRA.Game/Traits/World/ActorMap.cs | 18 ++++++------- OpenRA.Mods.RA/Activities/UnloadCargo.cs | 2 +- OpenRA.Mods.RA/Air/Aircraft.cs | 4 +-- OpenRA.Mods.RA/Buildings/Building.cs | 6 ++--- OpenRA.Mods.RA/Crate.cs | 2 +- OpenRA.Mods.RA/Husk.cs | 2 +- OpenRA.Mods.RA/Immobile.cs | 8 +++--- OpenRA.Mods.RA/Move/Mobile.cs | 32 ++++++++++++------------ OpenRA.Mods.RA/Move/Move.cs | 2 +- OpenRA.Mods.RA/Move/PathFinder.cs | 2 +- OpenRA.Mods.RA/SpawnMPUnits.cs | 2 +- 13 files changed, 41 insertions(+), 46 deletions(-) diff --git a/OpenRA.Game/Map/ActorInitializer.cs b/OpenRA.Game/Map/ActorInitializer.cs index 1ce7eeb80f..f1811ec833 100755 --- a/OpenRA.Game/Map/ActorInitializer.cs +++ b/OpenRA.Game/Map/ActorInitializer.cs @@ -63,13 +63,12 @@ namespace OpenRA public CPos Value(World world) { return value; } } - public class SubCellInit : IActorInit + public class SubCellInit : IActorInit { [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 diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 0f4193a349..d4fbdf7b56 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -126,7 +126,7 @@ namespace OpenRA.Traits { WPos CenterPosition { get; } CPos TopLeft { get; } - IEnumerable> OccupiedCells(); + IEnumerable> OccupiedCells(); } public static class IOccupySpaceExts diff --git a/OpenRA.Game/Traits/World/ActorMap.cs b/OpenRA.Game/Traits/World/ActorMap.cs index b31f331077..e9f73b95ce 100644 --- a/OpenRA.Game/Traits/World/ActorMap.cs +++ b/OpenRA.Game/Traits/World/ActorMap.cs @@ -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 GetUnitsAt(CPos a, SubCell sub) + public IEnumerable 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; diff --git a/OpenRA.Mods.RA/Activities/UnloadCargo.cs b/OpenRA.Mods.RA/Activities/UnloadCargo.cs index d331c8c75e..7a28a47b2d 100644 --- a/OpenRA.Mods.RA/Activities/UnloadCargo.cs +++ b/OpenRA.Mods.RA/Activities/UnloadCargo.cs @@ -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()) nbm.OnNotifyBlockingMove(blocker, self); diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index ac8273845a..55964bdfee 100644 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Air public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld { - static readonly Pair[] NoCells = { }; + static readonly Pair[] NoCells = { }; readonly AircraftInfo info; readonly Actor self; @@ -210,7 +210,7 @@ namespace OpenRA.Mods.RA.Air } } - public IEnumerable> OccupiedCells() { return NoCells; } + public IEnumerable> OccupiedCells() { return NoCells; } public WVec FlyStep(int facing) { diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 209f6df6b7..2106094c75 100644 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -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(); } - Pair[] occupiedCells; - public IEnumerable> OccupiedCells() { return occupiedCells; } + Pair[] occupiedCells; + public IEnumerable> OccupiedCells() { return occupiedCells; } public void Created(Actor self) { diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index f7df5848c6..30d57614f8 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA } public CPos TopLeft { get { return Location; } } - public IEnumerable> OccupiedCells() { yield return Pair.New(Location, SubCell.FullCell); } + public IEnumerable> 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)); } diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index aabf691e5a..42cc49e1af 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA self.QueueActivity(new Drag(CenterPosition, finalPos, distance / speed)); } - public IEnumerable> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } + public IEnumerable> OccupiedCells() { yield return Pair.New(TopLeft, 0); } public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) { if (!self.World.Map.Contains(cell)) diff --git a/OpenRA.Mods.RA/Immobile.cs b/OpenRA.Mods.RA/Immobile.cs index 63570e95a8..2042d31c44 100644 --- a/OpenRA.Mods.RA/Immobile.cs +++ b/OpenRA.Mods.RA/Immobile.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA { [Sync] readonly CPos location; [Sync] readonly WPos position; - readonly IEnumerable> occupied; + readonly IEnumerable> 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[0]; + occupied = new Pair[0]; } public CPos TopLeft { get { return location; } } public WPos CenterPosition { get { return position; } } - public IEnumerable> OccupiedCells() { return occupied; } + public IEnumerable> OccupiedCells() { return occupied; } public void AddedToWorld(Actor self) { diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 9050e7fe6f..fc334bc06c 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -133,14 +133,14 @@ namespace OpenRA.Mods.RA.Move return TilesetMovementClass[tileset]; } - public static readonly Dictionary SubCellOffsets = new Dictionary() + 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()) { - this.fromSubCell = this.toSubCell = init.Get(); + this.fromSubCell = this.toSubCell = init.Get(); } if (init.Contains()) @@ -414,7 +415,7 @@ namespace OpenRA.Mods.RA.Move public CPos TopLeft { get { return toCell; } } - public IEnumerable> OccupiedCells() + public IEnumerable> 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()) diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index 265fdb3076..5dc077a58d 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -180,7 +180,7 @@ namespace OpenRA.Mods.RA.Move } } - Pair? PopPath(Actor self, Mobile mobile) + Pair? PopPath(Actor self, Mobile mobile) { if (path.Count == 0) return null; diff --git a/OpenRA.Mods.RA/Move/PathFinder.cs b/OpenRA.Mods.RA/Move/PathFinder.cs index abaeb49b74..ead53ad4f0 100644 --- a/OpenRA.Mods.RA/Move/PathFinder.cs +++ b/OpenRA.Mods.RA/Move/PathFinder.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA.Move } } - public List FindUnitPathToRange(CPos src, SubCell srcSub, WPos target, WRange range, Actor self) + public List FindUnitPathToRange(CPos src, int srcSub, WPos target, WRange range, Actor self) { using (new PerfSample("Pathfinder")) { diff --git a/OpenRA.Mods.RA/SpawnMPUnits.cs b/OpenRA.Mods.RA/SpawnMPUnits.cs index f97f43a318..a0df13ee48 100644 --- a/OpenRA.Mods.RA/SpawnMPUnits.cs +++ b/OpenRA.Mods.RA/SpawnMPUnits.cs @@ -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 {