generate random numbers as floats
as they get converted from double before use anyway
This commit is contained in:
2
OpenRA.FileFormats/Thirdparty/Random.cs
vendored
2
OpenRA.FileFormats/Thirdparty/Random.cs
vendored
@@ -49,7 +49,7 @@ namespace OpenRA.Thirdparty
|
|||||||
|
|
||||||
public int Next(int low, int high) { return low + Next() % (high - low); }
|
public int Next(int low, int high) { return low + Next() % (high - low); }
|
||||||
public int Next(int high) { return Next() % high; }
|
public int Next(int high) { return Next() % high; }
|
||||||
public double NextDouble() { return Math.Abs(Next() / (double)0x7fffffff); }
|
public float NextFloat() { return Math.Abs(Next() / (float)0x7fffffff); }
|
||||||
|
|
||||||
void Generate()
|
void Generate()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static float Gauss1D(this Thirdparty.Random r, int samples)
|
public static float Gauss1D(this Thirdparty.Random r, int samples)
|
||||||
{
|
{
|
||||||
return Exts.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f)
|
return Exts.MakeArray(samples, _ => r.NextFloat() * 2 - 1f)
|
||||||
.Sum() / samples;
|
.Sum() / samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
var info = self.Info.Traits.Get<AttackBaseInfo>();
|
var info = self.Info.Traits.Get<AttackBaseInfo>();
|
||||||
nextScanTime = (int)(25 * (info.ScanTimeAverage +
|
nextScanTime = (int)(25 * (info.ScanTimeAverage +
|
||||||
(self.World.SharedRandom.NextDouble() * 2 - 1) * info.ScanTimeSpread));
|
(self.World.SharedRandom.NextFloat() * 2 - 1) * info.ScanTimeSpread));
|
||||||
|
|
||||||
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, (int)(Game.CellSize * range));
|
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, (int)(Game.CellSize * range));
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
void SpawnCrate(Actor self)
|
void SpawnCrate(Actor self)
|
||||||
{
|
{
|
||||||
var inWater = self.World.SharedRandom.NextDouble() < Info.WaterChance;
|
var inWater = self.World.SharedRandom.NextFloat() < Info.WaterChance;
|
||||||
var pp = ChooseDropCell(self, inWater, 100);
|
var pp = ChooseDropCell(self, inWater, 100);
|
||||||
if (pp == null) return;
|
if (pp == null) return;
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
|
|||||||
void SpawnCrate(Actor self, CrateSpawnerInfo info)
|
void SpawnCrate(Actor self, CrateSpawnerInfo info)
|
||||||
{
|
{
|
||||||
var threshold = 100;
|
var threshold = 100;
|
||||||
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
|
var inWater = self.World.SharedRandom.NextFloat() < info.WaterChance;
|
||||||
|
|
||||||
for (var n = 0; n < threshold; n++ )
|
for (var n = 0; n < threshold; n++ )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user