Merge pull request #11205 from reaperrr/rangelimit-wdist

Refactored Missile.RangeLimit to be a WDist value
This commit is contained in:
Matthias Mailänder
2016-05-07 15:10:49 +02:00
10 changed files with 107 additions and 39 deletions

View File

@@ -82,8 +82,8 @@ namespace OpenRA.Mods.Common.Effects
[Desc("Gravity applied while in free fall.")]
public readonly int Gravity = 10;
[Desc("Run out of fuel after being activated this many ticks. Zero for unlimited fuel.")]
public readonly int RangeLimit = 0;
[Desc("Run out of fuel after covering this distance. Zero for defaulting to weapon range. Negative for unlimited fuel.")]
public readonly WDist RangeLimit = WDist.Zero;
[Desc("Explode when running out of fuel.")]
public readonly bool ExplodeWhenEmpty = true;
@@ -181,6 +181,8 @@ namespace OpenRA.Mods.Common.Effects
WVec velocity;
int speed;
int loopRadius;
WDist distanceCovered;
WDist rangeLimit;
int renderFacing;
[Sync] int hFacing;
@@ -198,6 +200,7 @@ namespace OpenRA.Mods.Common.Effects
hFacing = args.Facing;
gravity = new WVec(0, 0, -info.Gravity);
targetPosition = args.PassiveTarget;
rangeLimit = info.RangeLimit != WDist.Zero ? info.RangeLimit : args.Weapon.Range;
var world = args.SourceActor.World;
@@ -766,7 +769,7 @@ namespace OpenRA.Mods.Common.Effects
}
// Switch from homing mode to freefall mode
if (info.RangeLimit != 0 && ticks == info.RangeLimit + 1)
if (rangeLimit >= WDist.Zero && distanceCovered > rangeLimit)
{
state = States.Freefall;
velocity = new WVec(0, -speed, 0)
@@ -824,11 +827,12 @@ namespace OpenRA.Mods.Common.Effects
if (info.ContrailLength > 0)
contrail.Update(pos);
distanceCovered += new WDist(speed);
var cell = world.Map.CellContaining(pos);
var height = world.Map.DistanceAboveTerrain(pos);
shouldExplode |= height.Length < 0 // Hit the ground
|| relTarDist < info.CloseEnough.Length // Within range
|| (info.ExplodeWhenEmpty && info.RangeLimit != 0 && ticks > info.RangeLimit) // Ran out of fuel
|| (info.ExplodeWhenEmpty && rangeLimit >= WDist.Zero && distanceCovered > rangeLimit) // Ran out of fuel
|| !world.Map.Contains(cell) // This also avoids an IndexOutOfRangeException in GetTerrainInfo below.
|| (!string.IsNullOrEmpty(info.BoundToTerrainType) && world.Map.GetTerrainInfo(cell).Type != info.BoundToTerrainType) // Hit incompatible terrain
|| (height.Length < info.AirburstAltitude.Length && relTarHorDist < info.CloseEnough.Length); // Airburst

View File

@@ -0,0 +1,35 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 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;
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Lint
{
class CheckRangeLimit : ILintRulesPass
{
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
{
foreach (var weaponInfo in rules.Weapons)
{
var range = weaponInfo.Value.Range;
var missile = weaponInfo.Value.Projectile as MissileInfo;
if (missile != null && missile.RangeLimit > WDist.Zero && missile.RangeLimit < range)
emitError("Weapon `{0}`: projectile RangeLimit lower than weapon range!"
.F(weaponInfo.Key));
}
}
}
}

View File

@@ -189,6 +189,7 @@
<Compile Include="Lint\CheckSyncAnnotations.cs" />
<Compile Include="Lint\CheckTraitPrerequisites.cs" />
<Compile Include="Lint\CheckDeathTypes.cs" />
<Compile Include="Lint\CheckRangeLimit.cs" />
<Compile Include="Lint\CheckVoiceReferences.cs" />
<Compile Include="Lint\CheckUpgrades.cs" />
<Compile Include="Lint\CheckTargetHealthRadius.cs" />

View File

@@ -826,6 +826,34 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
// Refactor Missile RangeLimit from ticks to WDist
if (engineVersion < 20160501)
{
var weapRange = node.Value.Nodes.FirstOrDefault(n => n.Key == "Range");
var projectile = node.Value.Nodes.FirstOrDefault(n => n.Key == "Projectile");
if (projectile != null && weapRange != null && projectile.Value.Value == "Missile")
{
var oldWDist = FieldLoader.GetValue<WDist>("Range", weapRange.Value.Value);
var rangeLimitNode = projectile.Value.Nodes.FirstOrDefault(x => x.Key == "RangeLimit");
// RangeLimit is now a WDist value, so for the conversion, we take weapon range and add 20% on top.
// Overly complicated calculations using Range, Speed and the old RangeLimit value would be rather pointless,
// because currently most mods have somewhat arbitrary, usually too high and in a few cases too low RangeLimits anyway.
var newValue = oldWDist.Length * 120 / 100;
var newCells = newValue / 1024;
var newCellPart = newValue % 1024;
if (rangeLimitNode != null)
rangeLimitNode.Value.Value = newCells.ToString() + "c" + newCellPart.ToString();
else
{
// Since the old default was 'unlimited', we're using weapon range * 1.2 for missiles not defining a custom RangeLimit as well
projectile.Value.Nodes.Add(new MiniYamlNode("RangeLimit", newCells.ToString() + "c" + newCellPart.ToString()));
}
}
}
UpgradeWeaponRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}