diff --git a/OpenRA.Game/Effects/Bullet.cs b/OpenRA.Game/Effects/Bullet.cs index a7850babd9..771328a9c7 100755 --- a/OpenRA.Game/Effects/Bullet.cs +++ b/OpenRA.Game/Effects/Bullet.cs @@ -29,7 +29,7 @@ namespace OpenRA.Effects { public readonly int Speed = 1; public readonly string Trail = null; - public readonly bool Inaccurate = false; + public readonly float Inaccuracy = 0; // expressed as pixels/cell^2 public readonly string Image = null; public readonly bool High = false; public readonly bool Arcing = false; @@ -57,7 +57,13 @@ namespace OpenRA.Effects Info = info; Args = args; - VisualDest = args.dest + (10 * args.firedBy.World.CosmeticRandom.Gauss2D(1)).ToInt2(); + if (info.Inaccuracy > 0) + { + var factor = (Args.dest - Args.src).LengthSquared / (Game.CellSize * Game.CellSize); + Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2(); + } + + VisualDest = Args.dest + (10 * args.firedBy.World.CosmeticRandom.Gauss2D(1)).ToInt2(); if (Info.Image != null) { diff --git a/OpenRA.Game/Effects/Missile.cs b/OpenRA.Game/Effects/Missile.cs index 37f35313ad..3c1266376b 100755 --- a/OpenRA.Game/Effects/Missile.cs +++ b/OpenRA.Game/Effects/Missile.cs @@ -34,7 +34,7 @@ namespace OpenRA.Effects public readonly bool Shadow = true; public readonly bool Proximity = false; public readonly string Trail = null; - public readonly bool Inaccurate = false; + public readonly float Inaccuracy = 0; // pixels/cell^2, not yet implemented for missiles public readonly string Image = null; public readonly int ROT = 5; public readonly int RangeLimit = 0; @@ -48,6 +48,7 @@ namespace OpenRA.Effects readonly MissileInfo Info; readonly ProjectileArgs Args; + int2 offset; float2 Pos; readonly Animation anim; int Facing; @@ -63,6 +64,12 @@ namespace OpenRA.Effects Altitude = Args.srcAltitude; Facing = Args.facing; + if (info.Inaccuracy > 0) + { + var factor = (Args.dest - Args.src).LengthSquared / (Game.CellSize * Game.CellSize); + offset = (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2(); + } + if (Info.Image != null) { anim = new Animation(Info.Image, () => Facing); @@ -77,17 +84,19 @@ namespace OpenRA.Effects { t += 40; + var targetPosition = Args.target.CenterLocation + offset; + var targetUnit = Args.target.traits.GetOrDefault(); var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0; Altitude += Math.Sign(targetAltitude - Altitude); Traits.Util.TickFacing(ref Facing, - Traits.Util.GetFacing(Args.target.CenterLocation - Pos, Facing), + Traits.Util.GetFacing(targetPosition - Pos, Facing), Info.ROT); anim.Tick(); - var dist = Args.target.CenterLocation - Pos; + var dist = targetPosition - Pos; if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead) Explode(world); diff --git a/mods/aftermath/weapons.yaml b/mods/aftermath/weapons.yaml index dbac3ffc66..7f29a7da00 100644 --- a/mods/aftermath/weapons.yaml +++ b/mods/aftermath/weapons.yaml @@ -73,7 +73,7 @@ APTusk: Shadow: false Proximity: true Trail: smokey - Inaccurate: true + Inaccuracy: 3 Image: DRAGON ROT: 5 RangeLimit: 20 diff --git a/mods/cnc/weapons.yaml b/mods/cnc/weapons.yaml index 6082027a35..608a511a7c 100644 --- a/mods/cnc/weapons.yaml +++ b/mods/cnc/weapons.yaml @@ -93,7 +93,7 @@ Rockets: High: yes Shadow: no Proximity: yes - Inaccurate: yes + Inaccuracy: 3 Image: DRAGON ROT: 5 Trail: smokey @@ -161,7 +161,7 @@ Grenade: Speed: 5 High: yes Arcing: yes - Inaccurate: yes + Inaccuracy: 5 Image: BOMB Warhead: Spread: 6 @@ -251,7 +251,7 @@ MissilePack: High: yes Shadow: no Proximity: yes - Inaccurate: yes + Inaccuracy: 3 Image: DRAGON ROT: 5 Trail: smokey @@ -276,7 +276,7 @@ MissilePack: High: yes Shadow: no Proximity: yes - Inaccurate: yes + Inaccuracy: 5 Image: DRAGON ROT: 5 Trail: smokey @@ -299,7 +299,7 @@ Ballistic: Speed: 12 High: yes Arcing: yes - Inaccurate: yes + Inaccuracy: 5 Image: 120MM Warhead: Damage: 150 @@ -333,7 +333,7 @@ BoatMissile: High: yes Shadow: no Proximity: yes - Inaccurate: yes + Inaccuracy: 5 Image: DRAGON ROT: 5 Trail: smokey @@ -357,7 +357,7 @@ Tomahawk: High: yes Shadow: no Proximity: yes - Inaccurate: yes + Inaccuracy: 3 Image: DRAGON ROT: 5 Trail: smokey @@ -436,7 +436,7 @@ HonestJohn: High: yes Shadow: no Proximity: yes - Inaccurate: yes + Inaccuracy: 3 Image: MISSILE Speed: 15 Warhead: diff --git a/mods/ra/weapons.yaml b/mods/ra/weapons.yaml index 361431781b..181a57b836 100644 --- a/mods/ra/weapons.yaml +++ b/mods/ra/weapons.yaml @@ -49,7 +49,7 @@ Maverick: Shadow: false Proximity: true Trail: smokey - Inaccurate: true + Inaccuracy: 3 Image: DRAGON ROT: 5 RangeLimit: 20 @@ -148,7 +148,7 @@ Dragon: Shadow: false Proximity: true Trail: smokey - Inaccurate: true + Inaccuracy: 3 Image: DRAGON ROT: 5 RangeLimit: 20 @@ -174,7 +174,7 @@ Hellfire: Shadow: false Proximity: true Trail: smokey - Inaccurate: true + Inaccuracy: 3 Image: DRAGON ROT: 5 RangeLimit: 20 @@ -195,7 +195,7 @@ Grenade: Speed: 5 High: true Arcing: true - Inaccurate: true + Inaccuracy: 3 Image: BOMB Warhead: Spread: 6 @@ -306,7 +306,7 @@ MammothTusk: Shadow: false Proximity: true Trail: smokey - Inaccurate: true + Inaccuracy: 3 Image: DRAGON ROT: 5 RangeLimit: 20 @@ -328,7 +328,7 @@ MammothTusk: Speed: 12 High: true Arcing: true - Inaccurate:true + Inaccuracy: 5 Image: 120MM Warhead: Spread: 6 @@ -461,7 +461,7 @@ RedEye: Speed: 12 High: true Arcing: true - Inaccurate:true + Inaccuracy: 3 Image: 120MM Warhead: Spread: 6 @@ -544,7 +544,7 @@ DepthCharge: Image: BOMB Arcing: true High: true - Inaccurate: true + Inaccuracy: 3 Warhead: Spread: 3 Wall: true @@ -613,7 +613,7 @@ SCUD: Shadow: false Proximity: true Trail: smokey - Inaccurate: true + Inaccuracy: 5 Image: V2 Warhead: Spread: 6