From b7a3a446e1f0a82a4dbab9d9cd8e012a42feadf9 Mon Sep 17 00:00:00 2001 From: teees Date: Fri, 20 Nov 2015 09:48:09 +0100 Subject: [PATCH] Unload passengers on death --- OpenRA.Mods.Common/Activities/Enter.cs | 5 +++++ OpenRA.Mods.Common/Traits/Cargo.cs | 23 +++++++++++++++++++++++ mods/ts/rules/aircraft.yaml | 3 +++ mods/ts/rules/gdi-vehicles.yaml | 1 + mods/ts/rules/nod-vehicles.yaml | 1 + 5 files changed, 33 insertions(+) diff --git a/OpenRA.Mods.Common/Activities/Enter.cs b/OpenRA.Mods.Common/Activities/Enter.cs index 60f3526253..729e02f84f 100644 --- a/OpenRA.Mods.Common/Activities/Enter.cs +++ b/OpenRA.Mods.Common/Activities/Enter.cs @@ -273,6 +273,11 @@ namespace OpenRA.Mods.Common.Activities // Run inner activity/InsideTick inner = inner == this ? InsideTick(self) : Util.RunActivity(self, inner); + + // If we are finished, move on to next activity + if (inner == null && nextState == State.Done) + return NextActivity; + return this; } } diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index a0d23ca5d8..b687706fb9 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -36,6 +36,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("When this actor is sold should all of its passengers be unloaded?")] public readonly bool EjectOnSell = true; + [Desc("When this actor dies should all of its passengers be unloaded?")] + public readonly bool EjectOnDeath = false; + [Desc("Terrain types that this actor is allowed to eject actors onto. Leave empty for all terrain types.")] public readonly HashSet UnloadTerrainTypes = new HashSet(); @@ -317,6 +320,26 @@ namespace OpenRA.Mods.Common.Traits public void Killed(Actor self, AttackInfo e) { + if (Info.EjectOnDeath) + while (!IsEmpty(self) && CanUnload()) + { + var passenger = Unload(self); + var cp = self.CenterPosition; + var inAir = self.World.Map.DistanceAboveTerrain(cp).Length != 0; + var positionable = passenger.Trait(); + positionable.SetPosition(passenger, self.Location); + + if (!inAir && positionable.CanEnterCell(self.Location, self, false)) + { + self.World.AddFrameEndTask(w => w.Add(passenger)); + var nbm = passenger.TraitOrDefault(); + if (nbm != null) + nbm.OnNotifyBlockingMove(passenger, passenger); + } + else + passenger.Kill(e.Attacker); + } + foreach (var c in cargo) c.Kill(e.Attacker); diff --git a/mods/ts/rules/aircraft.yaml b/mods/ts/rules/aircraft.yaml index 459e2edc50..822243d78a 100644 --- a/mods/ts/rules/aircraft.yaml +++ b/mods/ts/rules/aircraft.yaml @@ -22,6 +22,7 @@ DPOD: MaxWeight: 1 PipCount: 1 UnloadVoice: Move + EjectOnDeath: true Armament: Weapon: Vulcan2 AttackHeli: @@ -59,6 +60,7 @@ DSHP: MaxWeight: 5 PipCount: 5 UnloadVoice: Move + EjectOnDeath: true SpawnActorOnDeath: Actor: DSHP.Husk @@ -183,6 +185,7 @@ ORCATRAN: MaxWeight: 5 PipCount: 5 UnloadVoice: Move + EjectOnDeath: true SpawnActorOnDeath: Actor: ORCATRAN.Husk diff --git a/mods/ts/rules/gdi-vehicles.yaml b/mods/ts/rules/gdi-vehicles.yaml index 3906299bad..db2f20a599 100644 --- a/mods/ts/rules/gdi-vehicles.yaml +++ b/mods/ts/rules/gdi-vehicles.yaml @@ -28,6 +28,7 @@ APC: PipCount: 5 UnloadVoice: Unload LoadingUpgrades: notmobile + EjectOnDeath: true -WithVoxelBody: WithVoxelWaterBody: LeavesTrails: diff --git a/mods/ts/rules/nod-vehicles.yaml b/mods/ts/rules/nod-vehicles.yaml index 2fc4e56d0b..a211a49bb9 100644 --- a/mods/ts/rules/nod-vehicles.yaml +++ b/mods/ts/rules/nod-vehicles.yaml @@ -227,6 +227,7 @@ SAPC: PipCount: 5 UnloadVoice: Unload LoadingUpgrades: notmobile + EjectOnDeath: true SUBTANK: Inherits: ^VoxelTank