Add ITargetableCells interface

This commit is contained in:
reaperrr
2017-06-08 00:32:42 +02:00
parent 69aa4f5962
commit 9b137afa6d
3 changed files with 16 additions and 5 deletions

View File

@@ -201,6 +201,11 @@ namespace OpenRA.Traits
public interface IRadarColorModifier { Color RadarColorOverride(Actor self, Color color); }
public interface ITargetableCells
{
IEnumerable<Pair<CPos, SubCell>> TargetableCells();
}
public interface IOccupySpaceInfo : ITraitInfoInterface
{
IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any);

View File

@@ -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<CPos, SubCell>[] occupiedCells;
Pair<CPos, SubCell>[] 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<SkipMakeAnimsInit>();
}
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
public IEnumerable<Pair<CPos, SubCell>> TargetableCells() { return targetableCells; }
void INotifyCreated.Created(Actor self)
{
if (SkipMakeAnimation || !self.Info.HasTraitInfo<WithMakeAnimationInfo>())

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
public class HitShape : ConditionalTrait<HitShapeInfo>, 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<BodyOrientation>();
occupy = self.TraitOrDefault<IOccupySpace>();
targetableCells = self.TraitOrDefault<ITargetableCells>();
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)