moved randoms onto World (reqd for side-by-side worlds, also fixes some obscure desyncs)
This commit is contained in:
@@ -38,8 +38,8 @@ namespace OpenRa.Effects
|
|||||||
SrcAltitude = srcAltitude;
|
SrcAltitude = srcAltitude;
|
||||||
DestAltitude = destAltitude;
|
DestAltitude = destAltitude;
|
||||||
VisualDest = Dest + new int2(
|
VisualDest = Dest + new int2(
|
||||||
Game.CosmeticRandom.Next(-10, 10),
|
firedBy.World.CosmeticRandom.Next(-10, 10),
|
||||||
Game.CosmeticRandom.Next(-10, 10));
|
firedBy.World.CosmeticRandom.Next(-10, 10));
|
||||||
Weapon = weapon;
|
Weapon = weapon;
|
||||||
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
|
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
|
||||||
Warhead = Rules.WarheadInfo[Weapon.Warhead];
|
Warhead = Rules.WarheadInfo[Weapon.Warhead];
|
||||||
|
|||||||
@@ -177,9 +177,6 @@ namespace OpenRa
|
|||||||
PerfHistory.items["batches"].Tick();
|
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)
|
public static void SyncLobbyInfo(string data)
|
||||||
{
|
{
|
||||||
var session = new Session();
|
var session = new Session();
|
||||||
@@ -256,7 +253,7 @@ namespace OpenRa
|
|||||||
throw new InvalidOperationException("No free spawnpoint.");
|
throw new InvalidOperationException("No free spawnpoint.");
|
||||||
|
|
||||||
var n = taken.Count == 0
|
var n = taken.Count == 0
|
||||||
? Game.SharedRandom.Next(available.Count)
|
? world.SharedRandom.Next(available.Count)
|
||||||
: available // pick the most distant spawnpoint from everyone else
|
: available // pick the most distant spawnpoint from everyone else
|
||||||
.Select((k,i) => Pair.New(k,i))
|
.Select((k,i) => Pair.New(k,i))
|
||||||
.OrderByDescending(a => taken.Sum(t => (t - a.First).LengthSquared))
|
.OrderByDescending(a => taken.Sum(t => (t - a.First).LengthSquared))
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRa.GameRules
|
|||||||
if (liveclips.Count == 0)
|
if (liveclips.Count == 0)
|
||||||
return null; /* avoid crashing if there's no clips at all */
|
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];
|
var s = liveclips[i];
|
||||||
liveclips.RemoveAt(i);
|
liveclips.RemoveAt(i);
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRa.Traits
|
|||||||
{
|
{
|
||||||
var shares = self.traits.WithInterface<ICrateAction>().Select(a => Pair.New(a, a.SelectionShares));
|
var shares = self.traits.WithInterface<ICrateAction>().Select(a => Pair.New(a, a.SelectionShares));
|
||||||
var totalShares = shares.Sum(a => a.Second);
|
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));
|
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||||
foreach (var s in shares)
|
foreach (var s in shares)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
for (var j = -1; j < 2; j++)
|
for (var j = -1; j < 2; j++)
|
||||||
for (var i = -1; i < 2; i++)
|
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))
|
if (self.World.OreCanSpreadInto(self.Location.X + i, self.Location.Y + j))
|
||||||
self.World.Map.AddOre(self.Location.X + i, self.Location.Y + j);
|
self.World.Map.AddOre(self.Location.X + i, self.Location.Y + j);
|
||||||
|
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
void SpawnCrate(Actor self, CrateSpawnerInfo info)
|
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;
|
var umt = inWater ? UnitMovementType.Float : UnitMovementType.Wheel;
|
||||||
|
|
||||||
for (; ; )
|
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))
|
if (self.World.IsCellBuildable(p, umt))
|
||||||
{
|
{
|
||||||
self.World.AddFrameEndTask(
|
self.World.AddFrameEndTask(
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ namespace OpenRa.Traits
|
|||||||
|
|
||||||
if (info.Spreads)
|
if (info.Spreads)
|
||||||
Ore.SpreadOre(self.World,
|
Ore.SpreadOre(self.World,
|
||||||
Game.SharedRandom,
|
self.World.SharedRandom,
|
||||||
info.Chance);
|
info.Chance);
|
||||||
|
|
||||||
if (info.Grows)
|
if (info.Grows)
|
||||||
Ore.GrowOre(self.World, Game.SharedRandom);
|
Ore.GrowOre(self.World, self.World.SharedRandom);
|
||||||
|
|
||||||
self.World.Minimap.InvalidateOre();
|
self.World.Minimap.InvalidateOre();
|
||||||
remainingTicks = (int)(info.Interval * 60 * 25);
|
remainingTicks = (int)(info.Interval * 60 * 25);
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ namespace OpenRa
|
|||||||
List<IEffect> effects = new List<IEffect>();
|
List<IEffect> effects = new List<IEffect>();
|
||||||
List<Action<World>> frameEndActions = new List<Action<World>>();
|
List<Action<World>> frameEndActions = new List<Action<World>>();
|
||||||
|
|
||||||
|
public Random SharedRandom = new Random(0); // synced
|
||||||
|
public Random CosmeticRandom = new Random(); // not synced
|
||||||
|
|
||||||
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||||
|
|
||||||
int localPlayerIndex;
|
int localPlayerIndex;
|
||||||
|
|||||||
@@ -177,13 +177,13 @@ namespace OpenRa
|
|||||||
|
|
||||||
public static int2 ChooseRandomEdgeCell(this World w)
|
public static int2 ChooseRandomEdgeCell(this World w)
|
||||||
{
|
{
|
||||||
var isX = Game.SharedRandom.Next(2) == 0;
|
var isX = w.SharedRandom.Next(2) == 0;
|
||||||
var edge = Game.SharedRandom.Next(2) == 0;
|
var edge = w.SharedRandom.Next(2) == 0;
|
||||||
|
|
||||||
return new int2(
|
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),
|
: (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));
|
: (edge ? w.Map.YOffset : w.Map.YOffset + w.Map.Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user