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

View File

@@ -13,7 +13,7 @@ Rockets:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 298 Speed: 298
RangeLimit: 20 RangeLimit: 7c204
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 35 Damage: 35
@@ -46,7 +46,7 @@ BikeRockets:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 213 Speed: 213
RangeLimit: 30 RangeLimit: 7c204
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 30 Damage: 30
@@ -80,7 +80,7 @@ OrcaAGMissiles:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 256 Speed: 256
RangeLimit: 30 RangeLimit: 6c0
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 25 Damage: 25
@@ -114,7 +114,7 @@ OrcaAAMissiles:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 298 Speed: 298
RangeLimit: 30 RangeLimit: 6c0
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 25 Damage: 25
@@ -145,7 +145,7 @@ MammothMissiles:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 341 Speed: 341
RangeLimit: 35 RangeLimit: 6c0
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 298 Spread: 298
Damage: 45 Damage: 45
@@ -218,7 +218,7 @@ MammothMissiles:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 213 Speed: 213
RangeLimit: 40 RangeLimit: 8c409
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 60 Damage: 60
@@ -250,7 +250,7 @@ BoatMissile:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 170 Speed: 170
RangeLimit: 60 RangeLimit: 9c614
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 256 Spread: 256
Damage: 60 Damage: 60
@@ -285,7 +285,7 @@ TowerMissle:
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Speed: 298 Speed: 298
RangeLimit: 40 RangeLimit: 8c409
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 683 Spread: 683
Damage: 25 Damage: 25
@@ -313,7 +313,7 @@ SAMMissile:
Image: MISSILE Image: MISSILE
HorizontalRateOfTurn: 20 HorizontalRateOfTurn: 20
Speed: 426 Speed: 426
RangeLimit: 35 RangeLimit: 9c614
TrailImage: smokey TrailImage: smokey
ContrailLength: 8 ContrailLength: 8
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
@@ -374,7 +374,7 @@ Patriot:
ContrailLength: 8 ContrailLength: 8
HorizontalRateOfTurn: 20 HorizontalRateOfTurn: 20
Speed: 300 Speed: 300
RangeLimit: 30 RangeLimit: 10c819
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 682 Spread: 682
ValidTargets: Air ValidTargets: Air

View File

@@ -10,7 +10,7 @@ Bazooka:
TrailImage: bazooka_trail2 TrailImage: bazooka_trail2
TrailPalette: effect75alpha TrailPalette: effect75alpha
TrailInterval: 1 TrailInterval: 1
RangeLimit: 35 RangeLimit: 3c614
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 192 Spread: 192
Falloff: 100, 50, 25, 0 Falloff: 100, 50, 25, 0
@@ -43,7 +43,7 @@ Rocket:
TrailPalette: effect75alpha TrailPalette: effect75alpha
TrailInterval: 1 TrailInterval: 1
Speed: 343 Speed: 343
RangeLimit: 35 RangeLimit: 4c204
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 160 Spread: 160
Falloff: 100, 50, 25, 0 Falloff: 100, 50, 25, 0
@@ -76,7 +76,7 @@ TowerMissile:
Blockable: false Blockable: false
Shadow: true Shadow: true
HorizontalRateOfTurn: 1 HorizontalRateOfTurn: 1
RangeLimit: 50 RangeLimit: 6c614
Inaccuracy: 384 Inaccuracy: 384
Image: MISSILE2 Image: MISSILE2
TrailImage: large_trail TrailImage: large_trail
@@ -112,7 +112,7 @@ mtank_pri:
ValidTargets: Ground, Air ValidTargets: Ground, Air
Projectile: Missile Projectile: Missile
Speed: 281 Speed: 281
RangeLimit: 50 RangeLimit: 7c204
HorizontalRateOfTurn: 3 HorizontalRateOfTurn: 3
Blockable: false Blockable: false
Shadow: yes Shadow: yes
@@ -147,7 +147,7 @@ DeviatorMissile:
Report: MISSLE1.WAV Report: MISSLE1.WAV
Projectile: Missile Projectile: Missile
Speed: 281 Speed: 281
RangeLimit: 40 RangeLimit: 6c0
HorizontalRateOfTurn: 3 HorizontalRateOfTurn: 3
Blockable: false Blockable: false
Shadow: yes Shadow: yes

View File

@@ -28,7 +28,7 @@ MammothTusk:
ContrailLength: 150 ContrailLength: 150
Inaccuracy: 0c853 Inaccuracy: 0c853
ROT: 10 ROT: 10
RangeLimit: 80 RangeLimit: 12c0
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 640 Spread: 640
ValidTargets: Ground, Air ValidTargets: Ground, Air

View File

