diff --git a/C7/Text/c7-static-map-save-standalone.json b/C7/Text/c7-static-map-save-standalone.json index 8db0930b..9258bcd2 100644 --- a/C7/Text/c7-static-map-save-standalone.json +++ b/C7/Text/c7-static-map-save-standalone.json @@ -71322,7 +71322,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "A Barbarian Chiefdom", - "cityNameIndex": 0, "turnsUntilPriorityReevaluation": 0, "luxuryRate": 0, "scienceRate": 5, @@ -71340,7 +71339,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Netherlands", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 57, @@ -71417,7 +71415,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "America", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 64, @@ -71494,7 +71491,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Aztecs", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 59, @@ -71567,7 +71563,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Inca", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 76, @@ -71644,7 +71639,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Persia", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 30, @@ -71725,7 +71719,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Maya", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 9, @@ -71802,7 +71795,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Iroquois", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 46, diff --git a/C7/Text/c7-static-map-save.json b/C7/Text/c7-static-map-save.json index 86c084c6..eff2c8ec 100644 --- a/C7/Text/c7-static-map-save.json +++ b/C7/Text/c7-static-map-save.json @@ -73895,7 +73895,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "A Barbarian Chiefdom", - "cityNameIndex": 0, "turnsUntilPriorityReevaluation": 0, "luxuryRate": 0, "scienceRate": 5, @@ -73913,7 +73912,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Netherlands", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 57, @@ -73990,7 +73988,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "America", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 64, @@ -74067,7 +74064,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Aztecs", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 59, @@ -74140,7 +74136,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Inca", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 76, @@ -74217,7 +74212,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Persia", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 30, @@ -74298,7 +74292,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Maya", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 9, @@ -74375,7 +74368,6 @@ "hasPlayedCurrentTurn": false, "defeated": false, "civilization": "Iroquois", - "cityNameIndex": 0, "tileKnowledge": [ { "x": 46, diff --git a/C7Engine/C7GameData/ImportCiv3.cs b/C7Engine/C7GameData/ImportCiv3.cs index 22a71f74..5f8d3d8b 100644 --- a/C7Engine/C7GameData/ImportCiv3.cs +++ b/C7Engine/C7GameData/ImportCiv3.cs @@ -406,7 +406,6 @@ private void ImportBicLeaders() { save.Players.Add(MakeSavePlayerFromCiv(save.Civilizations[i], isBarbarian: i == 0, isHuman: false, - cityNameIndex: 0, era: "")); // Set a government for players not associated with LEAD. @@ -465,7 +464,6 @@ private void ImportSavLeaders() { SavePlayer player = MakeSavePlayerFromCiv(civ, isBarbarian: i == 0, isHuman: i == 1, - cityNameIndex: leader.FoundedCities, era: theBiq.Eras[leader.Era].CivilopediaEntry); // Record what the player is currently researching. @@ -769,7 +767,7 @@ private void ImportSavLeaders() { } } - private SavePlayer MakeSavePlayerFromCiv(Civilization civ, bool isBarbarian, bool isHuman, int cityNameIndex, string era) { + private SavePlayer MakeSavePlayerFromCiv(Civilization civ, bool isBarbarian, bool isHuman, string era) { return new SavePlayer { id = ids.CreateID("player"), colorIndex = civ.colorIndex, @@ -779,7 +777,6 @@ private SavePlayer MakeSavePlayerFromCiv(Civilization civ, bool isBarbarian, boo // Never let barbarians play before a real player. hasPlayedCurrentTurn = isBarbarian, - cityNameIndex = cityNameIndex, eraCivilopediaName = era, }; } diff --git a/C7Engine/C7GameData/Player.cs b/C7Engine/C7GameData/Player.cs index 4b598393..ffe84579 100644 --- a/C7Engine/C7GameData/Player.cs +++ b/C7Engine/C7GameData/Player.cs @@ -23,7 +23,6 @@ public class Player { public bool defeated = false; public Civilization civilization; - internal int cityNameIndex = 0; public List units = new List(); public List cities = new List(); @@ -157,18 +156,29 @@ public void AddTechItemToResearchQueue(Tech tech) { ResearchQueue.Enqueue(tech); } - public string GetNextCityName() { - string name = civilization.cityNames[cityNameIndex % civilization.cityNames.Count]; - int bonusLoops = cityNameIndex / civilization.cityNames.Count; - if (bonusLoops % 2 == 1) { - name = "New " + name; - } - int suffix = (bonusLoops / 2) + 1; - if (suffix > 1) { - name = name + " " + suffix; //e.g. for bonusLoops = 2, we'll have "Athens 2" + private IEnumerable CityNameGenerator() { + List cityNames = civilization.cityNames; + int loopCounter = 0; + + // Perpetual generator expression to yield all city names lazily + while (true) { + foreach (string city in cityNames) { + if (loopCounter == 0) yield return city; + else if (loopCounter == 1) yield return $"New {city}"; + else { + if (loopCounter % 2 == 0) yield return $"{city} {(loopCounter / 2) + 1}"; + else yield return $"New {city} {(loopCounter / 2) + 1}"; + } + } + loopCounter++; } - cityNameIndex++; - return name; + } + + public string GetNextCityName() { + // Convert to hashset for faster lookups + HashSet cityNameHashSet = cities.Select(city => city.name).ToHashSet(); + + return CityNameGenerator().First(x => !cityNameHashSet.Contains(x)); } public Player() { diff --git a/C7Engine/C7GameData/Save/SavePlayer.cs b/C7Engine/C7GameData/Save/SavePlayer.cs index 90f2d876..1c5fc6b3 100644 --- a/C7Engine/C7GameData/Save/SavePlayer.cs +++ b/C7Engine/C7GameData/Save/SavePlayer.cs @@ -11,7 +11,6 @@ public class SavePlayer { public bool defeated = false; public string civilization; - public int cityNameIndex = 0; public List tileKnowledge = new List(); @@ -68,7 +67,6 @@ public Player ToPlayer(GameMap map, List civilizations, List civ.name == civilization) : null, - cityNameIndex = cityNameIndex, knownTechs = knownTechs, eraCivilopediaName = eraCivilopediaName, luxuryRate = luxuryRate, @@ -118,7 +116,6 @@ public SavePlayer(Player player) { civilization = player.civilization?.name; // TODO: this should be computed by looking at cities defined in the save // so that adding cities in the save structure doesn't require updating this value - cityNameIndex = player.cityNameIndex; tileKnowledge = player.tileKnowledge.AllKnownTiles().ConvertAll(tile => new TileLocation(tile)); turnsUntilPriorityReevaluation = player.turnsUntilPriorityReevaluation; knownTechs = player.knownTechs;