diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 692b44a457..bb5a4efff4 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -201,6 +201,11 @@ namespace OpenRA.Traits public interface IRadarColorModifier { Color RadarColorOverride(Actor self, Color color); } + public interface ITargetableCells + { + IEnumerable> TargetableCells(); + } + public interface IOccupySpaceInfo : ITraitInfoInterface { IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any); diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index 06a14d906a..dc2af54558 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Traits } } - public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld + public class Building : IOccupySpace, ITargetableCells, INotifySold, INotifyTransform, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld { public readonly BuildingInfo Info; public bool BuildComplete { get; private set; } @@ -153,6 +153,7 @@ namespace OpenRA.Mods.Common.Traits public readonly bool SkipMakeAnimation; Pair[] occupiedCells; + Pair[] targetableCells; // Shared activity lock: undeploy, sell, capture, etc. [Sync] public bool Locked = true; @@ -180,12 +181,17 @@ namespace OpenRA.Mods.Common.Traits occupiedCells = FootprintUtils.UnpathableTiles(self.Info.Name, Info, TopLeft) .Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); + targetableCells = FootprintUtils.UnpathableTiles(self.Info.Name, Info, TopLeft) + .Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); + CenterPosition = init.World.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.World, Info); SkipMakeAnimation = init.Contains(); } public IEnumerable> OccupiedCells() { return occupiedCells; } + public IEnumerable> TargetableCells() { return targetableCells; } + void INotifyCreated.Created(Actor self) { if (SkipMakeAnimation || !self.Info.HasTraitInfo()) diff --git a/OpenRA.Mods.Common/Traits/HitShape.cs b/OpenRA.Mods.Common/Traits/HitShape.cs index 9d1313a953..3cd7aca20c 100644 --- a/OpenRA.Mods.Common/Traits/HitShape.cs +++ b/OpenRA.Mods.Common/Traits/HitShape.cs @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits public class HitShape : ConditionalTrait, ITargetablePositions { BodyOrientation orientation; - IOccupySpace occupy; + ITargetableCells targetableCells; public HitShape(Actor self, HitShapeInfo info) : base(info) { } @@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits protected override void Created(Actor self) { orientation = self.Trait(); - occupy = self.TraitOrDefault(); + targetableCells = self.TraitOrDefault(); base.Created(self); } @@ -78,8 +78,8 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled) yield break; - if (Info.UseOccupiedCellsOffsets && occupy != null) - foreach (var c in occupy.OccupiedCells()) + if (Info.UseOccupiedCellsOffsets && targetableCells != null) + foreach (var c in targetableCells.TargetableCells()) yield return self.World.Map.CenterOfCell(c.First); foreach (var o in Info.TargetableOffsets)