From 6adf453ad141e83a05d62adda841fb418f8d3a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 21 Jun 2014 20:38:56 +0200 Subject: [PATCH] finished EmitCargoOnSell closes #2424 --- OpenRA.Mods.RA/EmitCargoOnSell.cs | 34 ++++++++++++++++++++++++------- mods/ra/rules/structures.yaml | 2 ++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.RA/EmitCargoOnSell.cs b/OpenRA.Mods.RA/EmitCargoOnSell.cs index 7c77700c63..d1b021d59a 100644 --- a/OpenRA.Mods.RA/EmitCargoOnSell.cs +++ b/OpenRA.Mods.RA/EmitCargoOnSell.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * 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, @@ -8,23 +8,43 @@ */ #endregion +using OpenRA.Primitives; using OpenRA.Traits; +using OpenRA.Mods.RA.Activities; 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 EmitCargoOnSellInfo : ITraitInfo//, Requires // TODO: this breaks for no apparent reason { + public object Create(ActorInitializer init) { return new EmitCargoOnSell(init); } } class EmitCargoOnSell : INotifySold { - static void Emit(Actor self) + readonly Cargo cargo; + Actor passenger; + + public EmitCargoOnSell(ActorInitializer init) { - // TODO: would like to spill all actors out similar to how we call Unload + cargo = init.self.Trait(); } - public void Selling(Actor self) { Emit(self); } - public void Sold(Actor self) { } + 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/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index c2f5f9d5c8..123b413716 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -439,6 +439,7 @@ PBOX: PipCount: 1 InitialUnits: e1 -EmitInfantryOnSell: + EmitCargoOnSell: DrawLineToTarget: AttackGarrisoned: Armaments: garrisoned @@ -485,6 +486,7 @@ HBOX: PipCount: 1 InitialUnits: e1 -EmitInfantryOnSell: + EmitCargoOnSell: DrawLineToTarget: DetectCloaked: Range: 6