diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index 8c1472305..a79601b8b 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -233,7 +233,8 @@ namespace Barotrauma levelSeed = value; - backgroundSprite = LocationType.Random(levelSeed)?.GetPortrait(ToolBox.StringToInt(levelSeed)); + int intSeed = ToolBox.StringToInt(levelSeed); + backgroundSprite = LocationType.Random(new MTRandom(intSeed))?.GetPortrait(intSeed); seedBox.Text = levelSeed; //lastUpdateID++; diff --git a/Barotrauma/BarotraumaServer/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaServer/Source/Screens/NetLobbyScreen.cs index 6cea05941..fff8014d8 100644 --- a/Barotrauma/BarotraumaServer/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaServer/Source/Screens/NetLobbyScreen.cs @@ -148,7 +148,7 @@ namespace Barotrauma lastUpdateID++; levelSeed = value; - LocationType.Random(levelSeed); //call to sync up with clients + LocationType.Random(new MTRandom(ToolBox.StringToInt(levelSeed))); //call to sync up with clients } } diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs index ffe7cf9d3..9e00659fe 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameSession.cs @@ -139,7 +139,7 @@ namespace Barotrauma MTRandom rand = new MTRandom(ToolBox.StringToInt(seed)); for (int i = 0; i < 2; i++) { - dummyLocations[i] = Location.CreateRandom(new Vector2((float)rand.NextDouble() * 10000.0f, (float)rand.NextDouble() * 10000.0f), null); + dummyLocations[i] = Location.CreateRandom(new Vector2((float)rand.NextDouble() * 10000.0f, (float)rand.NextDouble() * 10000.0f), null, rand); } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index b1c396691..5bace8352 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -1519,14 +1519,6 @@ namespace Barotrauma string outpostFile = outpostFiles.GetRandom(Rand.RandSync.Server); var outpost = new Submarine(outpostFile, tryLoad: false); outpost.Load(unloadPrevious: false); - if (i == 0) - { - if (GameMain.GameSession?.StartLocation != null) { outpost.Name = GameMain.GameSession.StartLocation.Name; } - } - else - { - if (GameMain.GameSession?.EndLocation != null) { outpost.Name = GameMain.GameSession.EndLocation.Name; } - } outpost.MakeOutpost(); Point? minSize = null; @@ -1567,10 +1559,12 @@ namespace Barotrauma if ((i == 0) == !Mirrored) { StartOutpost = outpost; + if (GameMain.GameSession?.StartLocation != null) { outpost.Name = GameMain.GameSession.StartLocation.Name; } } else { EndOutpost = outpost; + if (GameMain.GameSession?.EndLocation != null) { outpost.Name = GameMain.GameSession.EndLocation.Name; } } } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Map/Location.cs b/Barotrauma/BarotraumaShared/Source/Map/Map/Location.cs index e397d485f..04a108a94 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Map/Location.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Map/Location.cs @@ -1,4 +1,5 @@ using Microsoft.Xna.Framework; +using System; using System.Collections.Generic; using System.Linq; @@ -76,10 +77,10 @@ namespace Barotrauma } } - public Location(Vector2 mapPosition, int? zone) + public Location(Vector2 mapPosition, int? zone, Random rand) { - this.Type = LocationType.Random("", zone); - this.Name = RandomName(Type); + this.Type = LocationType.Random(rand, zone); + this.Name = RandomName(Type, rand); this.MapPosition = mapPosition; PortraitId = ToolBox.StringToInt(Name); @@ -87,9 +88,9 @@ namespace Barotrauma Connections = new List(); } - public static Location CreateRandom(Vector2 position, int? zone) + public static Location CreateRandom(Vector2 position, int? zone , Random rand) { - return new Location(position, zone); + return new Location(position, zone, rand); } public IEnumerable GetMissionsInConnection(LocationConnection connection) @@ -129,10 +130,10 @@ namespace Barotrauma availableMissions.RemoveAll(m => m.Completed); } - private string RandomName(LocationType type) + private string RandomName(LocationType type, Random rand) { - baseName = type.GetRandomName(); - nameFormatIndex = Rand.Int(type.NameFormats.Count, Rand.RandSync.Server); + baseName = type.GetRandomName(rand); + nameFormatIndex = rand.Next() % type.NameFormats.Count; return type.NameFormats[nameFormatIndex].Replace("[name]", baseName); } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Map/LocationType.cs b/Barotrauma/BarotraumaShared/Source/Map/Map/LocationType.cs index 42039e967..aecfd8149 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Map/LocationType.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Map/LocationType.cs @@ -155,20 +155,15 @@ namespace Barotrauma return portraits[Math.Abs(portraitId) % portraits.Count]; } - public string GetRandomName() + public string GetRandomName(Random rand) { - return names[Rand.Int(names.Count, Rand.RandSync.Server)]; + return names[rand.Next() % names.Count]; } - public static LocationType Random(string seed = "", int? zone = null) + public static LocationType Random(Random rand, int? zone = null) { Debug.Assert(List.Count > 0, "LocationType.list.Count == 0, you probably need to initialize LocationTypes"); - if (!string.IsNullOrWhiteSpace(seed)) - { - Rand.SetSyncedSeed(ToolBox.StringToInt(seed)); - } - List allowedLocationTypes = zone.HasValue ? List.FindAll(lt => lt.CommonnessPerZone.ContainsKey(zone.Value)) : List; if (allowedLocationTypes.Count == 0) @@ -180,12 +175,12 @@ namespace Barotrauma { return ToolBox.SelectWeightedRandom( allowedLocationTypes, - allowedLocationTypes.Select(a => a.CommonnessPerZone[zone.Value]).ToList(), - Rand.RandSync.Server); + allowedLocationTypes.Select(a => a.CommonnessPerZone[zone.Value]).ToList(), + rand); } else { - return allowedLocationTypes[Rand.Int(allowedLocationTypes.Count, Rand.RandSync.Server)]; + return allowedLocationTypes[rand.Next() % allowedLocationTypes.Count]; } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs index 5776ce80b..eedceada2 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs @@ -196,7 +196,7 @@ namespace Barotrauma Vector2 position = points[positionIndex]; if (newLocations[1 - i] != null && newLocations[1 - i].MapPosition == position) position = points[1 - positionIndex]; int zone = MathHelper.Clamp(generationParams.DifficultyZones - (int)Math.Floor(Vector2.Distance(position, mapCenter) / zoneRadius), 1, generationParams.DifficultyZones); - newLocations[i] = Location.CreateRandom(position, zone); + newLocations[i] = Location.CreateRandom(position, zone, Rand.GetRNG(Rand.RandSync.Server)); Locations.Add(newLocations[i]); }