From 13f20a4b56db59d4b88a4755308542032a7b686d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 10 Jan 2016 07:28:28 +0100 Subject: [PATCH] cache the trait lookup --- OpenRA.Mods.Common/Traits/Guard.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Guard.cs b/OpenRA.Mods.Common/Traits/Guard.cs index 886a62a0de..34ed23a53d 100644 --- a/OpenRA.Mods.Common/Traits/Guard.cs +++ b/OpenRA.Mods.Common/Traits/Guard.cs @@ -27,15 +27,21 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new Guard(this); } } - public class Guard : IResolveOrder, IOrderVoice + public class Guard : IResolveOrder, IOrderVoice, INotifyCreated { readonly GuardInfo info; + IMove move; public Guard(GuardInfo info) { this.info = info; } + public void Created(Actor self) + { + move = self.Trait(); + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Guard") @@ -51,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits self.SetTargetLine(target, Color.Yellow); var range = target.Actor.Info.TraitInfo().Range; - self.QueueActivity(false, new AttackMoveActivity(self, self.Trait().MoveFollow(self, target, WDist.Zero, range))); + self.QueueActivity(false, new AttackMoveActivity(self, move.MoveFollow(self, target, WDist.Zero, range))); } public string VoicePhraseForOrder(Actor self, Order order)