Simplify special exits of several acitivities.

This commit is contained in:
tovl
2019-06-30 20:53:36 +02:00
committed by teinarss
parent 3790169db9
commit 985020b4ad
9 changed files with 20 additions and 45 deletions

View File

@@ -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 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))) if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
{ {
QueueChild(new ReturnToBase(self, aircraft.Info.AbortOnResupply)); QueueChild(new ReturnToBase(self));
return false; return aircraft.Info.AbortOnResupply;
} }
var pos = self.CenterPosition; var pos = self.CenterPosition;

View File

@@ -117,9 +117,8 @@ namespace OpenRA.Mods.Common.Activities
// Cannot land so fly towards the last target location instead. // Cannot land so fly towards the last target location instead.
if (!newLocation.HasValue) if (!newLocation.HasValue)
{ {
Cancel(self, true);
QueueChild(aircraft.MoveTo(landingCell, 0)); QueueChild(aircraft.MoveTo(landingCell, 0));
return false; return true;
} }
if (newLocation.Value != landingCell) if (newLocation.Value != landingCell)

View File

@@ -25,16 +25,13 @@ namespace OpenRA.Mods.Common.Activities
readonly RepairableInfo repairableInfo; readonly RepairableInfo repairableInfo;
readonly Rearmable rearmable; readonly Rearmable rearmable;
readonly bool alwaysLand; readonly bool alwaysLand;
readonly bool abortOnResupply;
bool resupplied;
Actor dest; Actor dest;
int facing = -1; 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.dest = dest;
this.alwaysLand = alwaysLand; this.alwaysLand = alwaysLand;
this.abortOnResupply = abortOnResupply;
aircraft = self.Trait<Aircraft>(); aircraft = self.Trait<Aircraft>();
repairableInfo = self.Info.TraitInfoOrDefault<RepairableInfo>(); repairableInfo = self.Info.TraitInfoOrDefault<RepairableInfo>();
rearmable = self.TraitOrDefault<Rearmable>(); rearmable = self.TraitOrDefault<Rearmable>();
@@ -73,17 +70,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding) if (aircraft.ForceLanding)
return true; return true;
// If a Cancel was triggered at this point, it's unlikely that previously queued child activities finished, if (IsCanceling || self.IsDead)
// 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)
return true; return true;
if (dest == null || dest.IsDead || !Reservable.IsAvailableFor(dest, self)) 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)); QueueChild(new Resupply(self, dest, WDist.Zero));
if (aircraft.Info.TakeOffOnResupply && !alwaysLand) if (aircraft.Info.TakeOffOnResupply && !alwaysLand)
QueueChild(new TakeOff(self)); 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; return false;
} }
} }

View File

@@ -22,8 +22,6 @@ namespace OpenRA.Mods.Common.Activities
readonly Harvester harv; readonly Harvester harv;
readonly Actor targetActor; readonly Actor targetActor;
bool isDocking;
public DeliverResources(Actor self, Actor targetActor = null) public DeliverResources(Actor self, Actor targetActor = null)
{ {
movement = self.Trait<IMove>(); movement = self.Trait<IMove>();
@@ -39,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self) public override bool Tick(Actor self)
{ {
if (IsCanceling || isDocking) if (IsCanceling)
return true; return true;
// Find the nearest best refinery if not explicitly ordered to a specific refinery: // Find the nearest best refinery if not explicitly ordered to a specific refinery:
@@ -66,14 +64,8 @@ namespace OpenRA.Mods.Common.Activities
return false; return false;
} }
if (!isDocking) QueueChild(new Wait(10));
{ iao.OnDock(self, this);
QueueChild(new Wait(10));
isDocking = true;
iao.OnDock(self, this);
return false;
}
return true; return true;
} }
} }

View File

@@ -20,7 +20,6 @@ namespace OpenRA.Mods.Common.Activities
readonly GrantConditionOnDeploy deploy; readonly GrantConditionOnDeploy deploy;
readonly bool canTurn; readonly bool canTurn;
readonly bool moving; readonly bool moving;
bool initiated;
public DeployForGrantedCondition(Actor self, GrantConditionOnDeploy deploy, bool moving = false) public DeployForGrantedCondition(Actor self, GrantConditionOnDeploy deploy, bool moving = false)
{ {
@@ -38,13 +37,11 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self) public override bool Tick(Actor self)
{ {
if (IsCanceling || initiated || (deploy.DeployState != DeployState.Deployed && moving)) if (IsCanceling || (deploy.DeployState != DeployState.Deployed && moving))
return true; return true;
QueueChild(new DeployInner(self, deploy)); QueueChild(new DeployInner(self, deploy));
return true;
initiated = true;
return false;
} }
} }

View File

@@ -129,13 +129,13 @@ namespace OpenRA.Mods.Common.Activities
if (!unloadAll || !cargo.CanUnload()) if (!unloadAll || !cargo.CanUnload())
{ {
Cancel(self, true);
if (cargo.Info.AfterUnloadDelay > 0) if (cargo.Info.AfterUnloadDelay > 0)
QueueChild(new Wait(cargo.Info.AfterUnloadDelay, false)); QueueChild(new Wait(cargo.Info.AfterUnloadDelay, false));
if (takeOffAfterUnload) if (takeOffAfterUnload)
QueueChild(new TakeOff(self)); QueueChild(new TakeOff(self));
return true;
} }
return false; return false;

View File

@@ -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.")] [Desc("Return to the base, which is either the destination given, or an auto-selected one otherwise.")]
public void ReturnToBase(Actor destination = null) public void ReturnToBase(Actor destination = null)
{ {
Self.QueueActivity(new ReturnToBase(Self, false, destination)); Self.QueueActivity(new ReturnToBase(Self, destination));
} }
[ScriptActorPropertyActivity] [ScriptActorPropertyActivity]

View File

@@ -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 // them to land on a resupplier. For aircraft without it, it makes more sense to land than to idle above a
// free resupplier. // free resupplier.
var forceLand = orderString == "ForceEnter" || !Info.TakeOffOnResupply; 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") 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 // 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. // 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") else if (orderString == "Scatter")
Nudge(self); Nudge(self);

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
var resupplier = ReturnToBase.ChooseResupplier(self, true); var resupplier = ReturnToBase.ChooseResupplier(self, true);
if (resupplier != null) if (resupplier != null)
self.QueueActivity(new ReturnToBase(self, aircraftInfo.AbortOnResupply, resupplier)); self.QueueActivity(new ReturnToBase(self, resupplier));
else else
{ {
// nowhere to land, pick something friendly and circle over it. // nowhere to land, pick something friendly and circle over it.