Allow move orders to cancel DeployForGrantedCondition.
This commit is contained in:
@@ -19,49 +19,71 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
readonly GrantConditionOnDeploy deploy;
|
||||
readonly bool canTurn;
|
||||
readonly bool moving;
|
||||
bool initiated;
|
||||
|
||||
public DeployForGrantedCondition(Actor self, GrantConditionOnDeploy deploy)
|
||||
public DeployForGrantedCondition(Actor self, GrantConditionOnDeploy deploy, bool moving = false)
|
||||
{
|
||||
this.deploy = deploy;
|
||||
this.moving = moving;
|
||||
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
|
||||
}
|
||||
|
||||
protected override void OnFirstRun(Actor self)
|
||||
{
|
||||
// Turn to the required facing.
|
||||
if (deploy.Info.Facing != -1 && canTurn)
|
||||
if (deploy.DeployState == DeployState.Undeployed && deploy.Info.Facing != -1 && canTurn && !moving)
|
||||
QueueChild(self, new Turn(self, deploy.Info.Facing));
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
// Do turn first, if needed.
|
||||
if (ChildActivity != null)
|
||||
{
|
||||
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
|
||||
return this;
|
||||
if (ChildActivity != null)
|
||||
return this;
|
||||
}
|
||||
|
||||
// Without this, turn for facing deploy angle will be canceled and immediately deploy!
|
||||
if (IsCanceling)
|
||||
if (IsCanceling || initiated || (deploy.DeployState != DeployState.Deployed && moving))
|
||||
return NextActivity;
|
||||
|
||||
if (IsInterruptible)
|
||||
{
|
||||
IsInterruptible = false; // must DEPLOY from now.
|
||||
deploy.Deploy();
|
||||
return this;
|
||||
}
|
||||
QueueChild(self, new DeployInner(self, deploy), true);
|
||||
|
||||
initiated = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class DeployInner : Activity
|
||||
{
|
||||
readonly GrantConditionOnDeploy deployment;
|
||||
bool initiated;
|
||||
|
||||
public DeployInner(Actor self, GrantConditionOnDeploy deployment)
|
||||
{
|
||||
this.deployment = deployment;
|
||||
|
||||
// Once deployment animation starts, the animation must finish.
|
||||
IsInterruptible = false;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
// Wait for deployment
|
||||
if (deploy.DeployState == DeployState.Deploying)
|
||||
if (deployment.DeployState == DeployState.Deploying || deployment.DeployState == DeployState.Undeploying)
|
||||
return this;
|
||||
|
||||
// Failed or success, we are going to NextActivity.
|
||||
// Deploy() at the first run would have put DeployState == Deploying so
|
||||
// if we are back to DeployState.Undeployed, it means deploy failure.
|
||||
// Parent activity will see the status and will take appropriate action.
|
||||
return NextActivity;
|
||||
if (initiated)
|
||||
return NextActivity;
|
||||
|
||||
if (deployment.DeployState == DeployState.Undeployed)
|
||||
deployment.Deploy();
|
||||
else
|
||||
deployment.Undeploy();
|
||||
|
||||
initiated = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user