cache the trait lookup

This commit is contained in:
Matthias Mailänder
2016-01-10 07:28:28 +01:00
parent a74aaf73c5
commit 13f20a4b56

View File

@@ -27,15 +27,21 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new Guard(this); } public object Create(ActorInitializer init) { return new Guard(this); }
} }
public class Guard : IResolveOrder, IOrderVoice public class Guard : IResolveOrder, IOrderVoice, INotifyCreated
{ {
readonly GuardInfo info; readonly GuardInfo info;
IMove move;
public Guard(GuardInfo info) public Guard(GuardInfo info)
{ {
this.info = info; this.info = info;
} }
public void Created(Actor self)
{
move = self.Trait<IMove>();
}
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
if (order.OrderString == "Guard") if (order.OrderString == "Guard")
@@ -51,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(target, Color.Yellow); self.SetTargetLine(target, Color.Yellow);
var range = target.Actor.Info.TraitInfo<GuardableInfo>().Range; var range = target.Actor.Info.TraitInfo<GuardableInfo>().Range;
self.QueueActivity(false, new AttackMoveActivity(self, self.Trait<IMove>().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) public string VoicePhraseForOrder(Actor self, Order order)