diff --git a/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs b/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs index 27c2893fa8..56411654dd 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits public class FreeActor : ConditionalTrait { - bool allowSpawn; + protected bool allowSpawn; public FreeActor(ActorInitializer init, FreeActorInfo info) : base(info) diff --git a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs index f979d6788a..20a5b39343 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs @@ -36,18 +36,26 @@ namespace OpenRA.Mods.Common.Traits public override object Create(ActorInitializer init) { return new FreeActorWithDelivery(init, this); } } - public class FreeActorWithDelivery + public class FreeActorWithDelivery : FreeActor { - public readonly FreeActorWithDeliveryInfo Info; - + readonly FreeActorWithDeliveryInfo info; readonly Actor self; public FreeActorWithDelivery(ActorInitializer init, FreeActorWithDeliveryInfo info) + : base(init, info) { self = init.Self; - Info = info; + this.info = info; + } - DoDelivery(self.Location + info.DeliveryOffset, info.Actor, info.DeliveringActor); + protected override void TraitEnabled(Actor self) + { + if (!allowSpawn) + return; + + allowSpawn = info.AllowRespawn; + + DoDelivery(self.Location + info.DeliveryOffset, Info.Actor, info.DeliveringActor); } public void DoDelivery(CPos location, string actorName, string carrierActorName) @@ -61,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits carryable.Reserve(cargo, carrier); carrier.Trait().AttachCarryable(carrier, cargo); - carrier.QueueActivity(new DeliverUnit(carrier, Target.FromCell(self.World, location), Info.DeliveryRange)); + carrier.QueueActivity(new DeliverUnit(carrier, Target.FromCell(self.World, location), info.DeliveryRange)); carrier.QueueActivity(new Fly(carrier, Target.FromCell(self.World, self.World.Map.ChooseRandomEdgeCell(self.World.SharedRandom)))); carrier.QueueActivity(new RemoveSelf()); @@ -71,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits void CreateActors(string actorName, string deliveringActorName, out Actor cargo, out Actor carrier) { // Get a carryall spawn location - var location = Info.SpawnLocation; + var location = info.SpawnLocation; if (location == CPos.Zero) location = self.World.Map.ChooseClosestEdgeCell(self.Location); diff --git a/OpenRA.Mods.D2k/Traits/Player/HarvesterInsurance.cs b/OpenRA.Mods.D2k/Traits/Player/HarvesterInsurance.cs index 070e030ae7..b2ad2ac454 100644 --- a/OpenRA.Mods.D2k/Traits/Player/HarvesterInsurance.cs +++ b/OpenRA.Mods.D2k/Traits/Player/HarvesterInsurance.cs @@ -41,7 +41,8 @@ namespace OpenRA.Mods.D2k.Traits return; var delivery = refinery.Trait(); - delivery.DoDelivery(refinery.Location + delivery.Info.DeliveryOffset, delivery.Info.Actor, delivery.Info.DeliveringActor); + var deliveryInfo = delivery.Info as FreeActorWithDeliveryInfo; + delivery.DoDelivery(refinery.Location + deliveryInfo.DeliveryOffset, deliveryInfo.Actor, deliveryInfo.DeliveringActor); } } }