Cargo improvements
This commit is contained in:
committed by
Oliver Brakmann
parent
30de4df749
commit
a46ec5d930
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public readonly CargoInfo Info;
|
||||
readonly Actor self;
|
||||
readonly Stack<Actor> cargo = new Stack<Actor>();
|
||||
readonly List<Actor> cargo = new List<Actor>();
|
||||
readonly HashSet<Actor> reserves = new HashSet<Actor>();
|
||||
readonly Dictionary<string, Stack<int>> passengerTokens = new Dictionary<string, Stack<int>>();
|
||||
readonly Lazy<IFacing> facing;
|
||||
@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (init.Contains<RuntimeCargoInit>())
|
||||
{
|
||||
cargo = new Stack<Actor>(init.Get<RuntimeCargoInit, Actor[]>());
|
||||
cargo = new List<Actor>(init.Get<RuntimeCargoInit, Actor[]>());
|
||||
totalWeight = cargo.Sum(c => GetWeight(c));
|
||||
}
|
||||
else if (init.Contains<CargoInit>())
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
|
||||
new TypeDictionary { new OwnerInit(self.Owner) });
|
||||
|
||||
cargo.Push(unit);
|
||||
cargo.Add(unit);
|
||||
}
|
||||
|
||||
totalWeight = cargo.Sum(c => GetWeight(c));
|
||||
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
|
||||
new TypeDictionary { new OwnerInit(self.Owner) });
|
||||
|
||||
cargo.Push(unit);
|
||||
cargo.Add(unit);
|
||||
}
|
||||
|
||||
totalWeight = cargo.Sum(c => GetWeight(c));
|
||||
@@ -271,33 +271,35 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool HasSpace(int weight) { return totalWeight + reservedWeight + weight <= Info.MaxWeight; }
|
||||
public bool IsEmpty(Actor self) { return cargo.Count == 0; }
|
||||
|
||||
public Actor Peek(Actor self) { return cargo.Peek(); }
|
||||
public Actor Peek(Actor self) { return cargo.Last(); }
|
||||
|
||||
public Actor Unload(Actor self)
|
||||
public Actor Unload(Actor self, Actor passenger = null)
|
||||
{
|
||||
var a = cargo.Pop();
|
||||
passenger = passenger ?? cargo.Last();
|
||||
if (!cargo.Remove(passenger))
|
||||
throw new ArgumentException("Attempted to unload an actor that is not a passenger.");
|
||||
|
||||
totalWeight -= GetWeight(a);
|
||||
totalWeight -= GetWeight(passenger);
|
||||
|
||||
SetPassengerFacing(a);
|
||||
SetPassengerFacing(passenger);
|
||||
|
||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerExited>())
|
||||
npe.OnPassengerExited(self, a);
|
||||
npe.OnPassengerExited(self, passenger);
|
||||
|
||||
foreach (var nec in a.TraitsImplementing<INotifyExitedCargo>())
|
||||
nec.OnExitedCargo(a, self);
|
||||
foreach (var nec in passenger.TraitsImplementing<INotifyExitedCargo>())
|
||||
nec.OnExitedCargo(passenger, self);
|
||||
|
||||
var p = a.Trait<Passenger>();
|
||||
var p = passenger.Trait<Passenger>();
|
||||
p.Transport = null;
|
||||
|
||||
Stack<int> passengerToken;
|
||||
if (passengerTokens.TryGetValue(a.Info.Name, out passengerToken) && passengerToken.Any())
|
||||
if (passengerTokens.TryGetValue(passenger.Info.Name, out passengerToken) && passengerToken.Any())
|
||||
conditionManager.RevokeCondition(self, passengerToken.Pop());
|
||||
|
||||
if (loadedTokens.Any())
|
||||
conditionManager.RevokeCondition(self, loadedTokens.Pop());
|
||||
|
||||
return a;
|
||||
return passenger;
|
||||
}
|
||||
|
||||
void SetPassengerFacing(Actor passenger)
|
||||
@@ -339,7 +341,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Load(Actor self, Actor a)
|
||||
{
|
||||
cargo.Push(a);
|
||||
cargo.Add(a);
|
||||
var w = GetWeight(a);
|
||||
totalWeight += w;
|
||||
if (reserves.Contains(a))
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new Passenger(this); }
|
||||
}
|
||||
|
||||
public class Passenger : INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, INotifyRemovedFromWorld, INotifyEnteredCargo, INotifyExitedCargo
|
||||
public class Passenger : INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, INotifyRemovedFromWorld, INotifyEnteredCargo, INotifyExitedCargo, INotifyKilled
|
||||
{
|
||||
public readonly PassengerInfo Info;
|
||||
public Actor Transport;
|
||||
@@ -183,5 +183,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
ReservedCargo.UnreserveSpace(self);
|
||||
ReservedCargo = null;
|
||||
}
|
||||
|
||||
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
if (Transport == null)
|
||||
return;
|
||||
|
||||
Transport.Trait<Cargo>().Unload(Transport, self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user