#68 Inaccurate weapons (2/2)

This commit is contained in:
Chris Forbes
2010-04-05 07:49:27 +12:00
parent 7dc765d120
commit 2f982c7eea
5 changed files with 38 additions and 23 deletions

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Effects
{ {
public readonly int Speed = 1; public readonly int Speed = 1;
public readonly string Trail = null; 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 string Image = null;
public readonly bool High = false; public readonly bool High = false;
public readonly bool Arcing = false; public readonly bool Arcing = false;
@@ -57,7 +57,13 @@ namespace OpenRA.Effects
Info = info; Info = info;
Args = args; 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) if (Info.Image != null)
{ {

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Effects
public readonly bool Shadow = true; public readonly bool Shadow = true;
public readonly bool Proximity = false; public readonly bool Proximity = false;
public readonly string Trail = null; 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 string Image = null;
public readonly int ROT = 5; public readonly int ROT = 5;
public readonly int RangeLimit = 0; public readonly int RangeLimit = 0;
@@ -48,6 +48,7 @@ namespace OpenRA.Effects
readonly MissileInfo Info; readonly MissileInfo Info;
readonly ProjectileArgs Args; readonly ProjectileArgs Args;
int2 offset;
float2 Pos; float2 Pos;
readonly Animation anim; readonly Animation anim;
int Facing; int Facing;
@@ -63,6 +64,12 @@ namespace OpenRA.Effects
Altitude = Args.srcAltitude; Altitude = Args.srcAltitude;
Facing = Args.facing; 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) if (Info.Image != null)
{ {
anim = new Animation(Info.Image, () => Facing); anim = new Animation(Info.Image, () => Facing);
@@ -77,17 +84,19 @@ namespace OpenRA.Effects
{ {
t += 40; t += 40;
var targetPosition = Args.target.CenterLocation + offset;
var targetUnit = Args.target.traits.GetOrDefault<Unit>(); var targetUnit = Args.target.traits.GetOrDefault<Unit>();
var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0; var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0;
Altitude += Math.Sign(targetAltitude - Altitude); Altitude += Math.Sign(targetAltitude - Altitude);
Traits.Util.TickFacing(ref Facing, Traits.Util.TickFacing(ref Facing,
Traits.Util.GetFacing(Args.target.CenterLocation - Pos, Facing), Traits.Util.GetFacing(targetPosition - Pos, Facing),
Info.ROT); Info.ROT);
anim.Tick(); anim.Tick();
var dist = Args.target.CenterLocation - Pos; var dist = targetPosition - Pos;
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead) if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead)
Explode(world); Explode(world);

View File

@@ -73,7 +73,7 @@ APTusk:
Shadow: false Shadow: false
Proximity: true Proximity: true
Trail: smokey Trail: smokey
Inaccurate: true Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
RangeLimit: 20 RangeLimit: 20

View File

@@ -93,7 +93,7 @@ Rockets:
High: yes High: yes
Shadow: no Shadow: no
Proximity: yes Proximity: yes
Inaccurate: yes Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
Trail: smokey Trail: smokey
@@ -161,7 +161,7 @@ Grenade:
Speed: 5 Speed: 5
High: yes High: yes
Arcing: yes Arcing: yes
Inaccurate: yes Inaccuracy: 5
Image: BOMB Image: BOMB
Warhead: Warhead:
Spread: 6 Spread: 6
@@ -251,7 +251,7 @@ MissilePack:
High: yes High: yes
Shadow: no Shadow: no
Proximity: yes Proximity: yes
Inaccurate: yes Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
Trail: smokey Trail: smokey
@@ -276,7 +276,7 @@ MissilePack:
High: yes High: yes
Shadow: no Shadow: no
Proximity: yes Proximity: yes
Inaccurate: yes Inaccuracy: 5
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
Trail: smokey Trail: smokey
@@ -299,7 +299,7 @@ Ballistic:
Speed: 12 Speed: 12
High: yes High: yes
Arcing: yes Arcing: yes
Inaccurate: yes Inaccuracy: 5
Image: 120MM Image: 120MM
Warhead: Warhead:
Damage: 150 Damage: 150
@@ -333,7 +333,7 @@ BoatMissile:
High: yes High: yes
Shadow: no Shadow: no
Proximity: yes Proximity: yes
Inaccurate: yes Inaccuracy: 5
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
Trail: smokey Trail: smokey
@@ -357,7 +357,7 @@ Tomahawk:
High: yes High: yes
Shadow: no Shadow: no
Proximity: yes Proximity: yes
Inaccurate: yes Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
Trail: smokey Trail: smokey
@@ -436,7 +436,7 @@ HonestJohn:
High: yes High: yes
Shadow: no Shadow: no
Proximity: yes Proximity: yes
Inaccurate: yes Inaccuracy: 3
Image: MISSILE Image: MISSILE
Speed: 15 Speed: 15
Warhead: Warhead:

View File

@@ -49,7 +49,7 @@ Maverick:
Shadow: false Shadow: false
Proximity: true Proximity: true
Trail: smokey Trail: smokey
Inaccurate: true Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
RangeLimit: 20 RangeLimit: 20
@@ -148,7 +148,7 @@ Dragon:
Shadow: false Shadow: false
Proximity: true Proximity: true
Trail: smokey Trail: smokey
Inaccurate: true Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
RangeLimit: 20 RangeLimit: 20
@@ -174,7 +174,7 @@ Hellfire:
Shadow: false Shadow: false
Proximity: true Proximity: true
Trail: smokey Trail: smokey
Inaccurate: true Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
RangeLimit: 20 RangeLimit: 20
@@ -195,7 +195,7 @@ Grenade:
Speed: 5 Speed: 5
High: true High: true
Arcing: true Arcing: true
Inaccurate: true Inaccuracy: 3
Image: BOMB Image: BOMB
Warhead: Warhead:
Spread: 6 Spread: 6
@@ -306,7 +306,7 @@ MammothTusk:
Shadow: false Shadow: false
Proximity: true Proximity: true
Trail: smokey Trail: smokey
Inaccurate: true Inaccuracy: 3
Image: DRAGON Image: DRAGON
ROT: 5 ROT: 5
RangeLimit: 20 RangeLimit: 20
@@ -328,7 +328,7 @@ MammothTusk:
Speed: 12 Speed: 12
High: true High: true
Arcing: true Arcing: true
Inaccurate:true Inaccuracy: 5
Image: 120MM Image: 120MM
Warhead: Warhead:
Spread: 6 Spread: 6
@@ -461,7 +461,7 @@ RedEye:
Speed: 12 Speed: 12
High: true High: true
Arcing: true Arcing: true
Inaccurate:true Inaccuracy: 3
Image: 120MM Image: 120MM
Warhead: Warhead:
Spread: 6 Spread: 6
@@ -544,7 +544,7 @@ DepthCharge:
Image: BOMB Image: BOMB
Arcing: true Arcing: true
High: true High: true
Inaccurate: true Inaccuracy: 3
Warhead: Warhead:
Spread: 3 Spread: 3
Wall: true Wall: true
@@ -613,7 +613,7 @@ SCUD:
Shadow: false Shadow: false
Proximity: true Proximity: true
Trail: smokey Trail: smokey
Inaccurate: true Inaccuracy: 5
Image: V2 Image: V2
Warhead: Warhead:
Spread: 6 Spread: 6