Skip to content

Commit

Permalink
Cargo improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CDVoidwalker committed Mar 12, 2019
1 parent 71dd84b commit 0cef355
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/UnloadCargo.cs
Expand Up @@ -62,7 +62,7 @@ public override Activity Tick(Actor self)
foreach (var inu in notifiers)
inu.Unloading(self);

var actor = cargo.Peek(self);
var actor = cargo.Peek();
var spawn = self.CenterPosition;

var exitSubCell = ChooseExitSubCell(actor);
Expand Down
22 changes: 14 additions & 8 deletions OpenRA.Mods.Common/Traits/Cargo.cs
Expand Up @@ -80,7 +80,7 @@ public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCrea
{
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;
Expand Down Expand Up @@ -108,7 +108,7 @@ public Cargo(ActorInitializer init, CargoInfo info)

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>())
Expand All @@ -118,7 +118,7 @@ public Cargo(ActorInitializer init, CargoInfo info)
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));
Expand All @@ -130,7 +130,7 @@ public Cargo(ActorInitializer init, CargoInfo info)
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));
Expand Down Expand Up @@ -269,11 +269,12 @@ public string VoicePhraseForOrder(Actor self, Order order)
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() { return cargo.Last(); }

public Actor Unload(Actor self)
public Actor Unload(Actor self, Actor target)
{
var a = cargo.Pop();
var a = cargo.First(x => x == target);
cargo.Remove(a);

totalWeight -= GetWeight(a);

Expand All @@ -298,6 +299,11 @@ public Actor Unload(Actor self)
return a;
}

public Actor Unload(Actor self)
{
return Unload(self, cargo.Last());
}

void SetPassengerFacing(Actor passenger)
{
if (facing.Value == null)
Expand Down Expand Up @@ -337,7 +343,7 @@ PipType GetPipAt(int i)

public void Load(Actor self, Actor a)
{
cargo.Push(a);
cargo.Add(a);
var w = GetWeight(a);
totalWeight += w;
if (reserves.Contains(a))
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/ParaDrop.cs
Expand Up @@ -73,7 +73,7 @@ void ITick.Tick(Actor self)
if (!inDropRange || cargo.IsEmpty(self))
return;

if (droppedAt.Contains(self.Location) || (checkForSuitableCell && !IsSuitableCell(cargo.Peek(self), self.Location)))
if (droppedAt.Contains(self.Location) || (checkForSuitableCell && !IsSuitableCell(cargo.Peek(), self.Location)))
return;

if (!self.World.Map.Contains(self.Location))
Expand Down
11 changes: 10 additions & 1 deletion OpenRA.Mods.Common/Traits/Passenger.cs
Expand Up @@ -51,7 +51,7 @@ public class PassengerInfo : ITraitInfo
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;
Expand Down Expand Up @@ -183,5 +183,14 @@ public void Unreserve(Actor self)
ReservedCargo.UnreserveSpace(self);
ReservedCargo = null;
}

void INotifyKilled.Killed(Actor self, AttackInfo e)
{
if (Transport == null || Transport.IsDead)
return;

var c = Transport.Trait<Cargo>();
c.Unload(Transport, self);
}
}
}

0 comments on commit 0cef355

Please sign in to comment.