Simplify special exits of several acitivities.
This commit is contained in:
@@ -114,8 +114,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload and then resume the activity
|
||||
if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
|
||||
{
|
||||
QueueChild(new ReturnToBase(self, aircraft.Info.AbortOnResupply));
|
||||
return false;
|
||||
QueueChild(new ReturnToBase(self));
|
||||
return aircraft.Info.AbortOnResupply;
|
||||
}
|
||||
|
||||
var pos = self.CenterPosition;
|
||||
|
||||
@@ -117,9 +117,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// Cannot land so fly towards the last target location instead.
|
||||
if (!newLocation.HasValue)
|
||||
{
|
||||
Cancel(self, true);
|
||||
QueueChild(aircraft.MoveTo(landingCell, 0));
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (newLocation.Value != landingCell)
|
||||
|
||||
@@ -25,16 +25,13 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly RepairableInfo repairableInfo;
|
||||
readonly Rearmable rearmable;
|
||||
readonly bool alwaysLand;
|
||||
readonly bool abortOnResupply;
|
||||
bool resupplied;
|
||||
Actor dest;
|
||||
int facing = -1;
|
||||
|
||||
public ReturnToBase(Actor self, bool abortOnResupply, Actor dest = null, bool alwaysLand = true)
|
||||
public ReturnToBase(Actor self, Actor dest = null, bool alwaysLand = true)
|
||||
{
|
||||
this.dest = dest;
|
||||
this.alwaysLand = alwaysLand;
|
||||
this.abortOnResupply = abortOnResupply;
|
||||
aircraft = self.Trait<Aircraft>();
|
||||
repairableInfo = self.Info.TraitInfoOrDefault<RepairableInfo>();
|
||||
rearmable = self.TraitOrDefault<Rearmable>();
|
||||
@@ -73,17 +70,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (aircraft.ForceLanding)
|
||||
return true;
|
||||
|
||||
// If a Cancel was triggered at this point, it's unlikely that previously queued child activities finished,
|
||||
// so 'resupplied' needs to be set to false, else it + abortOnResupply might cause another Cancel
|
||||
// that would cancel any other activities that were queued after the first Cancel was triggered.
|
||||
// TODO: This is a mess, we need to somehow make the activity cancelling a bit less tricky.
|
||||
if (resupplied && IsCanceling)
|
||||
resupplied = false;
|
||||
|
||||
if (resupplied && abortOnResupply)
|
||||
self.CancelActivity();
|
||||
|
||||
if (resupplied || IsCanceling || self.IsDead)
|
||||
if (IsCanceling || self.IsDead)
|
||||
return true;
|
||||
|
||||
if (dest == null || dest.IsDead || !Reservable.IsAvailableFor(dest, self))
|
||||
@@ -136,11 +123,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
QueueChild(new Resupply(self, dest, WDist.Zero));
|
||||
if (aircraft.Info.TakeOffOnResupply && !alwaysLand)
|
||||
QueueChild(new TakeOff(self));
|
||||
}
|
||||
else
|
||||
QueueChild(new Fly(self, Target.FromActor(dest)));
|
||||
|
||||
resupplied = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QueueChild(new Fly(self, Target.FromActor(dest)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly Harvester harv;
|
||||
readonly Actor targetActor;
|
||||
|
||||
bool isDocking;
|
||||
|
||||
public DeliverResources(Actor self, Actor targetActor = null)
|
||||
{
|
||||
movement = self.Trait<IMove>();
|
||||
@@ -39,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (IsCanceling || isDocking)
|
||||
if (IsCanceling)
|
||||
return true;
|
||||
|
||||
// Find the nearest best refinery if not explicitly ordered to a specific refinery:
|
||||
@@ -66,14 +64,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isDocking)
|
||||
{
|
||||
QueueChild(new Wait(10));
|
||||
isDocking = true;
|
||||
iao.OnDock(self, this);
|
||||
return false;
|
||||
}
|
||||
|
||||
QueueChild(new Wait(10));
|
||||
iao.OnDock(self, this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly GrantConditionOnDeploy deploy;
|
||||
readonly bool canTurn;
|
||||
readonly bool moving;
|
||||
bool initiated;
|
||||
|
||||
public DeployForGrantedCondition(Actor self, GrantConditionOnDeploy deploy, bool moving = false)
|
||||
{
|
||||
@@ -38,13 +37,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
{
|
||||
if (IsCanceling || initiated || (deploy.DeployState != DeployState.Deployed && moving))
|
||||
if (IsCanceling || (deploy.DeployState != DeployState.Deployed && moving))
|
||||
return true;
|
||||
|
||||
QueueChild(new DeployInner(self, deploy));
|
||||
|
||||
initiated = true;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,13 +129,13 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (!unloadAll || !cargo.CanUnload())
|
||||
{
|
||||
Cancel(self, true);
|
||||
|
||||
if (cargo.Info.AfterUnloadDelay > 0)
|
||||
QueueChild(new Wait(cargo.Info.AfterUnloadDelay, false));
|
||||
|
||||
if (takeOffAfterUnload)
|
||||
QueueChild(new TakeOff(self));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Return to the base, which is either the destination given, or an auto-selected one otherwise.")]
|
||||
public void ReturnToBase(Actor destination = null)
|
||||
{
|
||||
Self.QueueActivity(new ReturnToBase(Self, false, destination));
|
||||
Self.QueueActivity(new ReturnToBase(Self, destination));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
|
||||
@@ -1012,7 +1012,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// them to land on a resupplier. For aircraft without it, it makes more sense to land than to idle above a
|
||||
// free resupplier.
|
||||
var forceLand = orderString == "ForceEnter" || !Info.TakeOffOnResupply;
|
||||
self.QueueActivity(order.Queued, new ReturnToBase(self, Info.AbortOnResupply, targetActor, forceLand));
|
||||
self.QueueActivity(order.Queued, new ReturnToBase(self, targetActor, forceLand));
|
||||
}
|
||||
else if (orderString == "Stop")
|
||||
{
|
||||
@@ -1036,7 +1036,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Aircraft with TakeOffOnResupply would immediately take off again, so there's no point in forcing them to land
|
||||
// on a resupplier. For aircraft without it, it makes more sense to land than to idle above a free resupplier.
|
||||
self.QueueActivity(order.Queued, new ReturnToBase(self, Info.AbortOnResupply, null, !Info.TakeOffOnResupply));
|
||||
self.QueueActivity(order.Queued, new ReturnToBase(self, null, !Info.TakeOffOnResupply));
|
||||
}
|
||||
else if (orderString == "Scatter")
|
||||
Nudge(self);
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var resupplier = ReturnToBase.ChooseResupplier(self, true);
|
||||
if (resupplier != null)
|
||||
self.QueueActivity(new ReturnToBase(self, aircraftInfo.AbortOnResupply, resupplier));
|
||||
self.QueueActivity(new ReturnToBase(self, resupplier));
|
||||
else
|
||||
{
|
||||
// nowhere to land, pick something friendly and circle over it.
|
||||
|
||||
Reference in New Issue
Block a user