diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index 0a98f8e7cb..dc6e203643 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -23,11 +23,12 @@ namespace OpenRA.Mods.RA public readonly int PipCount = 0; public readonly string[] Types = { }; public readonly string[] InitialUnits = { }; + public readonly bool EjectOnSell = true; public object Create(ActorInitializer init) { return new Cargo(init, this); } } - public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyKilled, INotifyCapture, ITick + public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyKilled, INotifyCapture, ITick, INotifySold { readonly Actor self; public readonly CargoInfo Info; @@ -190,6 +191,26 @@ namespace OpenRA.Mods.RA cargo.Clear(); } + public void Selling(Actor self) { } + public void Sold(Actor self) + { + if (!Info.EjectOnSell || cargo == null) + return; + + while (!IsEmpty(self)) + SpawnPassenger(Unload(self)); + } + + void SpawnPassenger(Actor passenger) + { + self.World.AddFrameEndTask(w => + { + w.Add(passenger); + passenger.Trait().SetPosition(passenger, self.Location); + // TODO: this won't work well for >1 actor as they should move towards the next enterable (sub) cell instead + }); + } + public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) { if (cargo == null) diff --git a/OpenRA.Mods.RA/EmitCargoOnSell.cs b/OpenRA.Mods.RA/EmitCargoOnSell.cs deleted file mode 100644 index d1b021d59a..0000000000 --- a/OpenRA.Mods.RA/EmitCargoOnSell.cs +++ /dev/null @@ -1,50 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using OpenRA.Primitives; -using OpenRA.Traits; -using OpenRA.Mods.RA.Activities; - -namespace OpenRA.Mods.RA -{ - class EmitCargoOnSellInfo : ITraitInfo//, Requires // TODO: this breaks for no apparent reason - { - public object Create(ActorInitializer init) { return new EmitCargoOnSell(init); } - } - - class EmitCargoOnSell : INotifySold - { - readonly Cargo cargo; - Actor passenger; - - public EmitCargoOnSell(ActorInitializer init) - { - cargo = init.self.Trait(); - } - - public void Selling(Actor self) - { - // TODO: support more than one passenger - passenger = cargo.Unload(self); - } - - public void Sold(Actor self) - { - if (passenger == null) - return; - - self.World.AddFrameEndTask(w => w.CreateActor(passenger.Info.Name, new TypeDictionary - { - new LocationInit(self.Location), - new OwnerInit(self.Owner), - })); - } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 88a75a8b9c..678e6d6523 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -229,7 +229,6 @@ - diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 123b413716..c2f5f9d5c8 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -439,7 +439,6 @@ PBOX: PipCount: 1 InitialUnits: e1 -EmitInfantryOnSell: - EmitCargoOnSell: DrawLineToTarget: AttackGarrisoned: Armaments: garrisoned @@ -486,7 +485,6 @@ HBOX: PipCount: 1 InitialUnits: e1 -EmitInfantryOnSell: - EmitCargoOnSell: DrawLineToTarget: DetectCloaked: Range: 6