Moved projectile inaccuracy calculations to Common.Util
Also moved the InaccuracyType enum there. This also quietly adds the RangeModifiers to the calculations for all projectiles, while they were only used on Bullet so far, which seemed very wrong.
This commit is contained in:
committed by
Matthias Mailänder
parent
134d47e48c
commit
76dfda164e
@@ -21,8 +21,6 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Projectiles
|
namespace OpenRA.Mods.Common.Projectiles
|
||||||
{
|
{
|
||||||
public enum InaccuracyType { Maximum, PerCellIncrement, Absolute }
|
|
||||||
|
|
||||||
public class AreaBeamInfo : IProjectileInfo
|
public class AreaBeamInfo : IProjectileInfo
|
||||||
{
|
{
|
||||||
[Desc("Projectile speed in WDist / tick, two values indicate a randomly picked velocity per beam.")]
|
[Desc("Projectile speed in WDist / tick, two values indicate a randomly picked velocity per beam.")]
|
||||||
@@ -132,23 +130,8 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
target = args.PassiveTarget;
|
target = args.PassiveTarget;
|
||||||
if (info.Inaccuracy.Length > 0)
|
if (info.Inaccuracy.Length > 0)
|
||||||
{
|
{
|
||||||
var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
|
var maxInaccuracyOffset = Util.GetProjectileInaccuracy(info.Inaccuracy.Length, info.InaccuracyType, args);
|
||||||
|
target += WVec.FromPDF(world.SharedRandom, 2) * maxInaccuracyOffset / 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
towardsTargetFacing = (target - headPos).Yaw;
|
towardsTargetFacing = (target - headPos).Yaw;
|
||||||
|
|||||||
@@ -149,24 +149,8 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
target = args.PassiveTarget;
|
target = args.PassiveTarget;
|
||||||
if (info.Inaccuracy.Length > 0)
|
if (info.Inaccuracy.Length > 0)
|
||||||
{
|
{
|
||||||
var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
|
var maxInaccuracyOffset = Util.GetProjectileInaccuracy(info.Inaccuracy.Length, info.InaccuracyType, args);
|
||||||
var range = Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers);
|
target += WVec.FromPDF(world.SharedRandom, 2) * maxInaccuracyOffset / 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.AirburstAltitude > WDist.Zero)
|
if (info.AirburstAltitude > WDist.Zero)
|
||||||
|
|||||||
@@ -55,23 +55,9 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
target = args.GuidedTarget;
|
target = args.GuidedTarget;
|
||||||
else if (info.Inaccuracy.Length > 0)
|
else if (info.Inaccuracy.Length > 0)
|
||||||
{
|
{
|
||||||
var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
|
var maxInaccuracyOffset = Util.GetProjectileInaccuracy(info.Inaccuracy.Length, info.InaccuracyType, args);
|
||||||
|
var inaccuracyOffset = WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxInaccuracyOffset / 1024;
|
||||||
var maxOffset = 0;
|
target = Target.FromPos(args.PassiveTarget + inaccuracyOffset);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
target = Target.FromPos(args.PassiveTarget);
|
target = Target.FromPos(args.PassiveTarget);
|
||||||
|
|||||||
@@ -132,23 +132,8 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
|
|
||||||
if (info.Inaccuracy.Length > 0)
|
if (info.Inaccuracy.Length > 0)
|
||||||
{
|
{
|
||||||
var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
|
var maxInaccuracyOffset = Util.GetProjectileInaccuracy(info.Inaccuracy.Length, info.InaccuracyType, args);
|
||||||
|
target += WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxInaccuracyOffset / 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.HitAnim))
|
if (!string.IsNullOrEmpty(info.HitAnim))
|
||||||
|
|||||||
@@ -238,23 +238,8 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
var inaccuracy = lockOn && info.LockOnInaccuracy.Length > -1 ? info.LockOnInaccuracy.Length : info.Inaccuracy.Length;
|
var inaccuracy = lockOn && info.LockOnInaccuracy.Length > -1 ? info.LockOnInaccuracy.Length : info.Inaccuracy.Length;
|
||||||
if (inaccuracy > 0)
|
if (inaccuracy > 0)
|
||||||
{
|
{
|
||||||
inaccuracy = Util.ApplyPercentageModifiers(inaccuracy, args.InaccuracyModifiers);
|
var maxInaccuracyOffset = Util.GetProjectileInaccuracy(info.Inaccuracy.Length, info.InaccuracyType, args);
|
||||||
|
offset = WVec.FromPDF(world.SharedRandom, 2) * maxInaccuracyOffset / 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DetermineLaunchSpeedAndAngle(world, out speed, out vFacing);
|
DetermineLaunchSpeedAndAngle(world, out speed, out vFacing);
|
||||||
|
|||||||
@@ -134,23 +134,8 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
|
|
||||||
if (info.Inaccuracy.Length > 0)
|
if (info.Inaccuracy.Length > 0)
|
||||||
{
|
{
|
||||||
var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
|
var maxInaccuracyOffset = Util.GetProjectileInaccuracy(info.Inaccuracy.Length, info.InaccuracyType, args);
|
||||||
|
target += WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxInaccuracyOffset / 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.HitAnim))
|
if (!string.IsNullOrEmpty(info.HitAnim))
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Graphics;
|
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
@@ -21,6 +21,8 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common
|
namespace OpenRA.Mods.Common
|
||||||
{
|
{
|
||||||
|
public enum InaccuracyType { Maximum, PerCellIncrement, Absolute }
|
||||||
|
|
||||||
public static class Util
|
public static class Util
|
||||||
{
|
{
|
||||||
public static int TickFacing(int facing, int desiredFacing, int rot)
|
public static int TickFacing(int facing, int desiredFacing, int rot)
|
||||||
@@ -251,5 +253,22 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
return t.Name;
|
return t.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int GetProjectileInaccuracy(int baseInaccuracy, InaccuracyType inaccuracyType, ProjectileArgs args)
|
||||||
|
{
|
||||||
|
var inaccuracy = ApplyPercentageModifiers(baseInaccuracy, args.InaccuracyModifiers);
|
||||||
|
switch (inaccuracyType)
|
||||||
|
{
|
||||||
|
case InaccuracyType.Maximum:
|
||||||
|
var weaponMaxRange = ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers);
|
||||||
|
return inaccuracy * (args.PassiveTarget - args.Source).Length / weaponMaxRange;
|
||||||
|
case InaccuracyType.PerCellIncrement:
|
||||||
|
return inaccuracy * (args.PassiveTarget - args.Source).Length / 1024;
|
||||||
|
case InaccuracyType.Absolute:
|
||||||
|
return inaccuracy;
|
||||||
|
default:
|
||||||
|
throw new InvalidEnumArgumentException("inaccuracyType", (int)inaccuracyType, typeof(InaccuracyType));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user