diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 86c70bdf63..479dfc7fb7 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -19,7 +19,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class HarvesterInfo : ITraitInfo + public class HarvesterInfo : ITraitInfo, Requires { public readonly string[] DeliveryBuildings = { }; @@ -62,6 +62,7 @@ namespace OpenRA.Mods.Common.Traits INotifyResourceClaimLost, INotifyIdle, INotifyBlockingMove, INotifyBuildComplete { readonly HarvesterInfo info; + readonly Mobile mobile; Dictionary contents = new Dictionary(); [Sync] public Actor OwnerLinkedProc = null; @@ -76,6 +77,7 @@ namespace OpenRA.Mods.Common.Traits public Harvester(Actor self, HarvesterInfo info) { this.info = info; + mobile = self.Trait(); self.QueueActivity(new CallFunc(() => ChooseNewProc(self, null))); } @@ -189,10 +191,7 @@ namespace OpenRA.Mods.Common.Traits if (self.Location == deliveryLoc) { // Get out of the way: - var mobile = self.Trait(); - var harv = self.Trait(); - - var moveTo = harv.LastHarvestedCell ?? (deliveryLoc + new CVec(0, 4)); + var moveTo = LastHarvestedCell ?? (deliveryLoc + new CVec(0, 4)); self.QueueActivity(mobile.MoveTo(moveTo, 1)); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); @@ -219,7 +218,6 @@ namespace OpenRA.Mods.Common.Traits if (act is Wait) { self.CancelActivity(); - var mobile = self.Trait(); var cell = self.Location; var moveTo = mobile.NearestMoveableCell(cell, 2, 5); @@ -316,7 +314,6 @@ namespace OpenRA.Mods.Common.Traits self.CancelActivity(); - var mobile = self.Trait(); if (order.TargetLocation != CPos.Zero) { var loc = order.TargetLocation;