Convert DeployToUpgrade to conditions.
This commit is contained in:
@@ -490,7 +490,7 @@
|
|||||||
<Compile Include="Traits\Transforms.cs" />
|
<Compile Include="Traits\Transforms.cs" />
|
||||||
<Compile Include="Traits\Turreted.cs" />
|
<Compile Include="Traits\Turreted.cs" />
|
||||||
<Compile Include="Traits\ProducibleWithLevel.cs" />
|
<Compile Include="Traits\ProducibleWithLevel.cs" />
|
||||||
<Compile Include="Traits\Upgrades\DeployToUpgrade.cs" />
|
<Compile Include="Traits\Upgrades\GrantConditionOnDeploy.cs" />
|
||||||
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||||
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
||||||
|
|||||||
@@ -19,15 +19,15 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
public class DeployToUpgradeInfo : ITraitInfo, Requires<UpgradeManagerInfo>
|
public class GrantConditionOnDeployInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
[UpgradeGrantedReference]
|
[UpgradeGrantedReference]
|
||||||
[Desc("The upgrades to grant while the actor is undeployed.")]
|
[Desc("The condition to grant while the actor is undeployed.")]
|
||||||
public readonly string[] UndeployedUpgrades = { };
|
public readonly string UndeployedCondition = null;
|
||||||
|
|
||||||
[UpgradeGrantedReference, FieldLoader.Require]
|
[UpgradeGrantedReference, FieldLoader.Require]
|
||||||
[Desc("The upgrades to grant after deploying and revoke before undeploying.")]
|
[Desc("The condition to grant after deploying and revoke before undeploying.")]
|
||||||
public readonly string[] DeployedUpgrades = { };
|
public readonly string DeployedCondition = null;
|
||||||
|
|
||||||
[Desc("The terrain types that this actor can deploy on to receive these upgrades. " +
|
[Desc("The terrain types that this actor can deploy on to receive these upgrades. " +
|
||||||
"Leave empty to allow any.")]
|
"Leave empty to allow any.")]
|
||||||
@@ -57,27 +57,28 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Can this actor undeploy?")]
|
[Desc("Can this actor undeploy?")]
|
||||||
public readonly bool CanUndeploy = true;
|
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 enum DeployState { Undeployed, Deploying, Deployed, Undeploying }
|
||||||
|
|
||||||
public class DeployToUpgrade : IResolveOrder, IIssueOrder, INotifyCreated
|
public class GrantConditionOnDeploy : IResolveOrder, IIssueOrder, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly DeployToUpgradeInfo info;
|
readonly GrantConditionOnDeployInfo info;
|
||||||
readonly UpgradeManager manager;
|
|
||||||
readonly bool checkTerrainType;
|
readonly bool checkTerrainType;
|
||||||
readonly bool canTurn;
|
readonly bool canTurn;
|
||||||
readonly Lazy<WithSpriteBody> body;
|
readonly Lazy<WithSpriteBody> body;
|
||||||
|
|
||||||
DeployState deployState;
|
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;
|
self = init.Self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
manager = self.Trait<UpgradeManager>();
|
|
||||||
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
|
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
|
||||||
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
|
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
|
||||||
body = Exts.Lazy(self.TraitOrDefault<WithSpriteBody>);
|
body = Exts.Lazy(self.TraitOrDefault<WithSpriteBody>);
|
||||||
@@ -87,6 +88,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void Created(Actor self)
|
public void Created(Actor self)
|
||||||
{
|
{
|
||||||
|
manager = self.TraitOrDefault<UpgradeManager>();
|
||||||
|
|
||||||
switch (deployState)
|
switch (deployState)
|
||||||
{
|
{
|
||||||
case DeployState.Undeployed:
|
case DeployState.Undeployed:
|
||||||
@@ -239,32 +242,32 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void OnDeployStarted()
|
void OnDeployStarted()
|
||||||
{
|
{
|
||||||
foreach (var up in info.UndeployedUpgrades)
|
if (undeployedToken != UpgradeManager.InvalidConditionToken)
|
||||||
manager.RevokeUpgrade(self, up, this);
|
undeployedToken = manager.RevokeCondition(self, undeployedToken);
|
||||||
|
|
||||||
deployState = DeployState.Deploying;
|
deployState = DeployState.Deploying;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDeployCompleted()
|
void OnDeployCompleted()
|
||||||
{
|
{
|
||||||
foreach (var up in info.DeployedUpgrades)
|
if (manager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == UpgradeManager.InvalidConditionToken)
|
||||||
manager.GrantUpgrade(self, up, this);
|
deployedToken = manager.GrantCondition(self, info.DeployedCondition);
|
||||||
|
|
||||||
deployState = DeployState.Deployed;
|
deployState = DeployState.Deployed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUndeployStarted()
|
void OnUndeployStarted()
|
||||||
{
|
{
|
||||||
foreach (var up in info.DeployedUpgrades)
|
if (deployedToken != UpgradeManager.InvalidConditionToken)
|
||||||
manager.RevokeUpgrade(self, up, this);
|
deployedToken = manager.RevokeCondition(self, deployedToken);
|
||||||
|
|
||||||
deployState = DeployState.Deploying;
|
deployState = DeployState.Deploying;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUndeployCompleted()
|
void OnUndeployCompleted()
|
||||||
{
|
{
|
||||||
foreach (var up in info.UndeployedUpgrades)
|
if (manager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == UpgradeManager.InvalidConditionToken)
|
||||||
manager.GrantUpgrade(self, up, this);
|
undeployedToken = manager.GrantCondition(self, info.UndeployedCondition);
|
||||||
|
|
||||||
deployState = DeployState.Undeployed;
|
deployState = DeployState.Undeployed;
|
||||||
}
|
}
|
||||||
@@ -668,6 +668,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
if (node.Key.StartsWith("GlobalUpgradeManager", StringComparison.Ordinal))
|
if (node.Key.StartsWith("GlobalUpgradeManager", StringComparison.Ordinal))
|
||||||
RenameNodeKey(node, "GrantConditionOnPrerequisiteManager");
|
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);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ thumper:
|
|||||||
Mobile:
|
Mobile:
|
||||||
Speed: 43
|
Speed: 43
|
||||||
RequiresCondition: !deployed
|
RequiresCondition: !deployed
|
||||||
DeployToUpgrade:
|
GrantConditionOnDeploy:
|
||||||
DeployedUpgrades: deployed
|
DeployedCondition: deployed
|
||||||
Facing: 128
|
Facing: 128
|
||||||
AllowedTerrainTypes: Sand, Spice, Dune, SpiceSand
|
AllowedTerrainTypes: Sand, Spice, Dune, SpiceSand
|
||||||
WithInfantryBody:
|
WithInfantryBody:
|
||||||
|
|||||||
@@ -105,9 +105,9 @@ TTNK:
|
|||||||
MaxHeightDelta: 3
|
MaxHeightDelta: 3
|
||||||
RenderSprites:
|
RenderSprites:
|
||||||
Image: ttnk
|
Image: ttnk
|
||||||
DeployToUpgrade:
|
GrantConditionOnDeploy:
|
||||||
DeployedUpgrades: deployed
|
DeployedCondition: deployed
|
||||||
UndeployedUpgrades: undeployed
|
UndeployedCondition: undeployed
|
||||||
DeployAnimation: make
|
DeployAnimation: make
|
||||||
Facing: 160
|
Facing: 160
|
||||||
AllowedTerrainTypes: Clear, Road, DirtRoad, Rough
|
AllowedTerrainTypes: Clear, Road, DirtRoad, Rough
|
||||||
|
|||||||
@@ -137,9 +137,9 @@ LPST:
|
|||||||
FactionImages:
|
FactionImages:
|
||||||
gdi: lpst.gdi
|
gdi: lpst.gdi
|
||||||
nod: lpst.nod
|
nod: lpst.nod
|
||||||
DeployToUpgrade:
|
GrantConditionOnDeploy:
|
||||||
DeployedUpgrades: deployed
|
DeployedCondition: deployed
|
||||||
UndeployedUpgrades: undeployed
|
UndeployedCondition: undeployed
|
||||||
DeployAnimation: make
|
DeployAnimation: make
|
||||||
Facing: 160
|
Facing: 160
|
||||||
AllowedTerrainTypes: Clear, Road, DirtRoad, Rough
|
AllowedTerrainTypes: Clear, Road, DirtRoad, Rough
|
||||||
@@ -156,4 +156,4 @@ LPST:
|
|||||||
RenderDetectionCircle:
|
RenderDetectionCircle:
|
||||||
TrailCount: 3
|
TrailCount: 3
|
||||||
Carryable:
|
Carryable:
|
||||||
RequiresCondition: undeployed
|
RequiresCondition: undeployed
|
||||||
|
|||||||
Reference in New Issue
Block a user