diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index d8166e0d18..ad69d416df 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -180,7 +180,7 @@ namespace OpenRA.Traits public interface IPositionable : IOccupySpace { - bool IsMovingFrom(CPos location, int subCell = -1); + bool IsLeaving(CPos location, int subCell = -1); bool CanEnterCell(CPos location, Actor ignoreActor = null, bool checkTransientActors = true); int GetAvailableSubcell(CPos location, int preferredSubCell = -1, Actor ignoreActor = null, bool checkTransientActors = true); void SetPosition(Actor self, CPos cell, int subCell = -1); diff --git a/OpenRA.Game/Traits/World/ActorMap.cs b/OpenRA.Game/Traits/World/ActorMap.cs index 8f85db0e15..3db51d70ef 100644 --- a/OpenRA.Game/Traits/World/ActorMap.cs +++ b/OpenRA.Game/Traits/World/ActorMap.cs @@ -14,8 +14,6 @@ using System.Linq; namespace OpenRA.Traits { - public enum SubCell { FullCell, TopLeft, TopRight, Center, BottomLeft, BottomRight } - public class ActorMapInfo : ITraitInfo { [Desc("Size of partition bins (cells)")] @@ -131,7 +129,7 @@ namespace OpenRA.Traits if (checkTransient) return true; var pos = i.Actor.TraitOrDefault(); - if (pos == null || !pos.IsMovingFrom(a, i.SubCell)) + if (pos == null || !pos.IsLeaving(a, i.SubCell)) return true; } diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index 83aa1db45d..007d301261 100644 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -199,7 +199,7 @@ namespace OpenRA.Mods.RA.Air || info.RepairBuildings.Contains(a.Info.Name); } - public bool IsMovingFrom(CPos location, int subCell = -1) { return false; } // TODO: handle landing + public bool IsLeaving(CPos location, int subCell = -1) { return false; } // TODO: handle landing public int GetAvailableSubcell(CPos a, int preferredSubCell = -1, Actor ignoreActor = null, bool checkTransientActors = true) { return -1; } // does not use any subcell public bool CanEnterCell(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true) { return true; } diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 4f41200196..15217152b2 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA public void SetPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); } public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); } - public bool IsMovingFrom(CPos location, int subCell = -1) { return false; } + public bool IsLeaving(CPos location, int subCell = -1) { return self.Location == location && ticks + 1 == info.Lifetime * 25; } public int GetAvailableSubcell(CPos cell, int preferredSubCell = -1, Actor ignoreActor = null, bool checkTransientActors = true) { if (!self.World.Map.Contains(cell)) return -1; diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index 19d3fe37a1..9243ec87ab 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA } public IEnumerable> OccupiedCells() { yield return Pair.New(TopLeft, 0); } - public bool IsMovingFrom(CPos location, int subCell = -1) { return false; } + public bool IsLeaving(CPos location, int subCell = -1) { return false; } public int GetAvailableSubcell(CPos cell, int preferredSubCell = -1, Actor ignoreActor = null, bool checkTransientActors = true) { if (!self.World.Map.Contains(cell)) diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 6785875d8d..72b4506df2 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -160,22 +160,7 @@ namespace OpenRA.Mods.RA.Move return true; } - public bool CanEnterCell(World world, CPos cell, int subCell = -1, CellConditions check = CellConditions.All) - { - return CanEnterCell(world, null, cell, subCell, null, check); - } - - public bool CanEnterCell(World world, Actor self, CPos cell, int subCell, CellConditions check) - { - return CanEnterCell(world, self, cell, subCell, null, check); - } - - public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor, CellConditions check = CellConditions.All) - { - return CanEnterCell(world, self, cell, -1, ignoreActor, check); - } - - public bool CanEnterCell(World world, Actor self, CPos cell, int subCell = -1, Actor ignoreActor = null, CellConditions check = CellConditions.All) + public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, CellConditions check = CellConditions.All) { if (MovementCostForCell(world, cell) == int.MaxValue) return false; @@ -318,9 +303,17 @@ namespace OpenRA.Mods.RA.Move public void SetPosition(Actor self, CPos cell, int subCell = -1) { - SetLocation(cell, fromSubCell, cell, fromSubCell); - SetVisualPosition(self, self.World.Map.CenterOfCell(fromCell) - + self.World.Map.SubCellOffsets[subCell >= 0 ? subCell : fromSubCell]); + // Try same sub-cell + if (subCell < 0) + subCell = fromSubCell; + + // Fix sub-cell assignment + if (Info.SharesCell != (subCell != 0)) + subCell = Info.SharesCell ? self.World.Map.SubCellDefaultIndex : 0; + + SetLocation(cell, subCell, cell, subCell); + SetVisualPosition(self, self.World.Map.CenterOfCell(cell) + + self.World.Map.SubCellOffsets[subCell]); FinishedMoving(self); } @@ -476,7 +469,7 @@ namespace OpenRA.Mods.RA.Move } } - public bool IsMovingFrom(CPos location, int subCell = -1) + public bool IsLeaving(CPos location, int subCell = -1) { return toCell != location && __fromCell == location && (subCell == -1 || fromSubCell == subCell || subCell == 0 || fromSubCell == 0); diff --git a/OpenRA.Mods.RA/SpawnMPUnits.cs b/OpenRA.Mods.RA/SpawnMPUnits.cs index 58b5a2b46e..13dea80636 100644 --- a/OpenRA.Mods.RA/SpawnMPUnits.cs +++ b/OpenRA.Mods.RA/SpawnMPUnits.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA foreach (var s in unitGroup.SupportActors) { var mi = w.Map.Rules.Actors[s.ToLowerInvariant()].Traits.Get(); - var validCells = supportSpawnCells.Where(c => mi.CanEnterCell(w, c)); + var validCells = supportSpawnCells.Where(c => mi.CanEnterCell(w, null, c)); if (!validCells.Any()) throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));