From 3678e146cfa678e970b4fb918a4d237e8152bbf5 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Fri, 21 Aug 2015 16:50:59 +0300 Subject: [PATCH 1/7] Make WithVoxelBody upgradable --- OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs index 7cd11fa474..1d1db6b299 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBody.cs @@ -18,11 +18,11 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")] - public class WithVoxelBodyInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires + public class WithVoxelBodyInfo : UpgradableTraitInfo, IRenderActorPreviewVoxelsInfo, Requires { public readonly string Sequence = "idle"; - public object Create(ActorInitializer init) { return new WithVoxelBody(init.Self, this); } + public override object Create(ActorInitializer init) { return new WithVoxelBody(init.Self, this); } public IEnumerable RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p) { @@ -35,11 +35,12 @@ namespace OpenRA.Mods.Common.Traits } } - public class WithVoxelBody : IAutoSelectionSize + public class WithVoxelBody : UpgradableTrait, IAutoSelectionSize { readonly int2 size; public WithVoxelBody(Actor self, WithVoxelBodyInfo info) + : base(info) { var body = self.Trait(); var rv = self.Trait(); @@ -47,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits var voxel = VoxelProvider.GetVoxel(rv.Image, info.Sequence); rv.Add(new VoxelAnimation(voxel, () => WVec.Zero, () => new[] { body.QuantizeOrientation(self, self.Orientation) }, - () => false, () => 0)); + () => IsTraitDisabled, () => 0)); // Selection size var rvi = self.Info.Traits.Get(); From 7d59aaa00cbbc9c4f31270f3e30a87573e34872f Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Fri, 21 Aug 2015 16:45:18 +0300 Subject: [PATCH 2/7] Add a deploy animation to DeployToUpgrade Play a "deploy"/"undeploy" animation --- .../Traits/Upgrades/DeployToUpgrade.cs | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs index 3599c9883e..7c047661b9 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.Activities; using OpenRA.Mods.Common.Orders; using OpenRA.Traits; @@ -32,6 +33,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Cursor to display when unable to (un)deploy the actor.")] public readonly string DeployBlockedCursor = "deploy-blocked"; + [SequenceReference, Desc("Animation to play for deploying/undeploying.")] + public readonly string DeployAnimation = null; + public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); } } @@ -41,6 +45,7 @@ namespace OpenRA.Mods.Common.Traits readonly DeployToUpgradeInfo info; readonly UpgradeManager manager; readonly bool checkTerrainType; + readonly Lazy body; bool isUpgraded; @@ -50,6 +55,7 @@ namespace OpenRA.Mods.Common.Traits this.info = info; manager = self.Trait(); checkTerrainType = info.AllowedTerrainTypes.Length > 0; + body = Exts.Lazy(self.TraitOrDefault); } public IEnumerable Orders @@ -75,11 +81,40 @@ namespace OpenRA.Mods.Common.Traits return; if (isUpgraded) - foreach (var up in info.Upgrades) - manager.RevokeUpgrade(self, up, this); + { + // Play undeploy animation and after that revoke the upgrades + self.QueueActivity(new CallFunc(() => + { + if (string.IsNullOrEmpty(info.DeployAnimation)) + { + RevokeUpgrades(); + return; + } + + if (body.Value != null) + body.Value.PlayCustomAnimationBackwards(self, info.DeployAnimation, RevokeUpgrades); + else + RevokeUpgrades(); + })); + } else - foreach (var up in info.Upgrades) - manager.GrantUpgrade(self, up, this); + { + self.CancelActivity(); + + // Grant the upgrade + self.QueueActivity(new CallFunc(GrantUpgrades)); + + // Play deploy animation + self.QueueActivity(new CallFunc(() => + { + if (string.IsNullOrEmpty(info.DeployAnimation)) + return; + + if (body.Value != null) + body.Value.PlayCustomAnimation(self, info.DeployAnimation, + () => body.Value.PlayCustomAnimationRepeating(self, "idle")); + })); + } isUpgraded = !isUpgraded; } @@ -98,5 +133,17 @@ namespace OpenRA.Mods.Common.Traits return info.AllowedTerrainTypes.Contains(terrainType); } + + void GrantUpgrades() + { + foreach (var up in info.Upgrades) + manager.GrantUpgrade(self, up, this); + } + + void RevokeUpgrades() + { + foreach (var up in info.Upgrades) + manager.RevokeUpgrade(self, up, this); + } } } \ No newline at end of file From 21f9547fed70a6327aad8f0ae38389cde3122e40 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Fri, 21 Aug 2015 16:46:05 +0300 Subject: [PATCH 3/7] Add facing to DeployToUpgrade Make the actor turn to a desired facing before starting to deploy (and before granting the upgrade). --- OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs index 7c047661b9..7aa3c1e42e 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Activities; +using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Orders; using OpenRA.Traits; @@ -36,6 +37,9 @@ namespace OpenRA.Mods.Common.Traits [SequenceReference, Desc("Animation to play for deploying/undeploying.")] public readonly string DeployAnimation = null; + [Desc("Facing that the actor must face before deploying. Set to -1 to deploy regardless of facing.")] + public readonly int Facing = -1; + public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); } } @@ -45,6 +49,7 @@ namespace OpenRA.Mods.Common.Traits readonly DeployToUpgradeInfo info; readonly UpgradeManager manager; readonly bool checkTerrainType; + readonly bool canTurn; readonly Lazy body; bool isUpgraded; @@ -55,6 +60,7 @@ namespace OpenRA.Mods.Common.Traits this.info = info; manager = self.Trait(); checkTerrainType = info.AllowedTerrainTypes.Length > 0; + canTurn = self.Info.Traits.WithInterface().Any(); body = Exts.Lazy(self.TraitOrDefault); } @@ -101,6 +107,10 @@ namespace OpenRA.Mods.Common.Traits { self.CancelActivity(); + // Turn + if (info.Facing != -1 && canTurn) + self.QueueActivity(new Turn(self, info.Facing)); + // Grant the upgrade self.QueueActivity(new CallFunc(GrantUpgrades)); From 7668e0a30cfd4ae3176ed394eb11ebd032f9b781 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Fri, 21 Aug 2015 18:39:09 +0300 Subject: [PATCH 4/7] Add deploy and undeploy sounds to DeployToUpgrade --- .../Traits/Upgrades/DeployToUpgrade.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs index 7aa3c1e42e..b5d0821d2e 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs @@ -40,6 +40,12 @@ namespace OpenRA.Mods.Common.Traits [Desc("Facing that the actor must face before deploying. Set to -1 to deploy regardless of facing.")] public readonly int Facing = -1; + [Desc("Sound to play when deploying.")] + public readonly string DeploySound = null; + + [Desc("Sound to play when undeploying.")] + public readonly string UndeploySound = null; + public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); } } @@ -91,6 +97,9 @@ namespace OpenRA.Mods.Common.Traits // Play undeploy animation and after that revoke the upgrades self.QueueActivity(new CallFunc(() => { + if (!string.IsNullOrEmpty(info.UndeploySound)) + Sound.Play(info.UndeploySound, self.CenterPosition); + if (string.IsNullOrEmpty(info.DeployAnimation)) { RevokeUpgrades(); @@ -114,9 +123,12 @@ namespace OpenRA.Mods.Common.Traits // Grant the upgrade self.QueueActivity(new CallFunc(GrantUpgrades)); - // Play deploy animation + // Play deploy sound and animation self.QueueActivity(new CallFunc(() => { + if (!string.IsNullOrEmpty(info.DeploySound)) + Sound.Play(info.DeploySound, self.CenterPosition); + if (string.IsNullOrEmpty(info.DeployAnimation)) return; From cdedfe6931b8f4e82849e9bbf62ca4c0257f3f7f Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Fri, 21 Aug 2015 16:46:47 +0300 Subject: [PATCH 5/7] Don't get stuck in deployed mode because of an impossible move order --- OpenRA.Mods.Common/Activities/Move/Move.cs | 3 +++ OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index ebaf66aeb9..e5a704d33a 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -142,6 +142,9 @@ namespace OpenRA.Mods.Common.Activities public override Activity Tick(Actor self) { + if (IsCanceled) + return NextActivity; + if (moveDisablers.Any(d => d.MoveDisabled(self))) return this; diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs index b5d0821d2e..f9b7f23fee 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits if (isUpgraded) { // Play undeploy animation and after that revoke the upgrades - self.QueueActivity(new CallFunc(() => + self.QueueActivity(false, new CallFunc(() => { if (!string.IsNullOrEmpty(info.UndeploySound)) Sound.Play(info.UndeploySound, self.CenterPosition); From 899ea7e16dd5f2045f159232827c6179a84a0496 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Fri, 21 Aug 2015 17:12:14 +0300 Subject: [PATCH 6/7] Add a description to DisableUpgrade --- OpenRA.Mods.Common/Traits/Upgrades/DisableUpgrade.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DisableUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/DisableUpgrade.cs index 2e07036146..b02beb2978 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/DisableUpgrade.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/DisableUpgrade.cs @@ -8,13 +8,11 @@ */ #endregion -using System; -using System.Collections.Generic; -using OpenRA.GameRules; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { + [Desc("Disable the actor when this trait is enabled by an upgrade.")] public class DisableUpgradeInfo : UpgradableTraitInfo { public override object Create(ActorInitializer init) { return new DisableUpgrade(this); } @@ -25,7 +23,6 @@ namespace OpenRA.Mods.Common.Traits public DisableUpgrade(DisableUpgradeInfo info) : base(info) { } - // Disable the actor when this trait is enabled. public bool Disabled { get { return !IsTraitDisabled; } } public bool MoveDisabled(Actor self) { return !IsTraitDisabled; } } From 606a8c16398571a6eebe99acffc3ba7a2eda573f Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Tue, 1 Sep 2015 20:18:59 +0300 Subject: [PATCH 7/7] Convert the Mobile Sensor Array to use DeployToUpgrade Stop using Transforms. --- mods/ts/rules/shared-vehicles.yaml | 43 +++++++++++++++++++++--------- mods/ts/sequences/vehicles.yaml | 14 ++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/mods/ts/rules/shared-vehicles.yaml b/mods/ts/rules/shared-vehicles.yaml index 215df07cfc..4da98920c8 100644 --- a/mods/ts/rules/shared-vehicles.yaml +++ b/mods/ts/rules/shared-vehicles.yaml @@ -100,35 +100,54 @@ HARV: LPST: Inherits: ^VoxelVehicle + -AppearsOnRadar: + -GainsExperience: + Buildable: + Queue: Vehicle + BuildPaletteOrder: 100 + Prerequisites: ~factory, radar Valued: Cost: 950 Tooltip: Name: Mobile Sensor Array Description: Can detect cloaked and subterranean\nunits when deployed.\n Unarmed - Buildable: - Queue: Vehicle - BuildPaletteOrder: 100 - Prerequisites: ~factory, radar Health: HP: 600 Armor: - Type: Light + Type: Wood Mobile: Speed: 85 ROT: 5 RevealsShroud: - Range: 10c0 - Transforms: - IntoActor: gadpsa - Facing: 159 - TransformSounds: - NoTransformSounds: - Voice: Move + Range: 7c0 RenderSprites: Image: lpst.gdi FactionImages: gdi: lpst.gdi nod: lpst.nod + DeployToUpgrade: + Upgrades: deployed + DeployAnimation: make + Facing: 160 + AllowedTerrainTypes: Clear, Road, DirtRoad, Rough + DeploySound: place2.aud + UndeploySound: clicky1.aud + WithVoxelBody: + Image: lpst + UpgradeTypes: deployed + UpgradeMaxEnabledLevel: 0 + WithSpriteBody@deployed: + StartSequence: make + UpgradeTypes: deployed + UpgradeMinEnabledLevel: 1 + DisableUpgrade: + UpgradeTypes: deployed + UpgradeMinEnabledLevel: 1 + DetectCloaked: + UpgradeTypes: deployed + UpgradeMinEnabledLevel: 1 + Range: 18 + RenderDetectionCircle: GGHUNT: Inherits: ^Vehicle diff --git a/mods/ts/sequences/vehicles.yaml b/mods/ts/sequences/vehicles.yaml index f54745f0e2..671610484a 100644 --- a/mods/ts/sequences/vehicles.yaml +++ b/mods/ts/sequences/vehicles.yaml @@ -26,9 +26,23 @@ hvr: lpst.gdi: icon: sidec01.mix:lpsticon + idle: gadpsa + Offset: 0, -12 + ShadowStart: 3 + make: gadpsamk + Offset: 0, -12 + Length: 36 + ShadowStart: 36 lpst.nod: icon: sidec02.mix:lpsticon + idle: gadpsa + Offset: 0, -12 + ShadowStart: 3 + make: gadpsamk + Offset: 0, -12 + Length: 36 + ShadowStart: 36 repair: icon: rboticon