@@ -15,7 +15,7 @@ Maverick:
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 5 HorizontalRateOfTurn: 5
CruiseAltitude: 2c0 CruiseAltitude: 2c0
RangeLimit: 60 RangeLimit: 10c819
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 70 Damage: 70
@@ -52,7 +52,7 @@ Dragon:
Inaccuracy: 128 Inaccuracy: 128
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 5 HorizontalRateOfTurn: 5
RangeLimit: 35 RangeLimit: 6c0
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 50 Damage: 50
@@ -90,7 +90,7 @@ HellfireAG:
Inaccuracy: 128 Inaccuracy: 128
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 10 HorizontalRateOfTurn: 10
RangeLimit: 20 RangeLimit: 4c819
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 60 Damage: 60
@@ -128,7 +128,7 @@ HellfireAA:
Inaccuracy: 128 Inaccuracy: 128
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 10 HorizontalRateOfTurn: 10
RangeLimit: 20 RangeLimit: 4c819
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 40 Damage: 40
@@ -164,7 +164,7 @@ MammothTusk:
Inaccuracy: 128 Inaccuracy: 128
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 15 HorizontalRateOfTurn: 15
RangeLimit: 40 RangeLimit: 9c614
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 256 Spread: 256
Damage: 50 Damage: 50
@@ -201,7 +201,7 @@ Nike:
ContrailLength: 10 ContrailLength: 10
Image: MISSILE Image: MISSILE
HorizontalRateOfTurn: 25 HorizontalRateOfTurn: 25
RangeLimit: 50 RangeLimit: 9c0
Speed: 341 Speed: 341
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
@@ -229,7 +229,7 @@ RedEye:
ContrailLength: 10 ContrailLength: 10
Image: MISSILE Image: MISSILE
HorizontalRateOfTurn: 20 HorizontalRateOfTurn: 20
RangeLimit: 30 RangeLimit: 9c0
Speed: 298 Speed: 298
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
@@ -293,7 +293,7 @@ Stinger:
ContrailLength: 10 ContrailLength: 10
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 20 HorizontalRateOfTurn: 20
RangeLimit: 65 RangeLimit: 10c819
Speed: 170 Speed: 170
CloseEnough: 149 CloseEnough: 149
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
@@ -334,7 +334,7 @@ StingerAA:
ContrailLength: 10 ContrailLength: 10
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 20 HorizontalRateOfTurn: 20
RangeLimit: 50 RangeLimit: 10c819
Speed: 255 Speed: 255
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
@@ -374,7 +374,7 @@ TorpTube:
Speed: 85 Speed: 85
TrailImage: bubbles TrailImage: bubbles
HorizontalRateOfTurn: 1 HorizontalRateOfTurn: 1
RangeLimit: 160 RangeLimit: 10c819
BoundToTerrainType: Water BoundToTerrainType: Water
Palette: shadow Palette: shadow
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
@@ -451,7 +451,7 @@ APTusk:
Inaccuracy: 128 Inaccuracy: 128
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 10 HorizontalRateOfTurn: 10
RangeLimit: 22 RangeLimit: 7c204
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 128 Spread: 128
Damage: 30 Damage: 30

View File

@@ -12,7 +12,7 @@ Bazooka:
Image: DRAGON Image: DRAGON
TrailImage: small_smoke_trail TrailImage: small_smoke_trail
HorizontalRateOfTurn: 8 HorizontalRateOfTurn: 8
RangeLimit: 50 RangeLimit: 7c204
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384
@@ -58,7 +58,7 @@ HoverMissile:
Image: DRAGON Image: DRAGON
TrailImage: small_smoke_trail TrailImage: small_smoke_trail
HorizontalRateOfTurn: 8 HorizontalRateOfTurn: 8
RangeLimit: 35 RangeLimit: 9c614
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384
@@ -103,7 +103,7 @@ MammothTusk:
TrailImage: small_smoke_trail TrailImage: small_smoke_trail
HorizontalRateOfTurn: 10 HorizontalRateOfTurn: 10
MaximumLaunchSpeed: 213 MaximumLaunchSpeed: 213
RangeLimit: 50 RangeLimit: 7c204
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384
@@ -144,7 +144,7 @@ BikeMissile:
TrailImage: small_smoke_trail TrailImage: small_smoke_trail
HorizontalRateOfTurn: 8 HorizontalRateOfTurn: 8
MaximumLaunchSpeed: 213 MaximumLaunchSpeed: 213
RangeLimit: 50 RangeLimit: 6c0
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384
@@ -186,7 +186,7 @@ Dragon:
Image: DRAGON Image: DRAGON
TrailImage: small_smoke_trail TrailImage: small_smoke_trail
HorizontalRateOfTurn: 8 HorizontalRateOfTurn: 8
RangeLimit: 50 RangeLimit: 7c204
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384
@@ -232,7 +232,7 @@ Hellfire:
Image: DRAGON Image: DRAGON
TrailImage: small_smoke_trail TrailImage: small_smoke_trail
HorizontalRateOfTurn: 8 HorizontalRateOfTurn: 8
RangeLimit: 35 RangeLimit: 7c204
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384
@@ -277,7 +277,7 @@ RedEye2:
Image: DRAGON Image: DRAGON
TrailImage: small_smoke_trail TrailImage: small_smoke_trail
HorizontalRateOfTurn: 5 HorizontalRateOfTurn: 5
RangeLimit: 100 RangeLimit: 18c0
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384

View File

@@ -11,7 +11,7 @@ MultiCluster:
Inaccuracy: 128 Inaccuracy: 128
Image: DRAGON Image: DRAGON
HorizontalRateOfTurn: 8 HorizontalRateOfTurn: 8
RangeLimit: 35 RangeLimit: 7c204
Palette: ra Palette: ra
MinimumLaunchSpeed: 75 MinimumLaunchSpeed: 75
Speed: 384 Speed: 384