Skip to content

Commit

Permalink
Added callback in Passenger during unload from cargo just before the …
Browse files Browse the repository at this point in the history
…actor is added back to the world
  • Loading branch information
michaeldgg2 committed Sep 29, 2023
1 parent d5c940b commit 763309c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Activities/UnloadCargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ public override bool Tick(Actor self)
var move = actor.Trait<IMove>();
var pos = actor.Trait<IPositionable>();
var passenger = actor.Trait<Passenger>();
pos.SetPosition(actor, exitSubCell.Value.Cell, exitSubCell.Value.SubCell);
pos.SetCenterPosition(actor, spawn);
actor.CancelActivity();
passenger.OnBeforeAddedToWorld(actor);
w.Add(actor);
});
}
Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.Common/Traits/Cargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ void INotifyKilled.Killed(Actor self, AttackInfo e)
foreach (var nbm in nbms)
nbm.OnNotifyBlockingMove(passenger, passenger);
// For show.
passenger.QueueActivity(new Nudge(passenger));
passenger.Trait<Passenger>().OnEjectedFromKilledCargo(passenger);
}
else
passenger.Kill(e.Attacker);
Expand Down
13 changes: 13 additions & 0 deletions OpenRA.Mods.Common/Traits/Passenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ public void Unreserve(Actor self)
ReservedCargo = null;
}

public virtual void OnBeforeAddedToWorld(Actor actor)
{
actor.CancelActivity();
}

public virtual void OnEjectedFromKilledCargo(Actor self)
{
// Cancel all other activities to keep consistent behavior with the one in UnloadCargo.
self.CurrentActivity?.Cancel(self);

self.QueueActivity(new Nudge(self));
}

void INotifyKilled.Killed(Actor self, AttackInfo e)
{
if (Transport == null)
Expand Down

0 comments on commit 763309c

Please sign in to comment.