Skip to content

Commit

Permalink
Remove Resupply re-queueing hack from Aircraft
Browse files Browse the repository at this point in the history
By preventing that other traits can remotely cancel Resupply
or ReturnToBase.
  • Loading branch information
reaperrr committed Jul 18, 2019
1 parent d015c00 commit c24795b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
34 changes: 9 additions & 25 deletions OpenRA.Mods.Common/Traits/Air/Aircraft.cs
Expand Up @@ -672,23 +672,6 @@ void INotifyBecomingIdle.OnBecomingIdle(Actor self)

protected virtual void OnBecomingIdle(Actor self)
{
var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition);
var atLandAltitude = altitude == LandAltitude;

// Work-around to prevent players from accidentally canceling resupply by pressing 'Stop',
// by re-queueing Resupply as long as resupply hasn't finished and aircraft is still on resupplier.
// TODO: Investigate moving this back to ResolveOrder's "Stop" handling,
// once conflicts with other traits' "Stop" orders have been fixed.
if (atLandAltitude)
{
var host = GetActorBelow();
if (host != null && (CanRearmAt(host) || CanRepairAt(host)))
{
self.QueueActivity(new Resupply(self, host, new WDist(512)));
return;
}
}

if (Info.IdleBehavior == IdleBehaviorType.LeaveMap)
{
self.QueueActivity(new FlyOffMap(self));
Expand All @@ -698,16 +681,17 @@ protected virtual void OnBecomingIdle(Actor self)
self.QueueActivity(new ReturnToBase(self, null, !Info.TakeOffOnResupply));
else
{
if (atLandAltitude)
var dat = self.World.Map.DistanceAboveTerrain(CenterPosition);
if (dat == LandAltitude)
{
if (!CanLand(self.Location) && ReservedActor == null)
self.QueueActivity(new TakeOff(self));

// All remaining idle behaviors rely on not being atLandAltitude, so unconditionally return
// All remaining idle behaviors rely on not being at LandAltitude, so unconditionally return
return;
}

if (Info.IdleBehavior != IdleBehaviorType.Land && altitude != Info.CruiseAltitude)
if (Info.IdleBehavior != IdleBehaviorType.Land && dat != Info.CruiseAltitude)
self.QueueActivity(new TakeOff(self));
else if (Info.IdleBehavior == IdleBehaviorType.Land && Info.LandableTerrainTypes.Count > 0)
self.QueueActivity(new Land(self));
Expand Down Expand Up @@ -1031,13 +1015,13 @@ public void ResolveOrder(Actor self, Order order)
}
else if (orderString == "Stop")
{
self.CancelActivity();

// HACK: If the player accidentally pressed 'Stop', we don't want this to cancel reservation.
// If unreserving is actually desired despite an actor below, it should be triggered from OnBecomingIdle.
if (GetActorBelow() != null)
// We don't want the Stop order to cancel a running Resupply activity.
// Resupply is always either the main activity or a child of ReturnToBase.
if (self.CurrentActivity is Resupply ||
(self.CurrentActivity is ReturnToBase && GetActorBelow() != null))
return;

self.CancelActivity();
UnReserve();
}
else if (orderString == "ReturnToBase" && rearmable != null && rearmable.Info.RearmActors.Any())
Expand Down
7 changes: 7 additions & 0 deletions OpenRA.Mods.Common/Traits/Attack/AttackBase.cs
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Primitives;
using OpenRA.Support;
Expand Down Expand Up @@ -206,6 +207,12 @@ void IResolveOrder.ResolveOrder(Actor self, Order order)
// Some 3rd-party mods rely on this being public
public virtual void OnStopOrder(Actor self)
{
// We don't want Stop orders from traits other than Mobile or Aircraft to cancel Resupply activity.
// Resupply is always either the main activity or a child of ReturnToBase.
// TODO: This should generally only cancel activities queued by this trait.
if (self.CurrentActivity == null || self.CurrentActivity is Resupply || self.CurrentActivity is ReturnToBase)
return;

self.CancelActivity();
}

Expand Down
9 changes: 8 additions & 1 deletion OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs
Expand Up @@ -116,9 +116,16 @@ void IResolveOrder.ResolveOrder(Actor self, Order order)
if (currentTransform == null)
self.QueueActivity(order.Queued, activity);
}
else if (order.OrderString == "Stop")
{
// We don't want Stop orders from traits other than Mobile or Aircraft to cancel Resupply activity.
// Resupply is always either the main activity or a child of ReturnToBase.
// TODO: This should generally only cancel activities queued by this trait.
if (self.CurrentActivity == null || self.CurrentActivity is Resupply || self.CurrentActivity is ReturnToBase)
return;

if (order.OrderString == "Stop")
self.CancelActivity();
}
}

string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
Expand Down
1 change: 1 addition & 0 deletions OpenRA.Mods.Common/Traits/Mobile.cs
Expand Up @@ -802,6 +802,7 @@ void IResolveOrder.ResolveOrder(Actor self, Order order)
self.QueueActivity(order.Queued, WrapMove(new Move(self, cell, WDist.FromCells(8), null, true)));
}

// TODO: This should only cancel activities queued by this trait
if (order.OrderString == "Stop")
self.CancelActivity();

Expand Down

0 comments on commit c24795b

Please sign in to comment.