Deploy activities for mods and future AI scripting
This commit is contained in:
69
OpenRA.Mods.Common/Activities/DeployForGrantedCondition.cs
Normal file
69
OpenRA.Mods.Common/Activities/DeployForGrantedCondition.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2017 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 DeployForGrantedCondition : Activity
|
||||||
|
{
|
||||||
|
readonly GrantConditionOnDeploy deploy;
|
||||||
|
readonly int facing;
|
||||||
|
readonly bool canTurn;
|
||||||
|
|
||||||
|
public DeployForGrantedCondition(Actor self) : base()
|
||||||
|
{
|
||||||
|
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
|
||||||
|
facing = self.Info.TraitInfo<GrantConditionOnDeployInfo>().Facing;
|
||||||
|
deploy = self.Trait<GrantConditionOnDeploy>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFirstRun(Actor self)
|
||||||
|
{
|
||||||
|
// Turn to the required facing.
|
||||||
|
if (facing != -1 && canTurn)
|
||||||
|
QueueChild(new Turn(self, facing));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Activity Tick(Actor self)
|
||||||
|
{
|
||||||
|
// Do turn first, if needed.
|
||||||
|
if (ChildActivity != null)
|
||||||
|
{
|
||||||
|
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Without this, turn for facing deploy angle will be canceled and immediately deploy!
|
||||||
|
if (IsCanceled)
|
||||||
|
return NextActivity;
|
||||||
|
|
||||||
|
if (IsInterruptible)
|
||||||
|
{
|
||||||
|
IsInterruptible = false; // must DEPLOY from now.
|
||||||
|
deploy.Deploy();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for deployment
|
||||||
|
if (deploy.DeployState == DeployState.Deploying)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
OpenRA.Mods.Common/Activities/UndeployForGrantedCondition.cs
Normal file
39
OpenRA.Mods.Common/Activities/UndeployForGrantedCondition.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2017 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) : base()
|
||||||
|
{
|
||||||
|
deploy = self.Trait<GrantConditionOnDeploy>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,6 +92,7 @@
|
|||||||
<Compile Include="Activities\CaptureActor.cs" />
|
<Compile Include="Activities\CaptureActor.cs" />
|
||||||
<Compile Include="Activities\DeliverResources.cs" />
|
<Compile Include="Activities\DeliverResources.cs" />
|
||||||
<Compile Include="Activities\Demolish.cs" />
|
<Compile Include="Activities\Demolish.cs" />
|
||||||
|
<Compile Include="Activities\DeployForGrantedCondition.cs" />
|
||||||
<Compile Include="Activities\DonateCash.cs" />
|
<Compile Include="Activities\DonateCash.cs" />
|
||||||
<Compile Include="Activities\Enter.cs" />
|
<Compile Include="Activities\Enter.cs" />
|
||||||
<Compile Include="Activities\EnterTransport.cs" />
|
<Compile Include="Activities\EnterTransport.cs" />
|
||||||
@@ -117,6 +118,7 @@
|
|||||||
<Compile Include="Activities\SpriteHarvesterDockSequence.cs" />
|
<Compile Include="Activities\SpriteHarvesterDockSequence.cs" />
|
||||||
<Compile Include="Activities\Transform.cs" />
|
<Compile Include="Activities\Transform.cs" />
|
||||||
<Compile Include="Activities\Turn.cs" />
|
<Compile Include="Activities\Turn.cs" />
|
||||||
|
<Compile Include="Activities\UndeployForGrantedCondition.cs" />
|
||||||
<Compile Include="Activities\UnloadCargo.cs" />
|
<Compile Include="Activities\UnloadCargo.cs" />
|
||||||
<Compile Include="Activities\Wait.cs" />
|
<Compile Include="Activities\Wait.cs" />
|
||||||
<Compile Include="Activities\WaitForTransport.cs" />
|
<Compile Include="Activities\WaitForTransport.cs" />
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
int deployedToken = ConditionManager.InvalidConditionToken;
|
int deployedToken = ConditionManager.InvalidConditionToken;
|
||||||
int undeployedToken = ConditionManager.InvalidConditionToken;
|
int undeployedToken = ConditionManager.InvalidConditionToken;
|
||||||
|
|
||||||
|
public DeployState DeployState { get { return deployState; } }
|
||||||
|
|
||||||
public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info)
|
public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info)
|
||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
@@ -142,17 +144,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
|
|
||||||
if (deployState == DeployState.Deployed && info.CanUndeploy)
|
if (deployState == DeployState.Deployed && info.CanUndeploy)
|
||||||
{
|
self.QueueActivity(new UndeployForGrantedCondition(self));
|
||||||
self.QueueActivity(new CallFunc(Undeploy));
|
|
||||||
}
|
|
||||||
else if (deployState == DeployState.Undeployed)
|
else if (deployState == DeployState.Undeployed)
|
||||||
{
|
self.QueueActivity(new DeployForGrantedCondition(self));
|
||||||
// Turn to the required facing.
|
|
||||||
if (info.Facing != -1 && canTurn)
|
|
||||||
self.QueueActivity(new Turn(self, info.Facing));
|
|
||||||
|
|
||||||
self.QueueActivity(new CallFunc(Deploy));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCursorBlocked()
|
bool IsCursorBlocked()
|
||||||
@@ -206,7 +200,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Play deploy sound and animation.</summary>
|
/// <summary>Play deploy sound and animation.</summary>
|
||||||
void Deploy() { Deploy(false); }
|
public void Deploy() { Deploy(false); }
|
||||||
void Deploy(bool init)
|
void Deploy(bool init)
|
||||||
{
|
{
|
||||||
// Something went wrong, most likely due to deploy order spam and the fact that this is a delayed action.
|
// Something went wrong, most likely due to deploy order spam and the fact that this is a delayed action.
|
||||||
@@ -233,7 +227,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Play undeploy sound and animation and after that revoke the condition.</summary>
|
/// <summary>Play undeploy sound and animation and after that revoke the condition.</summary>
|
||||||
void Undeploy() { Undeploy(false); }
|
public void Undeploy() { Undeploy(false); }
|
||||||
void Undeploy(bool init)
|
void Undeploy(bool init)
|
||||||
{
|
{
|
||||||
// Something went wrong, most likely due to deploy order spam and the fact that this is a delayed action.
|
// Something went wrong, most likely due to deploy order spam and the fact that this is a delayed action.
|
||||||
|
|||||||
Reference in New Issue
Block a user