diff --git a/OpenRa.Game/Traits/RenderBuilding.cs b/OpenRa.Game/Traits/RenderBuilding.cs index d4cab8be24..b294327c18 100644 --- a/OpenRa.Game/Traits/RenderBuilding.cs +++ b/OpenRa.Game/Traits/RenderBuilding.cs @@ -10,7 +10,7 @@ using OpenRa.Game; namespace OpenRa.Game.Traits { - class RenderBuilding : RenderSimple + class RenderBuilding : RenderSimple, INotifyRemoved { const int SmallBibStart = 1; const int LargeBibStart = 5; @@ -19,7 +19,11 @@ namespace OpenRa.Game.Traits : base(self) { anim.PlayThen("make", () => anim.PlayRepeating("idle")); + DoBib(self, false); + } + void DoBib(Actor self, bool isRemove) + { // at this point, we already know where we are, so we can safely place the bib in the smudge var buildingInfo = (UnitInfo.BuildingInfo)self.unitInfo; if (buildingInfo.Bib) @@ -31,7 +35,13 @@ namespace OpenRa.Game.Traits for (int i = 0; i < 2 * size; i++) { var p = self.Location + new int2(i % size, i / size + bibOffset); - Game.map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex); + if (isRemove) + { + if (Game.map.MapTiles[p.X, p.Y].smudge == (byte)(i + startIndex)) + Game.map.MapTiles[p.X, p.Y].smudge = 0; + } + else + Game.map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex); } } } @@ -40,5 +50,7 @@ namespace OpenRa.Game.Traits { yield return Pair.New(anim.Image, 24f * (float2)self.Location); } + + public void Removed(Actor self) { DoBib(self, true); } } } diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 861026e1c8..3b90e629d9 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -10,4 +10,5 @@ namespace OpenRa.Game.Traits interface ITick { void Tick(Actor self); } interface IRender { IEnumerable> Render(Actor self); } interface IOrder { Order Order(Actor self, int2 xy, bool lmb, Actor underCursor); } + interface INotifyRemoved { void Removed(Actor self); } } diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 7f6384a90a..74f1edc411 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; using System.Windows.Forms; -using OpenRa.Game.Graphics; +using OpenRa.Game.Graphics; +using OpenRa.Game.Traits; namespace OpenRa.Game { @@ -21,8 +22,13 @@ namespace OpenRa.Game public void AddFrameEndTask( Action a ) { frameEndActions.Add( a ); } - public event Action ActorAdded = _ => { }; - public event Action ActorRemoved = a => { a.Health = 0; }; /* make sure everyone sees it as dead */ + public event Action ActorAdded = _ => { }; + public event Action ActorRemoved = a => + { + a.Health = 0; /* make sure everyone sees it as dead */ + foreach (var nr in a.traits.WithInterface()) + nr.Removed(a); + }; public void ResetTimer() {