diff --git a/OpenRa.Game/Effects/Bullet.cs b/OpenRa.Game/Effects/Bullet.cs index 2998e5d037..bb78a6d95d 100755 --- a/OpenRa.Game/Effects/Bullet.cs +++ b/OpenRa.Game/Effects/Bullet.cs @@ -38,8 +38,8 @@ namespace OpenRa.Effects SrcAltitude = srcAltitude; DestAltitude = destAltitude; VisualDest = Dest + new int2( - Game.CosmeticRandom.Next(-10, 10), - Game.CosmeticRandom.Next(-10, 10)); + firedBy.World.CosmeticRandom.Next(-10, 10), + firedBy.World.CosmeticRandom.Next(-10, 10)); Weapon = weapon; Projectile = Rules.ProjectileInfo[Weapon.Projectile]; Warhead = Rules.WarheadInfo[Weapon.Warhead]; diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 506563d6d8..a4fcbd4736 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -177,9 +177,6 @@ namespace OpenRa PerfHistory.items["batches"].Tick(); } - public static Random SharedRandom = new Random(0); /* for things that require sync */ - public static Random CosmeticRandom = new Random(); /* for things that are just fluff */ - public static void SyncLobbyInfo(string data) { var session = new Session(); @@ -256,7 +253,7 @@ namespace OpenRa throw new InvalidOperationException("No free spawnpoint."); var n = taken.Count == 0 - ? Game.SharedRandom.Next(available.Count) + ? world.SharedRandom.Next(available.Count) : available // pick the most distant spawnpoint from everyone else .Select((k,i) => Pair.New(k,i)) .OrderByDescending(a => taken.Sum(t => (t - a.First).LengthSquared)) diff --git a/OpenRa.Game/GameRules/VoiceInfo.cs b/OpenRa.Game/GameRules/VoiceInfo.cs index 4526dd09db..34d45d559c 100644 --- a/OpenRa.Game/GameRules/VoiceInfo.cs +++ b/OpenRa.Game/GameRules/VoiceInfo.cs @@ -45,7 +45,7 @@ namespace OpenRa.GameRules if (liveclips.Count == 0) return null; /* avoid crashing if there's no clips at all */ - var i = Game.CosmeticRandom.Next(liveclips.Count); + var i = Game.world.CosmeticRandom.Next(liveclips.Count); var s = liveclips[i]; liveclips.RemoveAt(i); return s; diff --git a/OpenRa.Game/Traits/Crate.cs b/OpenRa.Game/Traits/Crate.cs index e1ae0505d3..4676d7b944 100644 --- a/OpenRa.Game/Traits/Crate.cs +++ b/OpenRa.Game/Traits/Crate.cs @@ -46,7 +46,7 @@ namespace OpenRa.Traits { var shares = self.traits.WithInterface().Select(a => Pair.New(a, a.SelectionShares)); var totalShares = shares.Sum(a => a.Second); - var n = Game.SharedRandom.Next(totalShares); + var n = self.World.SharedRandom.Next(totalShares); self.World.AddFrameEndTask(w => w.Remove(self)); foreach (var s in shares) diff --git a/OpenRa.Game/Traits/SeedsOre.cs b/OpenRa.Game/Traits/SeedsOre.cs index 139b5c8881..21e1ec07d0 100644 --- a/OpenRa.Game/Traits/SeedsOre.cs +++ b/OpenRa.Game/Traits/SeedsOre.cs @@ -21,7 +21,7 @@ namespace OpenRa.Traits for (var j = -1; j < 2; j++) for (var i = -1; i < 2; i++) - if (Game.SharedRandom.NextDouble() < info.Chance) + if (self.World.SharedRandom.NextDouble() < info.Chance) if (self.World.OreCanSpreadInto(self.Location.X + i, self.Location.Y + j)) self.World.Map.AddOre(self.Location.X + i, self.Location.Y + j); diff --git a/OpenRa.Game/Traits/World/CrateSpawner.cs b/OpenRa.Game/Traits/World/CrateSpawner.cs index 88a82c06ea..ef814aaab9 100644 --- a/OpenRa.Game/Traits/World/CrateSpawner.cs +++ b/OpenRa.Game/Traits/World/CrateSpawner.cs @@ -41,12 +41,12 @@ namespace OpenRa.Traits void SpawnCrate(Actor self, CrateSpawnerInfo info) { - var inWater = Game.SharedRandom.NextDouble() < info.WaterChance; + var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; var umt = inWater ? UnitMovementType.Float : UnitMovementType.Wheel; for (; ; ) { - var p = new int2(Game.SharedRandom.Next(0,127), Game.SharedRandom.Next(0,127)); + var p = new int2(self.World.SharedRandom.Next(0, 127), self.World.SharedRandom.Next(0, 127)); if (self.World.IsCellBuildable(p, umt)) { self.World.AddFrameEndTask( diff --git a/OpenRa.Game/Traits/World/OreGrowth.cs b/OpenRa.Game/Traits/World/OreGrowth.cs index f79b21decc..0cd01b52c5 100644 --- a/OpenRa.Game/Traits/World/OreGrowth.cs +++ b/OpenRa.Game/Traits/World/OreGrowth.cs @@ -28,11 +28,11 @@ namespace OpenRa.Traits if (info.Spreads) Ore.SpreadOre(self.World, - Game.SharedRandom, + self.World.SharedRandom, info.Chance); if (info.Grows) - Ore.GrowOre(self.World, Game.SharedRandom); + Ore.GrowOre(self.World, self.World.SharedRandom); self.World.Minimap.InvalidateOre(); remainingTicks = (int)(info.Interval * 60 * 25); diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 9762d32dbf..8b2b65939a 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -16,6 +16,9 @@ namespace OpenRa List effects = new List(); List> frameEndActions = new List>(); + public Random SharedRandom = new Random(0); // synced + public Random CosmeticRandom = new Random(); // not synced + public readonly Dictionary players = new Dictionary(); int localPlayerIndex; diff --git a/OpenRa.Game/WorldUtils.cs b/OpenRa.Game/WorldUtils.cs index 6709a59fe0..57ae789d51 100755 --- a/OpenRa.Game/WorldUtils.cs +++ b/OpenRa.Game/WorldUtils.cs @@ -177,13 +177,13 @@ namespace OpenRa public static int2 ChooseRandomEdgeCell(this World w) { - var isX = Game.SharedRandom.Next(2) == 0; - var edge = Game.SharedRandom.Next(2) == 0; + var isX = w.SharedRandom.Next(2) == 0; + var edge = w.SharedRandom.Next(2) == 0; return new int2( - isX ? Game.SharedRandom.Next(w.Map.XOffset, w.Map.XOffset + w.Map.Width) + isX ? w.SharedRandom.Next(w.Map.XOffset, w.Map.XOffset + w.Map.Width) : (edge ? w.Map.XOffset : w.Map.XOffset + w.Map.Width), - !isX ? Game.SharedRandom.Next(w.Map.YOffset, w.Map.YOffset + w.Map.Height) + !isX ? w.SharedRandom.Next(w.Map.YOffset, w.Map.YOffset + w.Map.Height) : (edge ? w.Map.YOffset : w.Map.YOffset + w.Map.Height)); }