From ac44367440036f8d63f408590a199dccc5ab43fe Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 22 Oct 2019 13:07:00 +0200 Subject: [PATCH] Refactor Spin to MaximumSpinSpeed Additionally, add descriptions to other FallsToEarth properties. --- .../Activities/Air/FallToEarth.cs | 14 +++-- OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs | 9 ++- .../UpdateRules/Rules/RenameSpins.cs | 60 +++++++++++++++++++ mods/cnc/rules/defaults.yaml | 1 - mods/d2k/rules/defaults.yaml | 2 +- mods/ra/rules/defaults.yaml | 2 +- mods/ts/rules/defaults.yaml | 2 +- mods/ts/rules/husks.yaml | 8 ++- 8 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/RenameSpins.cs diff --git a/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs b/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs index 2ab716a05b..717bd9a13f 100644 --- a/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs +++ b/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Common.Traits; @@ -20,15 +21,16 @@ namespace OpenRA.Mods.Common.Activities { readonly Aircraft aircraft; readonly FallsToEarthInfo info; - int acceleration = 0; - int spin = 0; + + int acceleration; + int spin; public FallToEarth(Actor self, FallsToEarthInfo info) { this.info = info; IsInterruptible = false; aircraft = self.Trait(); - if (info.Spins) + if (info.MaximumSpinSpeed != 0) acceleration = self.World.SharedRandom.Next(2) * 2 - 1; } @@ -47,9 +49,11 @@ namespace OpenRA.Mods.Common.Activities return true; } - if (info.Spins) + if (info.MaximumSpinSpeed != 0) { - spin += acceleration; + if (info.MaximumSpinSpeed < 0 || Math.Abs(spin) < info.MaximumSpinSpeed) + spin += acceleration; // TODO: Possibly unhardcode this + aircraft.Facing = (aircraft.Facing + spin) % 256; } diff --git a/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs b/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs index a420093ae7..2492b0302c 100644 --- a/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs +++ b/OpenRA.Mods.Common/Traits/Air/FallsToEarth.cs @@ -19,10 +19,17 @@ namespace OpenRA.Mods.Common.Traits public class FallsToEarthInfo : ITraitInfo, IRulesetLoaded, Requires { [WeaponReference] + [Desc("Explosion weapon that triggers when hitting ground.")] public readonly string Explosion = "UnitExplode"; - public readonly bool Spins = true; + [Desc("Limit the maximum spin (in facing units per tick) that can be achieved while crashing.", + "0 disables spinning. Negative values imply no limit.")] + public readonly int MaximumSpinSpeed = -1; + + [Desc("Does the aircraft (husk) move forward at aircraft speed?")] public readonly bool Moves = false; + + [Desc("Velocity (per tick) at which aircraft falls to ground.")] public readonly WDist Velocity = new WDist(43); public WeaponInfo ExplosionWeapon { get; private set; } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/RenameSpins.cs b/OpenRA.Mods.Common/UpdateRules/Rules/RenameSpins.cs new file mode 100644 index 0000000000..ff790cc978 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/RenameSpins.cs @@ -0,0 +1,60 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class RenameSpins : UpdateRule + { + public override string Name { get { return "FallsToEarth.Spins has been refactored to MaximumSpinSpeed."; } } + public override string Description + { + get + { + return "The FallsToEarth.Spins property has been refactored to MaximumSpinSpeed."; + } + } + + readonly List locations = new List(); + + public override IEnumerable AfterUpdate(ModData modData) + { + if (locations.Any()) + yield return "The Spins property has been refactored to MaximumSpinSpeed.\n" + + "MaximumSpinSpeed defaults to 'unlimited', while disabling is done by setting it to 0.\n" + + "You may want to set a custom MaximumSpinSpeed limiting value in the following places:\n" + + UpdateUtils.FormatMessageList(locations); + + locations.Clear(); + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + foreach (var fallsToEarth in actorNode.ChildrenMatching("FallsToEarth")) + { + var spinsNode = fallsToEarth.LastChildMatching("Spins"); + if (spinsNode != null) + { + var spins = spinsNode.NodeValue(); + if (!spins) + fallsToEarth.AddNode("MaximumSpinSpeed", "0"); + + fallsToEarth.RemoveNode(spinsNode); + locations.Add("{0} ({1})".F(actorNode.Key, actorNode.Location.Filename)); + } + } + + yield break; + } + } +} diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml index 29d12e583c..08c21c6680 100644 --- a/mods/cnc/rules/defaults.yaml +++ b/mods/cnc/rules/defaults.yaml @@ -1087,7 +1087,6 @@ VTOL: true CanSlide: True FallsToEarth: - Spins: True Moves: False Explosion: HeliCrash Tooltip: diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index e6dc218625..19b4df5135 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -262,7 +262,7 @@ GenericName: Unit WithShadow: FallsToEarth: - Spins: False + MaximumSpinSpeed: 0 Moves: True Explosion: UnitExplodeLarge -MapEditorData: diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index 89496e1e55..edde743a5d 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -1030,10 +1030,10 @@ GenericName: Destroyed Plane Aircraft: FallsToEarth: - Spins: False Moves: True Velocity: 86 Explosion: UnitExplodePlane + MaximumSpinSpeed: 0 -MapEditorData: RevealOnDeath: Duration: 60 diff --git a/mods/ts/rules/defaults.yaml b/mods/ts/rules/defaults.yaml index a8616dcaa7..95278d3ebe 100644 --- a/mods/ts/rules/defaults.yaml +++ b/mods/ts/rules/defaults.yaml @@ -945,9 +945,9 @@ Tooltip: GenericName: Destroyed Aircraft FallsToEarth: - Spins: true Moves: true Velocity: 112 + MaximumSpinSpeed: 10 HitShape: ^Visceroid: diff --git a/mods/ts/rules/husks.yaml b/mods/ts/rules/husks.yaml index 9d2955d281..8a2a1c8ccc 100644 --- a/mods/ts/rules/husks.yaml +++ b/mods/ts/rules/husks.yaml @@ -30,8 +30,10 @@ ORCAB.Husk: Tooltip: Name: Orca Bomber Aircraft: - TurnSpeed: 5 + TurnSpeed: 3 Speed: 96 + FallsToEarth: + MaximumSpinSpeed: 6 RenderSprites: Image: orcab RenderVoxels: @@ -78,8 +80,10 @@ SCRIN.Husk: Tooltip: Name: Banshee Fighter Aircraft: - TurnSpeed: 5 + TurnSpeed: 3 Speed: 168 + FallsToEarth: + MaximumSpinSpeed: 6 RenderSprites: Image: scrin RenderVoxels: