#68 Inaccurate weapons (1/2)

This commit is contained in:
Chris Forbes
2010-04-05 07:39:02 +12:00
parent aa9d07261c
commit 7dc765d120
2 changed files with 14 additions and 3 deletions

View File

@@ -57,9 +57,7 @@ namespace OpenRA.Effects
Info = info; Info = info;
Args = args; Args = args;
VisualDest = args.dest + new int2( VisualDest = args.dest + (10 * args.firedBy.World.CosmeticRandom.Gauss2D(1)).ToInt2();
args.firedBy.World.CosmeticRandom.Next(-10, 10),
args.firedBy.World.CosmeticRandom.Next(-10, 10));
if (Info.Image != null) if (Info.Image != null)
{ {

View File

@@ -217,5 +217,18 @@ namespace OpenRA
{ {
return w.WorldActor.Info.Traits.WithInterface<CountryInfo>(); return w.WorldActor.Info.Traits.WithInterface<CountryInfo>();
} }
public static float Gauss1D(this Thirdparty.Random r, int samples)
{
var xs = Graphics.Util.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1);
return xs.Sum() / samples;
}
// Returns a random offset in the range [-1..1,-1..1] with a separable
// Gauss distribution with 'samples' values taken for each axis
public static float2 Gauss2D(this Thirdparty.Random r, int samples)
{
return new float2(Gauss1D(r, samples), Gauss1D(r, samples));
}
} }
} }