diff --git a/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs b/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs index 74aaa0789a..1d9fd0df56 100644 --- a/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs +++ b/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Cnc.Traits public TransformsNearResources(Actor self, TransformsNearResourcesInfo info) { resourceLayer = self.World.WorldActor.Trait(); - delay = Common.Util.RandomDelay(self.World, info.Delay); + delay = Common.Util.RandomInRange(self.World.SharedRandom, info.Delay); this.info = info; } diff --git a/OpenRA.Mods.Common/Traits/KillsSelf.cs b/OpenRA.Mods.Common/Traits/KillsSelf.cs index 6242219aaf..6beb822340 100644 --- a/OpenRA.Mods.Common/Traits/KillsSelf.cs +++ b/OpenRA.Mods.Common/Traits/KillsSelf.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits public KillsSelf(Actor self, KillsSelfInfo info) : base(info) { - lifetime = Util.RandomDelay(self.World, info.Delay); + lifetime = Util.RandomInRange(self.World.SharedRandom, info.Delay); } protected override void TraitEnabled(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs index 2d2e0b527f..e3dc0158c9 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits.Render : base(info) { wsb = self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); - ticks = Util.RandomDelay(self.World, info.Interval); + ticks = Util.RandomInRange(self.World.SharedRandom, info.Interval); } void ITick.Tick(Actor self) @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits.Render if (--ticks <= 0) { wsb.PlayCustomAnimation(self, Info.Sequences.Random(Game.CosmeticRandom)); - ticks = Util.RandomDelay(self.World, Info.Interval); + ticks = Util.RandomInRange(self.World.SharedRandom, Info.Interval); } } diff --git a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs index 7bfa2a3d86..435d5440b5 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits.Sound public AmbientSound(Actor self, AmbientSoundInfo info) : base(info) { - delay = Util.RandomDelay(self.World, info.Delay); + delay = Util.RandomInRange(self.World.SharedRandom, info.Delay); loop = Info.Interval.Length == 0 || (Info.Interval.Length == 1 && Info.Interval[0] == 0); } @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits.Sound { StartSound(self); if (!loop) - delay = Util.RandomDelay(self.World, Info.Interval); + delay = Util.RandomInRange(self.World.SharedRandom, Info.Interval); } } @@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits.Sound currentSounds.Clear(); } - protected override void TraitEnabled(Actor self) { delay = Util.RandomDelay(self.World, Info.Delay); } + protected override void TraitEnabled(Actor self) { delay = Util.RandomInRange(self.World.SharedRandom, Info.Delay); } protected override void TraitDisabled(Actor self) { StopSound(); } void INotifyRemovedFromWorld.RemovedFromWorld(Actor self) { StopSound(); } diff --git a/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs b/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs index 84d02db504..3b363b11bb 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits if (spawnPoint == null) return; - spawnCountdown = Util.RandomDelay(self.World, info.SpawnInterval); + spawnCountdown = Util.RandomInRange(self.World.SharedRandom, info.SpawnInterval); do { diff --git a/OpenRA.Mods.Common/Util.cs b/OpenRA.Mods.Common/Util.cs index 2eb43ae95e..fc23261dc2 100644 --- a/OpenRA.Mods.Common/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -198,7 +198,7 @@ namespace OpenRA.Mods.Common } } - public static int RandomDelay(World world, int[] range) + public static int RandomInRange(MersenneTwister random, int[] range) { if (range.Length == 0) return 0; @@ -206,7 +206,7 @@ namespace OpenRA.Mods.Common if (range.Length == 1) return range[0]; - return world.SharedRandom.Next(range[0], range[1]); + return random.Next(range[0], range[1]); } public static string FriendlyTypeName(Type t)