diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
index c65b6b5f84..cebf038225 100644
--- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
+++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
@@ -490,7 +490,7 @@
-
+
diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/GrantConditionOnDeploy.cs
similarity index 82%
rename from OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs
rename to OpenRA.Mods.Common/Traits/Upgrades/GrantConditionOnDeploy.cs
index 317b303c69..3272deeb24 100644
--- a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs
+++ b/OpenRA.Mods.Common/Traits/Upgrades/GrantConditionOnDeploy.cs
@@ -19,15 +19,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
- public class DeployToUpgradeInfo : ITraitInfo, Requires
+ public class GrantConditionOnDeployInfo : ITraitInfo
{
[UpgradeGrantedReference]
- [Desc("The upgrades to grant while the actor is undeployed.")]
- public readonly string[] UndeployedUpgrades = { };
+ [Desc("The condition to grant while the actor is undeployed.")]
+ public readonly string UndeployedCondition = null;
[UpgradeGrantedReference, FieldLoader.Require]
- [Desc("The upgrades to grant after deploying and revoke before undeploying.")]
- public readonly string[] DeployedUpgrades = { };
+ [Desc("The condition to grant after deploying and revoke before undeploying.")]
+ public readonly string DeployedCondition = null;
[Desc("The terrain types that this actor can deploy on to receive these upgrades. " +
"Leave empty to allow any.")]
@@ -57,27 +57,28 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Can this actor undeploy?")]
public readonly bool CanUndeploy = true;
- public object Create(ActorInitializer init) { return new DeployToUpgrade(init, this); }
+ public object Create(ActorInitializer init) { return new GrantConditionOnDeploy(init, this); }
}
public enum DeployState { Undeployed, Deploying, Deployed, Undeploying }
- public class DeployToUpgrade : IResolveOrder, IIssueOrder, INotifyCreated
+ public class GrantConditionOnDeploy : IResolveOrder, IIssueOrder, INotifyCreated
{
readonly Actor self;
- readonly DeployToUpgradeInfo info;
- readonly UpgradeManager manager;
+ readonly GrantConditionOnDeployInfo info;
readonly bool checkTerrainType;
readonly bool canTurn;
readonly Lazy body;
DeployState deployState;
+ UpgradeManager manager;
+ int deployedToken = UpgradeManager.InvalidConditionToken;
+ int undeployedToken = UpgradeManager.InvalidConditionToken;
- public DeployToUpgrade(ActorInitializer init, DeployToUpgradeInfo info)
+ public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info)
{
self = init.Self;
this.info = info;
- manager = self.Trait();
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
canTurn = self.Info.HasTraitInfo();
body = Exts.Lazy(self.TraitOrDefault);
@@ -87,6 +88,8 @@ namespace OpenRA.Mods.Common.Traits
public void Created(Actor self)
{
+ manager = self.TraitOrDefault();
+
switch (deployState)
{
case DeployState.Undeployed:
@@ -239,32 +242,32 @@ namespace OpenRA.Mods.Common.Traits
void OnDeployStarted()
{
- foreach (var up in info.UndeployedUpgrades)
- manager.RevokeUpgrade(self, up, this);
+ if (undeployedToken != UpgradeManager.InvalidConditionToken)
+ undeployedToken = manager.RevokeCondition(self, undeployedToken);
deployState = DeployState.Deploying;
}
void OnDeployCompleted()
{
- foreach (var up in info.DeployedUpgrades)
- manager.GrantUpgrade(self, up, this);
+ if (manager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == UpgradeManager.InvalidConditionToken)
+ deployedToken = manager.GrantCondition(self, info.DeployedCondition);
deployState = DeployState.Deployed;
}
void OnUndeployStarted()
{
- foreach (var up in info.DeployedUpgrades)
- manager.RevokeUpgrade(self, up, this);
+ if (deployedToken != UpgradeManager.InvalidConditionToken)
+ deployedToken = manager.RevokeCondition(self, deployedToken);
deployState = DeployState.Deploying;
}
void OnUndeployCompleted()
{
- foreach (var up in info.UndeployedUpgrades)
- manager.GrantUpgrade(self, up, this);
+ if (manager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == UpgradeManager.InvalidConditionToken)
+ undeployedToken = manager.GrantCondition(self, info.UndeployedCondition);
deployState = DeployState.Undeployed;
}
diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs
index 0404547e9f..decab150d9 100644
--- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs
+++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs
@@ -668,6 +668,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (node.Key.StartsWith("GlobalUpgradeManager", StringComparison.Ordinal))
RenameNodeKey(node, "GrantConditionOnPrerequisiteManager");
+
+ if (node.Key.StartsWith("DeployToUpgrade", StringComparison.Ordinal))
+ {
+ RenameNodeKey(node, "GrantConditionOnDeploy");
+ ConvertUpgradesToCondition(parent, node, "UndeployedUpgrades", "UndeployedCondition");
+ ConvertUpgradesToCondition(parent, node, "DeployedUpgrades", "DeployedCondition");
+ }
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
diff --git a/mods/d2k/rules/infantry.yaml b/mods/d2k/rules/infantry.yaml
index 61d76e4aff..ecb99177e1 100644
--- a/mods/d2k/rules/infantry.yaml
+++ b/mods/d2k/rules/infantry.yaml
@@ -96,8 +96,8 @@ thumper:
Mobile:
Speed: 43
RequiresCondition: !deployed
- DeployToUpgrade:
- DeployedUpgrades: deployed
+ GrantConditionOnDeploy:
+ DeployedCondition: deployed
Facing: 128
AllowedTerrainTypes: Sand, Spice, Dune, SpiceSand
WithInfantryBody:
diff --git a/mods/ts/rules/nod-vehicles.yaml b/mods/ts/rules/nod-vehicles.yaml
index 091508cc0a..8c1259b06f 100644
--- a/mods/ts/rules/nod-vehicles.yaml
+++ b/mods/ts/rules/nod-vehicles.yaml
@@ -105,9 +105,9 @@ TTNK:
MaxHeightDelta: 3
RenderSprites:
Image: ttnk
- DeployToUpgrade:
- DeployedUpgrades: deployed
- UndeployedUpgrades: undeployed
+ GrantConditionOnDeploy:
+ DeployedCondition: deployed
+ UndeployedCondition: undeployed
DeployAnimation: make
Facing: 160
AllowedTerrainTypes: Clear, Road, DirtRoad, Rough
diff --git a/mods/ts/rules/shared-vehicles.yaml b/mods/ts/rules/shared-vehicles.yaml
index 739dce9f9c..282fe137e7 100644
--- a/mods/ts/rules/shared-vehicles.yaml
+++ b/mods/ts/rules/shared-vehicles.yaml
@@ -137,9 +137,9 @@ LPST:
FactionImages:
gdi: lpst.gdi
nod: lpst.nod
- DeployToUpgrade:
- DeployedUpgrades: deployed
- UndeployedUpgrades: undeployed
+ GrantConditionOnDeploy:
+ DeployedCondition: deployed
+ UndeployedCondition: undeployed
DeployAnimation: make
Facing: 160
AllowedTerrainTypes: Clear, Road, DirtRoad, Rough
@@ -156,4 +156,4 @@ LPST:
RenderDetectionCircle:
TrailCount: 3
Carryable:
- RequiresCondition: undeployed
\ No newline at end of file
+ RequiresCondition: undeployed