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

Fix crashing when transports are loaded via lua and related regressions #21076

Merged
merged 5 commits into from
Dec 3, 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
21 changes: 12 additions & 9 deletions OpenRA.Mods.Common/Traits/Air/Aircraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,10 @@ void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary

Activity ICreationActivity.GetCreationActivity()
{
return new AssociateWithAirfieldActivity(self, creationActivityDelay, creationRallyPoint);
if (creationRallyPoint != null || creationActivityDelay > 0)
return new AssociateWithAirfieldActivity(self, creationActivityDelay, creationRallyPoint);

return null;
}

sealed class AssociateWithAirfieldActivity : Activity
Expand All @@ -1233,7 +1236,6 @@ sealed class AssociateWithAirfieldActivity : Activity
public AssociateWithAirfieldActivity(Actor self, int delay, CPos[] rallyPoint)
{
aircraft = self.Trait<Aircraft>();
IsInterruptible = false;
this.delay = delay;
this.rallyPoint = rallyPoint;
}
Expand All @@ -1242,25 +1244,26 @@ protected override void OnFirstRun(Actor self)
{
var host = aircraft.GetActorBelow();
if (host != null)
{
aircraft.MakeReservation(host);

// Freshly created aircraft shouldn't block the exit, so we allow them to yield their reservation.
aircraft.AllowYieldingReservation();
}

if (delay > 0)
QueueChild(new Wait(delay));
}

public override bool Tick(Actor self)
{
if (!aircraft.Info.TakeOffOnCreation)
{
// Freshly created aircraft shouldn't block the exit, so we allow them to yield their reservation
aircraft.AllowYieldingReservation();
if (!aircraft.Info.TakeOffOnCreation || IsCanceling)
return true;
}

if (rallyPoint != null && aircraft.Info.TakeOffOnCreation)
if (rallyPoint != null && rallyPoint.Length > 0)
{
foreach (var cell in rallyPoint)
self.QueueActivity(new AttackMoveActivity(self, () => aircraft.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
QueueChild(new AttackMoveActivity(self, () => aircraft.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
}
else if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length <= aircraft.LandAltitude.Length)
QueueChild(new TakeOff(self));
Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.Common/Traits/Harvester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ protected override void Created(Actor self)
mobile = self.TraitOrDefault<Mobile>();
UpdateCondition(self);

// Note: This is queued in a FrameEndTask because otherwise the activity is dropped/overridden while moving out of a factory.
if (Info.SearchOnCreation && mobile != null)
self.World.AddFrameEndTask(w => self.QueueActivity(new FindAndDeliverResources(self)));
self.QueueActivity(new FindAndDeliverResources(self));

base.Created(self);
}
Expand Down
14 changes: 9 additions & 5 deletions OpenRA.Mods.Common/Traits/Mobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,28 +979,32 @@ public class LeaveProductionActivity : Activity
public LeaveProductionActivity(Actor self, int delay, CPos[] rallyPoint, ReturnToCellActivity returnToCell)
{
mobile = self.Trait<Mobile>();
IsInterruptible = false;
this.delay = delay;
this.rallyPoint = rallyPoint;
this.returnToCell = returnToCell;
}

protected override void OnFirstRun(Actor self)
{
// It is vital that ReturnToCell is queued first as it needs the power to intercept a possible cancellation of this activity.
if (returnToCell != null)
self.QueueActivity(returnToCell);
QueueChild(returnToCell);
else if (delay > 0)
self.QueueActivity(new Wait(delay));
QueueChild(new Wait(delay));

if (rallyPoint != null)
foreach (var cell in rallyPoint)
self.QueueActivity(new AttackMoveActivity(self, () => mobile.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
QueueChild(new AttackMoveActivity(self, () => mobile.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
}
}

Activity ICreationActivity.GetCreationActivity()
{
return new LeaveProductionActivity(self, creationActivityDelay, creationRallypoint, returnToCellOnCreation ? new ReturnToCellActivity(self, creationActivityDelay, returnToCellOnCreationRecalculateSubCell) : null);
if (returnToCellOnCreation || creationRallypoint != null || creationActivityDelay > 0)
return new LeaveProductionActivity(self, creationActivityDelay, creationRallypoint,
returnToCellOnCreation ? new ReturnToCellActivity(self, creationActivityDelay, returnToCellOnCreationRecalculateSubCell) : null);

return null;
}

sealed class MoveOrderTargeter : IOrderTargeter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endregion

using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Traits;
Expand Down Expand Up @@ -61,7 +62,8 @@ void ITick.Tick(Actor self)
if (exitingActor == null)
return;

if (!exitingActor.IsInWorld || exitingActor.Location != openExit || exitingActor.CurrentActivity is not Mobile.ReturnToCellActivity)
if (!exitingActor.IsInWorld || exitingActor.Location != openExit
|| (!exitingActor.CurrentActivity?.ActivitiesImplementing<Mobile.ReturnToCellActivity>().Any() ?? true))
{
desiredFrame = 0;
exitingActor = null;
Expand Down
4 changes: 4 additions & 0 deletions mods/d2k/maps/shellmap/d2k-shellmap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ WorldLoaded = function()
Corrino = Player.GetPlayer("Corrino")
Smugglers = Player.GetPlayer("Smugglers")

Reinforcements.Reinforce(Atreides, { "carryall" }, { atr_carry_1.Location })
Reinforcements.Reinforce(Atreides, { "carryall" }, { atr_carry_2.Location })
Reinforcements.Reinforce(Atreides, { "carryall" }, { atr_carry_3.Location })

ViewportOrigin = Camera.Position

Utils.Do(Utils.Take(4, Upgrades), function(upgrade)
Expand Down
21 changes: 9 additions & 12 deletions mods/d2k/maps/shellmap/map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -676,18 +676,6 @@ Actors:
Owner: Atreides
Location: 71,86
Facing: 384
atr_carry1: carryall
Owner: Atreides
Location: 94,86
Facing: 0
atr_carry2: carryall
Owner: Atreides
Location: 94,88
Facing: 0
atr_carry3: carryall
Owner: Atreides
Location: 94,90
Facing: 0
atr_trike: trike
Owner: Atreides
Location: 92,82
Expand Down Expand Up @@ -976,5 +964,14 @@ Actors:
Actor267: spicebloom.spawnpoint
Owner: Neutral
Location: 50,65
atr_carry_3: waypoint
Owner: Atreides
Location: 96,90
atr_carry_2: waypoint
Owner: Atreides
Location: 88,98
atr_carry_1: waypoint
Owner: Atreides
Location: 80,98

Rules: d2k|rules/campaign-palettes.yaml, rules.yaml