Refactor Spin to MaximumSpinSpeed

Additionally, add descriptions to
other FallsToEarth properties.
This commit is contained in:
reaperrr
2019-10-22 13:07:00 +02:00
committed by Paul Chote
parent 20beb4abe1
commit ac44367440
8 changed files with 86 additions and 12 deletions

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System;
using System.Linq; using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
@@ -20,15 +21,16 @@ namespace OpenRA.Mods.Common.Activities
{ {
readonly Aircraft aircraft; readonly Aircraft aircraft;
readonly FallsToEarthInfo info; readonly FallsToEarthInfo info;
int acceleration = 0;
int spin = 0; int acceleration;
int spin;
public FallToEarth(Actor self, FallsToEarthInfo info) public FallToEarth(Actor self, FallsToEarthInfo info)
{ {
this.info = info; this.info = info;
IsInterruptible = false; IsInterruptible = false;
aircraft = self.Trait<Aircraft>(); aircraft = self.Trait<Aircraft>();
if (info.Spins) if (info.MaximumSpinSpeed != 0)
acceleration = self.World.SharedRandom.Next(2) * 2 - 1; acceleration = self.World.SharedRandom.Next(2) * 2 - 1;
} }
@@ -47,9 +49,11 @@ namespace OpenRA.Mods.Common.Activities
return true; 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; aircraft.Facing = (aircraft.Facing + spin) % 256;
} }

View File

@@ -19,10 +19,17 @@ namespace OpenRA.Mods.Common.Traits
public class FallsToEarthInfo : ITraitInfo, IRulesetLoaded, Requires<AircraftInfo> public class FallsToEarthInfo : ITraitInfo, IRulesetLoaded, Requires<AircraftInfo>
{ {
[WeaponReference] [WeaponReference]
[Desc("Explosion weapon that triggers when hitting ground.")]
public readonly string Explosion = "UnitExplode"; 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; public readonly bool Moves = false;
[Desc("Velocity (per tick) at which aircraft falls to ground.")]
public readonly WDist Velocity = new WDist(43); public readonly WDist Velocity = new WDist(43);
public WeaponInfo ExplosionWeapon { get; private set; } public WeaponInfo ExplosionWeapon { get; private set; }

View File

@@ -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<string> locations = new List<string>();
public override IEnumerable<string> 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<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
foreach (var fallsToEarth in actorNode.ChildrenMatching("FallsToEarth"))
{
var spinsNode = fallsToEarth.LastChildMatching("Spins");
if (spinsNode != null)
{
var spins = spinsNode.NodeValue<bool>();
if (!spins)
fallsToEarth.AddNode("MaximumSpinSpeed", "0");
fallsToEarth.RemoveNode(spinsNode);
locations.Add("{0} ({1})".F(actorNode.Key, actorNode.Location.Filename));
}
}
yield break;
}
}
}

View File

@@ -1087,7 +1087,6 @@
VTOL: true VTOL: true
CanSlide: True CanSlide: True
FallsToEarth: FallsToEarth:
Spins: True
Moves: False Moves: False
Explosion: HeliCrash Explosion: HeliCrash
Tooltip: Tooltip:

View File

@@ -262,7 +262,7 @@
GenericName: Unit GenericName: Unit
WithShadow: WithShadow:
FallsToEarth: FallsToEarth:
Spins: False MaximumSpinSpeed: 0
Moves: True Moves: True
Explosion: UnitExplodeLarge Explosion: UnitExplodeLarge
-MapEditorData: -MapEditorData:

View File

@@ -1030,10 +1030,10 @@
GenericName: Destroyed Plane GenericName: Destroyed Plane
Aircraft: Aircraft:
FallsToEarth: FallsToEarth:
Spins: False
Moves: True Moves: True
Velocity: 86 Velocity: 86
Explosion: UnitExplodePlane Explosion: UnitExplodePlane
MaximumSpinSpeed: 0
-MapEditorData: -MapEditorData:
RevealOnDeath: RevealOnDeath:
Duration: 60 Duration: 60

View File

@@ -945,9 +945,9 @@
Tooltip: Tooltip:
GenericName: Destroyed Aircraft GenericName: Destroyed Aircraft
FallsToEarth: FallsToEarth:
Spins: true
Moves: true Moves: true
Velocity: 112 Velocity: 112
MaximumSpinSpeed: 10
HitShape: HitShape:
^Visceroid: ^Visceroid:

View File

@@ -30,8 +30,10 @@ ORCAB.Husk:
Tooltip: Tooltip:
Name: Orca Bomber Name: Orca Bomber
Aircraft: Aircraft:
TurnSpeed: 5 TurnSpeed: 3
Speed: 96 Speed: 96
FallsToEarth:
MaximumSpinSpeed: 6
RenderSprites: RenderSprites:
Image: orcab Image: orcab
RenderVoxels: RenderVoxels:
@@ -78,8 +80,10 @@ SCRIN.Husk:
Tooltip: Tooltip:
Name: Banshee Fighter Name: Banshee Fighter
Aircraft: Aircraft:
TurnSpeed: 5 TurnSpeed: 3
Speed: 168 Speed: 168
FallsToEarth:
MaximumSpinSpeed: 6
RenderSprites: RenderSprites:
Image: scrin Image: scrin
RenderVoxels: RenderVoxels: