diff --git a/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs index ae80d16913..9d1c757cd6 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithWallSpriteBody.cs @@ -68,12 +68,19 @@ namespace OpenRA.Mods.Common.Traits } } - class WithWallSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, ITick + class WithWallSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, IWallConnector, ITick { readonly WithWallSpriteBodyInfo wallInfo; int adjacent = 0; bool dirty = true; + bool IWallConnector.AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType) + { + return wallInfo.Type == wallType; + } + + void IWallConnector.SetDirty() { dirty = true; } + public WithWallSpriteBody(ActorInitializer init, WithWallSpriteBodyInfo info) : base(init, info, () => 0) { @@ -97,8 +104,8 @@ namespace OpenRA.Mods.Common.Traits adjacent = 0; foreach (var a in adjacentActors) { - var rb = a.TraitOrDefault(); - if (rb == null || rb.wallInfo.Type != wallInfo.Type) + var rb = a.TraitOrDefault(); + if (rb == null || !rb.AdjacentWallCanConnect(self, self.Location, wallInfo.Type)) continue; var location = self.Location; @@ -127,11 +134,11 @@ namespace OpenRA.Mods.Common.Traits { var adjacentActors = CVec.Directions.SelectMany(dir => self.World.ActorMap.GetActorsAt(self.Location + dir)) - .Select(a => a.TraitOrDefault()) + .Select(a => a.TraitOrDefault()) .Where(a => a != null); foreach (var rb in adjacentActors) - rb.dirty = true; + rb.SetDirty(); } public void RemovedFromWorld(Actor self) diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 23ae4125e7..207aac06a2 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -116,4 +116,11 @@ namespace OpenRA.Mods.Common.Traits { bool PreventsAutoTarget(Actor self, Actor attacker); } + + [RequireExplicitImplementation] + interface IWallConnector + { + bool AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType); + void SetDirty(); + } }