diff --git a/OpenRA.Mods.Common/Traits/Render/RenderBuildingWall.cs b/OpenRA.Mods.Common/Traits/Render/RenderBuildingWall.cs index b4fdc0ae6d..7ed6d8868d 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderBuildingWall.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderBuildingWall.cs @@ -24,9 +24,44 @@ namespace OpenRA.Mods.Common.Traits public override IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) { - // Show a static frame instead of animating all of the wall states + var adjacent = 0; + + if (init.Contains()) + { + var location = CPos.Zero; + if (init.Contains()) + location = init.Get(); + + var neighbours = init.Get>(); + foreach (var kv in neighbours) + { + var haveNeighbour = false; + foreach (var n in kv.Value) + { + var rb = init.World.Map.Rules.Actors[n].Traits.GetOrDefault(); + if (rb != null && rb.Type == Type) + { + haveNeighbour = true; + break; + } + } + + if (!haveNeighbour) + continue; + + if (kv.Key == location + new CVec(0, -1)) + adjacent |= 1; + else if (kv.Key == location + new CVec(+1, 0)) + adjacent |= 2; + else if (kv.Key == location + new CVec(0, +1)) + adjacent |= 4; + else if (kv.Key == location + new CVec(-1, 0)) + adjacent |= 8; + } + } + var anim = new Animation(init.World, image, () => 0); - anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0); + anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => adjacent); yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale); } @@ -110,4 +145,12 @@ namespace OpenRA.Mods.Common.Traits UpdateNeighbours(self); } } + + public class RuntimeNeighbourInit : IActorInit> + { + [FieldFromYamlKey] readonly Dictionary value = null; + public RuntimeNeighbourInit() { } + public RuntimeNeighbourInit(Dictionary init) { value = init; } + public Dictionary Value(World world) { return value; } + } }