From 134d47e48c9da73113c40f01b567d1bbb26a4e37 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Sat, 2 May 2020 00:31:27 +0300 Subject: [PATCH] Added InaccuracyType.Absolute to projectiles --- OpenRA.Mods.Common/Projectiles/AreaBeam.cs | 22 +++++++++++++------- OpenRA.Mods.Common/Projectiles/Bullet.cs | 20 ++++++++++++------ OpenRA.Mods.Common/Projectiles/InstantHit.cs | 20 ++++++++++++------ OpenRA.Mods.Common/Projectiles/LaserZap.cs | 20 ++++++++++++------ OpenRA.Mods.Common/Projectiles/Missile.cs | 20 +++++++++++++----- OpenRA.Mods.Common/Projectiles/Railgun.cs | 20 ++++++++++++------ 6 files changed, 86 insertions(+), 36 deletions(-) diff --git a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs index 681365c298..fcf5a13d2f 100644 --- a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs +++ b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs @@ -21,7 +21,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Projectiles { - public enum InaccuracyType { Maximum, PerCellIncrement } + public enum InaccuracyType { Maximum, PerCellIncrement, Absolute } public class AreaBeamInfo : IProjectileInfo { @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Projectiles public readonly WDist Inaccuracy = WDist.Zero; - [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' and 'PerCellIncrement'.")] + [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' - scale from 0 to max with range, 'PerCellIncrement' - scale from 0 with range and 'Absolute' - use set value regardless of range.")] public readonly InaccuracyType InaccuracyType = InaccuracyType.Maximum; [Desc("Can this projectile be blocked when hitting actors with an IBlocksProjectiles trait.")] @@ -134,11 +134,19 @@ namespace OpenRA.Mods.Common.Projectiles { var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); - int maxOffset; - if (info.InaccuracyType == InaccuracyType.Maximum) - maxOffset = inaccuracy * (target - headPos).Length / args.Weapon.Range.Length; - else - maxOffset = inaccuracy * (target - headPos).Length / 1024; + var maxOffset = 0; + switch (info.InaccuracyType) + { + case InaccuracyType.Maximum: + maxOffset = inaccuracy * (target - headPos).Length / args.Weapon.Range.Length; + break; + case InaccuracyType.PerCellIncrement: + maxOffset = inaccuracy * (target - headPos).Length / 1024; + break; + case InaccuracyType.Absolute: + maxOffset = inaccuracy; + break; + } target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; } diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index 9c8924abba..a66766f2c7 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Projectiles public readonly WDist Inaccuracy = WDist.Zero; - [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' and 'PerCellIncrement'.")] + [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' - scale from 0 to max with range, 'PerCellIncrement' - scale from 0 with range and 'Absolute' - use set value regardless of range.")] public readonly InaccuracyType InaccuracyType = InaccuracyType.Maximum; [Desc("Image to display.")] @@ -152,11 +152,19 @@ namespace OpenRA.Mods.Common.Projectiles var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); var range = Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers); - int maxOffset; - if (info.InaccuracyType == InaccuracyType.Maximum) - maxOffset = inaccuracy * (target - pos).Length / range; - else - maxOffset = inaccuracy * (target - pos).Length / 1024; + var maxOffset = 0; + switch (info.InaccuracyType) + { + case InaccuracyType.Maximum: + maxOffset = inaccuracy * (target - pos).Length / range; + break; + case InaccuracyType.PerCellIncrement: + maxOffset = inaccuracy * (target - pos).Length / 1024; + break; + case InaccuracyType.Absolute: + maxOffset = inaccuracy; + break; + } target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; } diff --git a/OpenRA.Mods.Common/Projectiles/InstantHit.cs b/OpenRA.Mods.Common/Projectiles/InstantHit.cs index 488d156f82..58fa83b938 100644 --- a/OpenRA.Mods.Common/Projectiles/InstantHit.cs +++ b/OpenRA.Mods.Common/Projectiles/InstantHit.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Projectiles { public readonly WDist Inaccuracy = WDist.Zero; - [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' and 'PerCellIncrement'.")] + [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' - scale from 0 to max with range, 'PerCellIncrement' - scale from 0 with range and 'Absolute' - use set value regardless of range.")] public readonly InaccuracyType InaccuracyType = InaccuracyType.Maximum; [Desc("Projectile can be blocked.")] @@ -57,11 +57,19 @@ namespace OpenRA.Mods.Common.Projectiles { var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); - int maxOffset; - if (info.InaccuracyType == InaccuracyType.Maximum) - maxOffset = inaccuracy * (args.PassiveTarget - args.Source).Length / args.Weapon.Range.Length; - else - maxOffset = inaccuracy * (args.PassiveTarget - args.Source).Length / 1024; + var maxOffset = 0; + switch (info.InaccuracyType) + { + case InaccuracyType.Maximum: + maxOffset = inaccuracy * (args.PassiveTarget - args.Source).Length / args.Weapon.Range.Length; + break; + case InaccuracyType.PerCellIncrement: + maxOffset = inaccuracy * (args.PassiveTarget - args.Source).Length / 1024; + break; + case InaccuracyType.Absolute: + maxOffset = inaccuracy; + break; + } target = Target.FromPos(args.PassiveTarget + WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxOffset / 1024); } diff --git a/OpenRA.Mods.Common/Projectiles/LaserZap.cs b/OpenRA.Mods.Common/Projectiles/LaserZap.cs index 665df898e7..c0f830cfbe 100644 --- a/OpenRA.Mods.Common/Projectiles/LaserZap.cs +++ b/OpenRA.Mods.Common/Projectiles/LaserZap.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Projectiles public readonly WDist Inaccuracy = WDist.Zero; - [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' and 'PerCellIncrement'.")] + [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' - scale from 0 to max with range, 'PerCellIncrement' - scale from 0 with range and 'Absolute' - use set value regardless of range.")] public readonly InaccuracyType InaccuracyType = InaccuracyType.Maximum; [Desc("Beam can be blocked.")] @@ -134,11 +134,19 @@ namespace OpenRA.Mods.Common.Projectiles { var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); - int maxOffset; - if (info.InaccuracyType == InaccuracyType.Maximum) - maxOffset = inaccuracy * (target - source).Length / args.Weapon.Range.Length; - else - maxOffset = inaccuracy * (target - source).Length / 1024; + var maxOffset = 0; + switch (info.InaccuracyType) + { + case InaccuracyType.Maximum: + maxOffset = inaccuracy * (target - source).Length / args.Weapon.Range.Length; + break; + case InaccuracyType.PerCellIncrement: + maxOffset = inaccuracy * (target - source).Length / 1024; + break; + case InaccuracyType.Absolute: + maxOffset = inaccuracy; + break; + } target += WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxOffset / 1024; } diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index 1a2e2472e4..891af33e3f 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -73,8 +73,8 @@ namespace OpenRA.Mods.Common.Projectiles public readonly WDist Inaccuracy = WDist.Zero; - [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' and 'PerCellIncrement'.")] - public readonly InaccuracyType InaccuracyType = InaccuracyType.Maximum; + [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' - scale from 0 to max with range, 'PerCellIncrement' - scale from 0 with range and 'Absolute' - use set value regardless of range.")] + public readonly InaccuracyType InaccuracyType = InaccuracyType.Absolute; [Desc("Inaccuracy override when sucessfully locked onto target. Defaults to Inaccuracy if negative.")] public readonly WDist LockOnInaccuracy = new WDist(-1); @@ -240,9 +240,19 @@ namespace OpenRA.Mods.Common.Projectiles { inaccuracy = Util.ApplyPercentageModifiers(inaccuracy, args.InaccuracyModifiers); - var maxOffset = inaccuracy; - if (info.InaccuracyType == InaccuracyType.PerCellIncrement) - maxOffset = inaccuracy * (targetPosition - pos).Length / 1024; + var maxOffset = 0; + switch (info.InaccuracyType) + { + case InaccuracyType.Maximum: + maxOffset = inaccuracy * (targetPosition - pos).Length / args.Weapon.Range.Length; + break; + case InaccuracyType.PerCellIncrement: + maxOffset = inaccuracy * (targetPosition - pos).Length / 1024; + break; + case InaccuracyType.Absolute: + maxOffset = inaccuracy; + break; + } offset = WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; } diff --git a/OpenRA.Mods.Common/Projectiles/Railgun.cs b/OpenRA.Mods.Common/Projectiles/Railgun.cs index 7e2d4718a2..e0fd17be6a 100644 --- a/OpenRA.Mods.Common/Projectiles/Railgun.cs +++ b/OpenRA.Mods.Common/Projectiles/Railgun.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Projectiles public readonly WDist Inaccuracy = WDist.Zero; - [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' and 'PerCellIncrement'.")] + [Desc("Controls the way inaccuracy is calculated. Possible values are 'Maximum' - scale from 0 to max with range, 'PerCellIncrement' - scale from 0 with range and 'Absolute' - use set value regardless of range.")] public readonly InaccuracyType InaccuracyType = InaccuracyType.Maximum; [Desc("Can this projectile be blocked when hitting actors with an IBlocksProjectiles trait.")] @@ -136,11 +136,19 @@ namespace OpenRA.Mods.Common.Projectiles { var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); - int maxOffset; - if (info.InaccuracyType == InaccuracyType.Maximum) - maxOffset = inaccuracy * (target - source).Length / args.Weapon.Range.Length; - else - maxOffset = inaccuracy * (target - source).Length / 1024; + var maxOffset = 0; + switch (info.InaccuracyType) + { + case InaccuracyType.Maximum: + maxOffset = inaccuracy * (target - source).Length / args.Weapon.Range.Length; + break; + case InaccuracyType.PerCellIncrement: + maxOffset = inaccuracy * (target - source).Length / 1024; + break; + case InaccuracyType.Absolute: + maxOffset = inaccuracy; + break; + } target += WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxOffset / 1024; }