Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Bib & footprint cells - part 1 #13561

Merged
merged 4 commits into from Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions OpenRA.Game/Traits/TraitsInterfaces.cs
Expand Up @@ -201,6 +201,11 @@ public interface IFogVisibilityModifier

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);
Expand Down
17 changes: 16 additions & 1 deletion OpenRA.Mods.Common/Traits/Buildings/Building.cs
Expand Up @@ -27,21 +27,30 @@ public class BuildingInfo : ITraitInfo, IOccupySpaceInfo, IPlaceBuildingDecorati
{
[Desc("Where you are allowed to place the building (Water, Clear, ...)")]
public readonly HashSet<string> TerrainTypes = new HashSet<string>();

[Desc("The range to the next building it can be constructed. Set it higher for walls.")]
public readonly int Adjacent = 2;

[Desc("x means space it blocks, _ is a part that is passable by actors.")]
public readonly string Footprint = "x";

public readonly CVec Dimensions = new CVec(1, 1);

public readonly bool RequiresBaseProvider = false;

public readonly bool AllowInvalidPlacement = false;

[Desc("Clear smudges from underneath the building footprint.")]
public readonly bool RemoveSmudgesOnBuild = true;

[Desc("Clear smudges from underneath the building footprint on sell.")]
public readonly bool RemoveSmudgesOnSell = true;

[Desc("Clear smudges from underneath the building footprint on transform.")]
public readonly bool RemoveSmudgesOnTransform = true;

public readonly string[] BuildSounds = { "placbldg.aud", "build5.aud" };

public readonly string[] UndeploySounds = { "cashturn.aud" };

public virtual object Create(ActorInitializer init) { return new Building(init, this); }
Expand Down Expand Up @@ -135,7 +144,7 @@ public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai,
}
}

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; }
Expand All @@ -144,6 +153,7 @@ public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, INot
public readonly bool SkipMakeAnimation;

Pair<CPos, SubCell>[] occupiedCells;
Pair<CPos, SubCell>[] targetableCells;

// Shared activity lock: undeploy, sell, capture, etc.
[Sync] public bool Locked = true;
Expand Down Expand Up @@ -171,12 +181,17 @@ public Building(ActorInitializer init, BuildingInfo info)
occupiedCells = FootprintUtils.UnpathableTiles(self.Info.Name, Info, TopLeft)
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();

targetableCells = FootprintUtils.UnpathableTiles(self.Info.Name, Info, TopLeft)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: This duplication is intended for now, #13553 will update this part as soon as this PR is merged.
This is primarily a measure to keep the diff of the next revision of #13553 in check, as code-wise that will be harder to review than this PR.

.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>())
Expand Down
8 changes: 4 additions & 4 deletions OpenRA.Mods.Common/Traits/HitShape.cs
Expand Up @@ -60,15 +60,15 @@ static object LoadShape(MiniYaml yaml)
public class HitShape : ConditionalTrait<HitShapeInfo>, ITargetablePositions
{
BodyOrientation orientation;
IOccupySpace occupy;
ITargetableCells targetableCells;

public HitShape(Actor self, HitShapeInfo info)
: base(info) { }

protected override void Created(Actor self)
{
orientation = self.Trait<BodyOrientation>();
occupy = self.TraitOrDefault<IOccupySpace>();
targetableCells = self.TraitOrDefault<ITargetableCells>();

base.Created(self);
}
Expand All @@ -78,8 +78,8 @@ public IEnumerable<WPos> TargetablePositions(Actor self)
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)
Expand Down