Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback in Passenger during UnloadCargo before re-adding it to the world #21084

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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