Set passenger facings when they are unloading

This commit is contained in:
ScottNZ
2014-11-09 02:12:17 +13:00
parent 5bf3d9879c
commit eea978a4ae

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
@@ -27,6 +28,9 @@ namespace OpenRA.Mods.RA
public readonly string[] InitialUnits = { }; public readonly string[] InitialUnits = { };
public readonly bool EjectOnSell = true; 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); } public object Create(ActorInitializer init) { return new Cargo(init, this); }
} }
@@ -36,6 +40,7 @@ namespace OpenRA.Mods.RA
readonly Actor self; readonly Actor self;
readonly List<Actor> cargo = new List<Actor>(); readonly List<Actor> cargo = new List<Actor>();
readonly HashSet<Actor> reserves = new HashSet<Actor>(); readonly HashSet<Actor> reserves = new HashSet<Actor>();
readonly Lazy<IFacing> facing;
int totalWeight = 0; int totalWeight = 0;
int reservedWeight = 0; int reservedWeight = 0;
@@ -82,6 +87,7 @@ namespace OpenRA.Mods.RA
totalWeight = cargo.Sum(c => GetWeight(c)); totalWeight = cargo.Sum(c => GetWeight(c));
} }
facing = Exts.Lazy(self.TraitOrDefault<IFacing>);
} }
public void Created(Actor self) public void Created(Actor self)
@@ -184,19 +190,38 @@ namespace OpenRA.Mods.RA
public Actor Unload(Actor self) public Actor Unload(Actor self)
{ {
var a = cargo[0]; var a = cargo[0];
cargo.RemoveAt(0); cargo.RemoveAt(0);
totalWeight -= GetWeight(a); totalWeight -= GetWeight(a);
SetPassengerFacing(a);
foreach (var npe in self.TraitsImplementing<INotifyPassengerExited>()) foreach (var npe in self.TraitsImplementing<INotifyPassengerExited>())
npe.PassengerExited(self, a); npe.PassengerExited(self, a);
var p = a.Trait<Passenger>(); var p = a.Trait<Passenger>();
p.Transport = null; p.Transport = null;
foreach (var u in p.Info.GrantUpgrades) foreach (var u in p.Info.GrantUpgrades)
self.Trait<UpgradeManager>().RevokeUpgrade(self, u, p); self.Trait<UpgradeManager>().RevokeUpgrade(self, u, p);
return a; return a;
} }
void SetPassengerFacing(Actor passenger)
{
if (facing.Value == null)
return;
var passengerFacing = passenger.TraitOrDefault<IFacing>();
if (passengerFacing != null)
passengerFacing.Facing = facing.Value.Facing + Info.PassengerFacing;
var passengerTurreted = passenger.TraitOrDefault<Turreted>();
if (passengerTurreted != null)
passengerTurreted.TurretFacing = facing.Value.Facing + Info.PassengerFacing;
}
public IEnumerable<PipType> GetPips(Actor self) public IEnumerable<PipType> GetPips(Actor self)
{ {
var numPips = Info.PipCount; var numPips = Info.PipCount;