diff --git a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs index d6ef22dca7..a332b1c305 100644 --- a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs +++ b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs @@ -60,6 +60,7 @@ namespace OpenRA.Mods.Cnc.Traits readonly Actor self; IEnumerable speedModifiers; + INotifyVisualPositionChanged[] notifyVisualPositionChanged; [Sync] public int Facing { get; set; } @@ -96,6 +97,7 @@ namespace OpenRA.Mods.Cnc.Traits { speedModifiers = self.TraitsImplementing().ToArray().Select(sm => sm.GetSpeedModifier()); cachedLocation = self.Location; + notifyVisualPositionChanged = self.TraitsImplementing().ToArray(); } void INotifyAddedToWorld.AddedToWorld(Actor self) @@ -178,6 +180,11 @@ namespace OpenRA.Mods.Cnc.Traits return; self.World.UpdateMaps(self, this); + + // This can be called from the constructor before notifyVisualPositionChanged is assigned. + if (notifyVisualPositionChanged != null) + foreach (var n in notifyVisualPositionChanged) + n.VisualPositionChanged(self, 0, 0); } public Activity MoveTo(CPos cell, int nearEnough = 0, Actor ignoreActor = null, diff --git a/OpenRA.Mods.Common/Traits/Crates/Crate.cs b/OpenRA.Mods.Common/Traits/Crates/Crate.cs index b12e317cc4..c1a4a1960c 100644 --- a/OpenRA.Mods.Common/Traits/Crates/Crate.cs +++ b/OpenRA.Mods.Common/Traits/Crates/Crate.cs @@ -74,12 +74,13 @@ namespace OpenRA.Mods.Common.Traits } } - public class Crate : ITick, IPositionable, ICrushable, ISync, + public class Crate : ITick, IPositionable, ICrushable, ISync, INotifyCreated, INotifyParachute, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCrushed { readonly Actor self; readonly CrateInfo info; bool collected; + INotifyVisualPositionChanged[] notifyVisualPositionChanged; [Sync] int ticks; @@ -96,6 +97,11 @@ namespace OpenRA.Mods.Common.Traits SetPosition(self, init.Get()); } + void INotifyCreated.Created(Actor self) + { + notifyVisualPositionChanged = self.TraitsImplementing().ToArray(); + } + void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet crushClasses) { } void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet crushClasses) @@ -197,6 +203,11 @@ namespace OpenRA.Mods.Common.Traits { CenterPosition = pos; self.World.UpdateMaps(self, this); + + // This can be called from the constructor before notifyVisualPositionChanged is assigned. + if (notifyVisualPositionChanged != null) + foreach (var n in notifyVisualPositionChanged) + n.VisualPositionChanged(self, 0, 0); } // Sets only the location (Location) diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index 9291ac97c3..9318cf4bfc 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -60,6 +60,8 @@ namespace OpenRA.Mods.Common.Traits readonly int dragSpeed; readonly WPos finalPosition; + INotifyVisualPositionChanged[] notifyVisualPositionChanged; + [Sync] public CPos TopLeft { get; private set; } @@ -91,6 +93,8 @@ namespace OpenRA.Mods.Common.Traits var distance = (finalPosition - CenterPosition).Length; if (dragSpeed > 0 && distance > 0) self.QueueActivity(new Drag(self, CenterPosition, finalPosition, distance / dragSpeed)); + + notifyVisualPositionChanged = self.TraitsImplementing().ToArray(); } public bool CanExistInCell(CPos cell) @@ -130,6 +134,11 @@ namespace OpenRA.Mods.Common.Traits { CenterPosition = pos; self.World.ScreenMap.AddOrUpdate(self); + + // This can be called from the constructor before notifyVisualPositionChanged is assigned. + if (notifyVisualPositionChanged != null) + foreach (var n in notifyVisualPositionChanged) + n.VisualPositionChanged(self, 0, 0); } public void SetPosition(Actor self, WPos pos)