From 392b77647d18926bfb3d4c98146e5c5a650c3311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 21 Jun 2014 20:08:36 +0200 Subject: [PATCH 1/4] this does not make any sense with 0 HP you also can not a single dude --- OpenRA.Mods.RA/EmitInfantryOnSell.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/OpenRA.Mods.RA/EmitInfantryOnSell.cs b/OpenRA.Mods.RA/EmitInfantryOnSell.cs index d9a9a20726..609ba508d3 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) { } @@ -61,10 +61,5 @@ namespace OpenRA.Mods.RA } public void Sold(Actor self) { Emit(self); } - - public void Killed(Actor self, AttackInfo e) - { - Emit(self); - } } } From e8bccc33c6547f010e77cab62b5b585f58a9e55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 21 Jun 2014 20:15:40 +0200 Subject: [PATCH 2/4] StyleCop --- OpenRA.Mods.RA/EmitInfantryOnSell.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.RA/EmitInfantryOnSell.cs b/OpenRA.Mods.RA/EmitInfantryOnSell.cs index 609ba508d3..cb931f486e 100644 --- a/OpenRA.Mods.RA/EmitInfantryOnSell.cs +++ b/OpenRA.Mods.RA/EmitInfantryOnSell.cs @@ -54,8 +54,8 @@ 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), })); } } 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 3/4] 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 From ea86aac089f91389956be26a3ae72b01e276083a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 22 Jun 2014 12:39:16 +0200 Subject: [PATCH 4/4] replace EmitCargoOnSell with Cargo.EjectOnSell --- OpenRA.Mods.RA/Cargo.cs | 23 ++++++++++++- OpenRA.Mods.RA/EmitCargoOnSell.cs | 50 ---------------------------- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 - mods/ra/rules/structures.yaml | 2 -- 4 files changed, 22 insertions(+), 54 deletions(-) delete mode 100644 OpenRA.Mods.RA/EmitCargoOnSell.cs 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