Merge pull request #9501 from atlimit8/DeployedInit
Add DeployStateInit for Pre-deployment and Clean Up after #9124
This commit is contained in:
@@ -52,13 +52,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Sound to play when undeploying.")]
|
[Desc("Sound to play when undeploying.")]
|
||||||
public readonly string UndeploySound = null;
|
public readonly string UndeploySound = null;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); }
|
public object Create(ActorInitializer init) { return new DeployToUpgrade(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DeployState { Undeployed, Deploying, Deployed, Undeploying }
|
||||||
|
|
||||||
public class DeployToUpgrade : IResolveOrder, IIssueOrder, INotifyCreated
|
public class DeployToUpgrade : IResolveOrder, IIssueOrder, INotifyCreated
|
||||||
{
|
{
|
||||||
enum DeployState { Undeployed, Deploying, Deployed }
|
|
||||||
|
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly DeployToUpgradeInfo info;
|
readonly DeployToUpgradeInfo info;
|
||||||
readonly UpgradeManager manager;
|
readonly UpgradeManager manager;
|
||||||
@@ -68,19 +68,44 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
DeployState deployState;
|
DeployState deployState;
|
||||||
|
|
||||||
public DeployToUpgrade(Actor self, DeployToUpgradeInfo info)
|
public DeployToUpgrade(ActorInitializer init, DeployToUpgradeInfo info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = init.Self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
manager = self.Trait<UpgradeManager>();
|
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<ISpriteBody>);
|
body = Exts.Lazy(self.TraitOrDefault<ISpriteBody>);
|
||||||
|
if (init.Contains<DeployStateInit>())
|
||||||
|
deployState = init.Get<DeployStateInit, DeployState>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Created(Actor self)
|
public void Created(Actor self)
|
||||||
{
|
{
|
||||||
|
switch (deployState)
|
||||||
|
{
|
||||||
|
case DeployState.Undeployed:
|
||||||
OnUndeployCompleted();
|
OnUndeployCompleted();
|
||||||
|
break;
|
||||||
|
case DeployState.Deploying:
|
||||||
|
if (canTurn)
|
||||||
|
self.Trait<IFacing>().Facing = info.Facing;
|
||||||
|
|
||||||
|
Deploy(true);
|
||||||
|
break;
|
||||||
|
case DeployState.Deployed:
|
||||||
|
if (canTurn)
|
||||||
|
self.Trait<IFacing>().Facing = info.Facing;
|
||||||
|
|
||||||
|
OnDeployCompleted();
|
||||||
|
break;
|
||||||
|
case DeployState.Undeploying:
|
||||||
|
if (canTurn)
|
||||||
|
self.Trait<IFacing>().Facing = info.Facing;
|
||||||
|
|
||||||
|
Undeploy(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
@@ -99,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void ResolveOrder(Actor self, Order order)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (order.OrderString != "DeployToUpgrade" || deployState == DeployState.Deploying)
|
if (order.OrderString != "DeployToUpgrade" || deployState == DeployState.Deploying || deployState == DeployState.Undeploying)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!order.Queued)
|
if (!order.Queued)
|
||||||
@@ -157,10 +182,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Play deploy sound and animation.</summary>
|
/// <summary>Play deploy sound and animation.</summary>
|
||||||
void Deploy()
|
void Deploy() { Deploy(false); }
|
||||||
|
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.
|
||||||
if (deployState != DeployState.Undeployed)
|
if (!init && deployState != DeployState.Undeployed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsOnValidTerrain())
|
if (!IsOnValidTerrain())
|
||||||
@@ -170,6 +196,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Game.Sound.Play(info.DeploySound, self.CenterPosition);
|
Game.Sound.Play(info.DeploySound, self.CenterPosition);
|
||||||
|
|
||||||
// Revoke upgrades that are used while undeployed.
|
// Revoke upgrades that are used while undeployed.
|
||||||
|
if (!init)
|
||||||
OnDeployStarted();
|
OnDeployStarted();
|
||||||
|
|
||||||
// If there is no animation to play just grant the upgrades that are used while deployed.
|
// If there is no animation to play just grant the upgrades that are used while deployed.
|
||||||
@@ -181,15 +208,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Play undeploy sound and animation and after that revoke the upgrades.</summary>
|
/// <summary>Play undeploy sound and animation and after that revoke the upgrades.</summary>
|
||||||
void Undeploy()
|
void Undeploy() { Undeploy(false); }
|
||||||
|
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.
|
||||||
if (deployState != DeployState.Deployed)
|
if (!init && deployState != DeployState.Deployed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.UndeploySound))
|
if (!string.IsNullOrEmpty(info.UndeploySound))
|
||||||
Game.Sound.Play(info.UndeploySound, self.CenterPosition);
|
Game.Sound.Play(info.UndeploySound, self.CenterPosition);
|
||||||
|
|
||||||
|
if (!init)
|
||||||
OnUndeployStarted();
|
OnUndeployStarted();
|
||||||
|
|
||||||
// If there is no animation to play just grant the upgrades that are used while undeployed.
|
// If there is no animation to play just grant the upgrades that are used while undeployed.
|
||||||
@@ -232,4 +261,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
deployState = DeployState.Undeployed;
|
deployState = DeployState.Undeployed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DeployStateInit : IActorInit<DeployState>
|
||||||
|
{
|
||||||
|
[FieldFromYamlKey]
|
||||||
|
readonly DeployState value = DeployState.Deployed;
|
||||||
|
public DeployStateInit() { }
|
||||||
|
public DeployStateInit(DeployState init) { value = init; }
|
||||||
|
public DeployState Value(World world) { return value; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,3 @@
|
|||||||
GADPSA:
|
|
||||||
Inherits: ^DeployedVehicle
|
|
||||||
Valued:
|
|
||||||
Cost: 950
|
|
||||||
Tooltip:
|
|
||||||
Name: Deployed Sensor Array
|
|
||||||
Health:
|
|
||||||
HP: 600
|
|
||||||
Armor:
|
|
||||||
Type: Wood
|
|
||||||
RevealsShroud:
|
|
||||||
Range: 8c0
|
|
||||||
Transforms:
|
|
||||||
IntoActor: lpst
|
|
||||||
Facing: 159
|
|
||||||
TransformSounds: place2.aud
|
|
||||||
NoTransformSounds:
|
|
||||||
Voice: Move
|
|
||||||
-AutoTarget:
|
|
||||||
-DrawLineToTarget:
|
|
||||||
-AttackTurreted:
|
|
||||||
-RenderRangeCircle:
|
|
||||||
RenderDetectionCircle:
|
|
||||||
DetectCloaked:
|
|
||||||
Range: 6c0
|
|
||||||
|
|
||||||
NAPULS:
|
NAPULS:
|
||||||
Inherits: ^Defense
|
Inherits: ^Defense
|
||||||
Valued:
|
Valued:
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ LPST:
|
|||||||
UpgradeTypes: undeployed
|
UpgradeTypes: undeployed
|
||||||
UpgradeMinEnabledLevel: 1
|
UpgradeMinEnabledLevel: 1
|
||||||
WithSpriteBody@deployed:
|
WithSpriteBody@deployed:
|
||||||
StartSequence: make
|
|
||||||
UpgradeTypes: undeployed
|
UpgradeTypes: undeployed
|
||||||
UpgradeMaxEnabledLevel: 0
|
UpgradeMaxEnabledLevel: 0
|
||||||
DisableOnUpgrade:
|
DisableOnUpgrade:
|
||||||
|
|||||||
@@ -573,19 +573,6 @@ gaicbm:
|
|||||||
Length: 30
|
Length: 30
|
||||||
ShadowStart: 30
|
ShadowStart: 30
|
||||||
|
|
||||||
gadpsa:
|
|
||||||
Defaults:
|
|
||||||
Offset: 0, -12
|
|
||||||
UseTilesetCode: true
|
|
||||||
idle:
|
|
||||||
ShadowStart: 3
|
|
||||||
damaged-idle:
|
|
||||||
Start: 1
|
|
||||||
ShadowStart: 4
|
|
||||||
make: gadpsamk
|
|
||||||
Length: 36
|
|
||||||
ShadowStart: 36
|
|
||||||
|
|
||||||
gaarty:
|
gaarty:
|
||||||
Defaults:
|
Defaults:
|
||||||
Offset: 0, -12
|
Offset: 0, -12
|
||||||
|
|||||||
Reference in New Issue
Block a user