Allow move orders to cancel DeployForGrantedCondition.

This commit is contained in:
tovl
2019-06-07 22:14:47 +00:00
committed by reaperrr
parent 8589e26dc2
commit ea036d4cc0
9 changed files with 99 additions and 88 deletions

View File

@@ -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;
}
}
}

View File

@@ -1,39 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
{
public class UndeployForGrantedCondition : Activity
{
readonly GrantConditionOnDeploy deploy;
public UndeployForGrantedCondition(Actor self, GrantConditionOnDeploy deploy)
{
this.deploy = deploy;
}
public override Activity Tick(Actor self)
{
IsInterruptible = false; // must DEPLOY from now.
deploy.Undeploy();
// Wait for deployment
if (deploy.DeployState == DeployState.Undeploying)
return this;
return NextActivity;
}
}
}