Add UndeployOnPickup to GrantConditionOnDeploy.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.Mods.Common.Activities;
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -37,6 +37,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public enum LockResponse { Success, Pending, Failed }
|
public enum LockResponse { Success, Pending, Failed }
|
||||||
|
|
||||||
|
public interface IDelayCarryallPickup
|
||||||
|
{
|
||||||
|
bool TryLockForPickup(Actor self, Actor carrier);
|
||||||
|
}
|
||||||
|
|
||||||
public class Carryable : ConditionalTrait<CarryableInfo>
|
public class Carryable : ConditionalTrait<CarryableInfo>
|
||||||
{
|
{
|
||||||
ConditionManager conditionManager;
|
ConditionManager conditionManager;
|
||||||
@@ -45,6 +50,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
int lockedToken = ConditionManager.InvalidConditionToken;
|
int lockedToken = ConditionManager.InvalidConditionToken;
|
||||||
|
|
||||||
Mobile mobile;
|
Mobile mobile;
|
||||||
|
IDelayCarryallPickup[] delayPickups;
|
||||||
|
|
||||||
public Actor Carrier { get; private set; }
|
public Actor Carrier { get; private set; }
|
||||||
public bool Reserved { get { return state != State.Free; } }
|
public bool Reserved { get { return state != State.Free; } }
|
||||||
@@ -62,6 +68,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
conditionManager = self.Trait<ConditionManager>();
|
conditionManager = self.Trait<ConditionManager>();
|
||||||
mobile = self.TraitOrDefault<Mobile>();
|
mobile = self.TraitOrDefault<Mobile>();
|
||||||
|
delayPickups = self.TraitsImplementing<IDelayCarryallPickup>().ToArray();
|
||||||
|
|
||||||
base.Created(self);
|
base.Created(self);
|
||||||
}
|
}
|
||||||
@@ -121,6 +128,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (state == State.Locked && Carrier != carrier)
|
if (state == State.Locked && Carrier != carrier)
|
||||||
return LockResponse.Failed;
|
return LockResponse.Failed;
|
||||||
|
|
||||||
|
if (delayPickups.Any(d => d.IsTraitEnabled() && !d.TryLockForPickup(self, carrier)))
|
||||||
|
return LockResponse.Pending;
|
||||||
|
|
||||||
if (state != State.Locked)
|
if (state != State.Locked)
|
||||||
{
|
{
|
||||||
state = State.Locked;
|
state = State.Locked;
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Undeploy before the actor tries to move?")]
|
[Desc("Undeploy before the actor tries to move?")]
|
||||||
public readonly bool UndeployOnMove = false;
|
public readonly bool UndeployOnMove = false;
|
||||||
|
|
||||||
|
[Desc("Undeploy before the actor is picked up by a Carryall?")]
|
||||||
|
public readonly bool UndeployOnPickup = false;
|
||||||
|
|
||||||
[VoiceReference]
|
[VoiceReference]
|
||||||
public readonly string Voice = "Action";
|
public readonly string Voice = "Action";
|
||||||
|
|
||||||
@@ -87,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public enum DeployState { Undeployed, Deploying, Deployed, Undeploying }
|
public enum DeployState { Undeployed, Deploying, Deployed, Undeploying }
|
||||||
|
|
||||||
public class GrantConditionOnDeploy : PausableConditionalTrait<GrantConditionOnDeployInfo>, IResolveOrder, IIssueOrder,
|
public class GrantConditionOnDeploy : PausableConditionalTrait<GrantConditionOnDeployInfo>, IResolveOrder, IIssueOrder,
|
||||||
INotifyDeployComplete, IIssueDeployOrder, IOrderVoice, IWrapMove
|
INotifyDeployComplete, IIssueDeployOrder, IOrderVoice, IWrapMove, IDelayCarryallPickup
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly bool checkTerrainType;
|
readonly bool checkTerrainType;
|
||||||
@@ -157,6 +160,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return activity;
|
return activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IDelayCarryallPickup.TryLockForPickup(Actor self, Actor carrier)
|
||||||
|
{
|
||||||
|
if (!Info.UndeployOnPickup || deployState == DeployState.Undeployed || IsTraitDisabled)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (deployState == DeployState.Deployed && !IsTraitPaused)
|
||||||
|
Undeploy();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerable<IOrderTargeter> IIssueOrder.Orders
|
IEnumerable<IOrderTargeter> IIssueOrder.Orders
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
Reference in New Issue
Block a user