diff --git a/Assets/Scripts/ServerShared/Galaxy.cs b/Assets/Scripts/ServerShared/Galaxy.cs index 89fa80794..7291a0c38 100644 --- a/Assets/Scripts/ServerShared/Galaxy.cs +++ b/Assets/Scripts/ServerShared/Galaxy.cs @@ -333,12 +333,13 @@ public class Galaxy ref Random random, Action progressCallback = null) { + var used = new HashSet(); for (var i = 0; i < Factions.Length; i++) { progressCallback?.Invoke($"Feeding Markov Chains: {i + 1} / {Factions.Length}"); //if(progressCallback!=null) Thread.Sleep(250); // Inserting Delay to make it seem like it's doing more work lmao var faction = Factions[i]; - _nameGenerators[faction] = new MarkovNameGenerator(ref random, cache.Get(faction.GeonameFile).Names, nameGeneratorSettings); + _nameGenerators[faction] = new MarkovNameGenerator(ref random, cache.Get(faction.GeonameFile).Names, nameGeneratorSettings, used); } // Generate zone name using the owner's name generator, otherwise assign catalogue ID diff --git a/Assets/Scripts/ServerShared/MarkovNameGenerator.cs b/Assets/Scripts/ServerShared/MarkovNameGenerator.cs index cf58a7b91..528684f40 100644 --- a/Assets/Scripts/ServerShared/MarkovNameGenerator.cs +++ b/Assets/Scripts/ServerShared/MarkovNameGenerator.cs @@ -14,14 +14,17 @@ public class MarkovNameGenerator { private Dictionary> _chains = new Dictionary>(); private List _samples = new List(); - private static List _used = new List(); + // The names already given, shared by every generator that must not repeat another's: a galaxy passes one set to + // all its factions' generators. Never process-wide, so one galaxy's names cannot change the next galaxy's. + private readonly HashSet _used; private int _order; private int _minLength; private int _maxLength; private Random _random; - public MarkovNameGenerator(ref Random random, IEnumerable sampleNames, NameGeneratorSettings settings) + public MarkovNameGenerator(ref Random random, IEnumerable sampleNames, NameGeneratorSettings settings, HashSet used) { + _used = used; var names = new HashSet(); foreach (var line in sampleNames) { @@ -41,6 +44,7 @@ public class MarkovNameGenerator public MarkovNameGenerator(ref Random random, IEnumerable sampleNames, int order, int minLength, int maxLength) { + _used = new HashSet(); _random = random; _order = max(1, order); @@ -113,12 +117,6 @@ public class MarkovNameGenerator } } - //Reset the used names - public void Reset() - { - _used.Clear(); - } - //Get a random letter from the chain private char GetLetter(string token) {