diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index 4c62b3c581..3189a58518 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits Actor = actor; Harvester = actor.Trait(); Parachutable = actor.TraitOrDefault(); - Mobile = actor.Trait(); + Mobile = actor.TraitOrDefault(); } } @@ -110,6 +110,9 @@ namespace OpenRA.Mods.Common.Traits // Find idle harvesters and give them orders: foreach (var h in harvesters) { + if (h.Value.Mobile == null) + continue; + if (!h.Key.IsIdle) { // Ignore this actor if FindAndDeliverResources is working fine or it is performing a different activity diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index eac5a1e91d..7c7356b9fd 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -18,7 +18,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class HarvesterInfo : DockClientBaseInfo, Requires, Requires, IRulesetLoaded + public class HarvesterInfo : DockClientBaseInfo, Requires, IRulesetLoaded { [Desc("Docking type")] public readonly BitSet Type = new("Unload"); @@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits public class Harvester : DockClientBase, IIssueOrder, IResolveOrder, IOrderVoice, ISpeedModifier, ISync, INotifyCreated { - readonly Mobile mobile; + Mobile mobile; readonly IResourceLayer resourceLayer; readonly ResourceClaimLayer claimLayer; readonly IStoresResources[] storesResources; @@ -104,7 +104,6 @@ namespace OpenRA.Mods.Common.Traits public Harvester(Actor self, HarvesterInfo info) : base(self, info) { - mobile = self.Trait(); storesResources = self.TraitsImplementing().Where(sr => info.Resources.Any(r => sr.HasType(r))).ToArray(); resourceLayer = self.World.WorldActor.Trait(); claimLayer = self.World.WorldActor.Trait(); @@ -112,10 +111,11 @@ namespace OpenRA.Mods.Common.Traits protected override void Created(Actor self) { + mobile = self.TraitOrDefault(); UpdateCondition(self); // Note: This is queued in a FrameEndTask because otherwise the activity is dropped/overridden while moving out of a factory. - if (Info.SearchOnCreation) + if (Info.SearchOnCreation && mobile != null) self.World.AddFrameEndTask(w => self.QueueActivity(new FindAndDeliverResources(self))); base.Created(self); @@ -218,7 +218,7 @@ namespace OpenRA.Mods.Common.Traits { get { - if (IsTraitDisabled) + if (IsTraitDisabled || mobile == null) yield break; yield return new HarvestOrderTargeter(); @@ -235,7 +235,7 @@ namespace OpenRA.Mods.Common.Traits string IOrderVoice.VoicePhraseForOrder(Actor self, Order order) { - if (order.OrderString == "Harvest") + if (order.OrderString == "Harvest" && mobile != null) return Info.HarvestVoice; return null; @@ -243,7 +243,7 @@ namespace OpenRA.Mods.Common.Traits void IResolveOrder.ResolveOrder(Actor self, Order order) { - if (order.OrderString == "Harvest") + if (order.OrderString == "Harvest" && mobile != null) { CPos loc; if (order.Target.Type != TargetType.Invalid)