From a2af79ff98f0918e1b3ecd86bb8634ad3d1224be Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 4 Apr 2015 01:00:45 +0100 Subject: [PATCH] Add support for wall preview neighbours. --- .../Traits/Render/RenderBuildingWall.cs | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) 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; } + } }