From eea978a4ae9309afc4e168e52d87306bb37341a3 Mon Sep 17 00:00:00 2001 From: ScottNZ Date: Sun, 9 Nov 2014 02:12:17 +1300 Subject: [PATCH] Set passenger facings when they are unloading --- OpenRA.Mods.RA/Cargo.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index 98fa24b00f..f88a948e04 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Linq; using System.Collections.Generic; using OpenRA.Traits; @@ -27,6 +28,9 @@ namespace OpenRA.Mods.RA public readonly string[] InitialUnits = { }; public readonly bool EjectOnSell = true; + [Desc("Which direction the passenger will face (relative to the transport) when unloading.")] + public readonly int PassengerFacing = 128; + public object Create(ActorInitializer init) { return new Cargo(init, this); } } @@ -36,6 +40,7 @@ namespace OpenRA.Mods.RA readonly Actor self; readonly List cargo = new List(); readonly HashSet reserves = new HashSet(); + readonly Lazy facing; int totalWeight = 0; int reservedWeight = 0; @@ -82,6 +87,7 @@ namespace OpenRA.Mods.RA totalWeight = cargo.Sum(c => GetWeight(c)); } + facing = Exts.Lazy(self.TraitOrDefault); } public void Created(Actor self) @@ -184,19 +190,38 @@ namespace OpenRA.Mods.RA public Actor Unload(Actor self) { var a = cargo[0]; + cargo.RemoveAt(0); totalWeight -= GetWeight(a); + SetPassengerFacing(a); + foreach (var npe in self.TraitsImplementing()) npe.PassengerExited(self, a); var p = a.Trait(); p.Transport = null; + foreach (var u in p.Info.GrantUpgrades) self.Trait().RevokeUpgrade(self, u, p); + return a; } + void SetPassengerFacing(Actor passenger) + { + if (facing.Value == null) + return; + + var passengerFacing = passenger.TraitOrDefault(); + if (passengerFacing != null) + passengerFacing.Facing = facing.Value.Facing + Info.PassengerFacing; + + var passengerTurreted = passenger.TraitOrDefault(); + if (passengerTurreted != null) + passengerTurreted.TurretFacing = facing.Value.Facing + Info.PassengerFacing; + } + public IEnumerable GetPips(Actor self) { var numPips = Info.PipCount;