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 7c77700c63..0000000000 --- a/OpenRA.Mods.RA/EmitCargoOnSell.cs +++ /dev/null @@ -1,30 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 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.Traits; - -namespace OpenRA.Mods.RA -{ - // for some reason I get yelled at for pbox.e1 not having Cargo, but that's a lie? - class EmitCargoOnSellInfo : TraitInfo//, Requires - { - } - - class EmitCargoOnSell : INotifySold - { - static void Emit(Actor self) - { - // TODO: would like to spill all actors out similar to how we call Unload - } - - public void Selling(Actor self) { Emit(self); } - public void Sold(Actor self) { } - } -} diff --git a/OpenRA.Mods.RA/EmitInfantryOnSell.cs b/OpenRA.Mods.RA/EmitInfantryOnSell.cs index d9a9a20726..cb931f486e 100644 --- a/OpenRA.Mods.RA/EmitInfantryOnSell.cs +++ b/OpenRA.Mods.RA/EmitInfantryOnSell.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA public readonly string[] ActorTypes = { "e1" }; } - class EmitInfantryOnSell : INotifySold, INotifyKilled + class EmitInfantryOnSell : INotifySold { public void Selling(Actor self) { } @@ -54,17 +54,12 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => w.CreateActor(at.Name, new TypeDictionary { - new LocationInit( loc ), - new OwnerInit( self.Owner ), + new LocationInit(loc), + new OwnerInit(self.Owner), })); } } public void Sold(Actor self) { Emit(self); } - - public void Killed(Actor self, AttackInfo e) - { - Emit(self); - } } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 19a2a6bd9d..613ee4bcba 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -229,7 +229,6 @@ -