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 IRadarColorModifier { Color RadarColorOverride(Actor self, Color color); }
public interface ITargetableCells
{
IEnumerable<Pair<CPos, SubCell>> TargetableCells();
}
public interface IOccupySpaceInfo : ITraitInfoInterface public interface IOccupySpaceInfo : ITraitInfoInterface
{ {
IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any); 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 readonly BuildingInfo Info;
public bool BuildComplete { get; private set; } public bool BuildComplete { get; private set; }
@@ -153,6 +153,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool SkipMakeAnimation; public readonly bool SkipMakeAnimation;
Pair<CPos, SubCell>[] occupiedCells; Pair<CPos, SubCell>[] occupiedCells;
Pair<CPos, SubCell>[] targetableCells;
// Shared activity lock: undeploy, sell, capture, etc. // Shared activity lock: undeploy, sell, capture, etc.
[Sync] public bool Locked = true; [Sync] public bool Locked = true;
@@ -180,12 +181,17 @@ namespace OpenRA.Mods.Common.Traits
occupiedCells = FootprintUtils.UnpathableTiles(self.Info.Name, Info, TopLeft) occupiedCells = FootprintUtils.UnpathableTiles(self.Info.Name, Info, TopLeft)
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); .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); CenterPosition = init.World.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.World, Info);
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>(); SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
} }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; } public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
public IEnumerable<Pair<CPos, SubCell>> TargetableCells() { return targetableCells; }
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
if (SkipMakeAnimation || !self.Info.HasTraitInfo<WithMakeAnimationInfo>()) if (SkipMakeAnimation || !self.Info.HasTraitInfo<WithMakeAnimationInfo>())

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
public class HitShape : ConditionalTrait<HitShapeInfo>, ITargetablePositions public class HitShape : ConditionalTrait<HitShapeInfo>, ITargetablePositions
{ {
BodyOrientation orientation; BodyOrientation orientation;
IOccupySpace occupy; ITargetableCells targetableCells;
public HitShape(Actor self, HitShapeInfo info) public HitShape(Actor self, HitShapeInfo info)
: base(info) { } : base(info) { }
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
orientation = self.Trait<BodyOrientation>(); orientation = self.Trait<BodyOrientation>();
occupy = self.TraitOrDefault<IOccupySpace>(); targetableCells = self.TraitOrDefault<ITargetableCells>();
base.Created(self); base.Created(self);
} }
@@ -78,8 +78,8 @@ namespace OpenRA.Mods.Common.Traits
if (IsTraitDisabled) if (IsTraitDisabled)
yield break; yield break;
if (Info.UseOccupiedCellsOffsets && occupy != null) if (Info.UseOccupiedCellsOffsets && targetableCells != null)
foreach (var c in occupy.OccupiedCells()) foreach (var c in targetableCells.TargetableCells())
yield return self.World.Map.CenterOfCell(c.First); yield return self.World.Map.CenterOfCell(c.First);
foreach (var o in Info.TargetableOffsets) foreach (var o in Info.TargetableOffsets)