(b8f75ee96) Fixed level inequality errors caused by 866621c. Accessing the level start/end location properties during level generation caused the seed of RandSync.Server to be changed. Now generating a new random location uses a new MTRandom instance and doesn't touch RandSync.Server.
This commit is contained in:
@@ -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<LocationConnection>();
|
||||
}
|
||||
|
||||
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<Mission> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<LocationType> 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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user