From 2ddac36060804775c19e41cb2264fcfdfa4d8c3c Mon Sep 17 00:00:00 2001 From: wowgetoffyourcellphone Date: Thu, 9 May 2024 18:31:33 +0000 Subject: [PATCH] [GUI] Remove Roman numerals from bot names To avoid the appearance of two Roman numerals at the end of bot names (e.g. "Artaxshasha II II -> here "Artaxshasha II" was the name itself and the second "II" was added when the name was chosen for the second time), remove the addition of Roman numerals entirely. Instead, if possible, a new name is chosen for each bot. If not, the suffix "(n)" is added counting the duplicates and warning is displayed. AINames are added to the Iberians, Gauls, and Mauryas bringing their totel to at least 8 each in order avoid any duplicates in regular 8-player games. Credit to Norse_Harold for changing the condition for reusing names to not use a hardcoded assumption about the maximum number of player slots Patch by @Vantha Accepted by @phosit, @wowgetoffyourcellphone Differential Revision: https://code.wildfiregames.com/D5256 git-svn-id: https://svn.wildfiregames.com/public/ps/trunk@28082 3db68df2-c116-0410-a063-a993310a9797 --- .../public/gamesettings/attributes/PlayerName.js | 53 ++++++++++++---------- .../mods/public/gui/credits/texts/programming.json | 1 + .../mods/public/simulation/data/civs/gaul.json | 1 + .../mods/public/simulation/data/civs/iber.json | 4 ++ .../mods/public/simulation/data/civs/maur.json | 6 ++- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/binaries/data/mods/public/gamesettings/attributes/PlayerName.js b/binaries/data/mods/public/gamesettings/attributes/PlayerName.js index 417cf987a1..1d524ab864 100644 --- a/binaries/data/mods/public/gamesettings/attributes/PlayerName.js +++ b/binaries/data/mods/public/gamesettings/attributes/PlayerName.js @@ -62,10 +62,11 @@ GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSett } /** - * Pick bot names. + * Pick AI names. */ pickRandomItems() { + const AIPlayerNamesList = []; let picked = false; for (let i in this.values) { @@ -82,22 +83,29 @@ GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSett continue; picked = true; - // Pick one of the available botnames for the chosen civ - // Determine botnames - let chosenName = pickRandom(this.settings.civData[civ].AINames); - if (!this.settings.isNetworked) - chosenName = translate(chosenName); - - // Count how many players use the chosenName - let usedName = this.values.filter(oName => oName && oName.indexOf(chosenName) !== -1).length; - - this.values[i] = - usedName ? - sprintf(this.RomanLabel, { - "playerName": chosenName, - "romanNumber": this.RomanNumbers[usedName + 1] - }) : - chosenName; + + const names = this.settings.civData[civ].AINames; + const remainingNames = names.filter(name => !AIPlayerNamesList.includes(name)); + const chosenName = pickRandom(remainingNames.length ? remainingNames : names); + + // Avoid translating AI names if the game is networked, so all players see and refer to + // English names instead of names in the language of the host. + const translatedCountLabel = this.settings.isNetworked ? this.CountLabel : translate(this.CountLabel); + const translatedChosenName = this.settings.isNetworked ? chosenName : translate(chosenName); + + const duplicateNameCount = AIPlayerNamesList.reduce((count, name) => { + if (name == chosenName) + count++; + return count; + }, 0); + + AIPlayerNamesList.push(chosenName); + + this.values[i] = !duplicateNameCount ? translatedChosenName : + sprintf(translatedCountLabel, { + "playerName": translatedChosenName, + "nameCount": duplicateNameCount + 1 + }); } if (picked) this.trigger("values"); @@ -128,9 +136,8 @@ GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSett } }; - -GameSettings.prototype.Attributes.PlayerName.prototype.RomanLabel = - translate("%(playerName)s %(romanNumber)s"); - -GameSettings.prototype.Attributes.PlayerName.prototype.RomanNumbers = - [undefined, "I", "II", "III", "IV", "V", "VI", "VII", "VIII"]; +/** Translation: This is a template (sprintf format specifier) for the name of + * an AI-controlled player and a unique number for each of the players with + * that same name. Example: Perseus (2) + */ +GameSettings.prototype.Attributes.PlayerName.prototype.CountLabel = markForTranslation("%(playerName)s (%(nameCount)i)"); diff --git a/binaries/data/mods/public/gui/credits/texts/programming.json b/binaries/data/mods/public/gui/credits/texts/programming.json index 14f0774aa9..1d3be88bcb 100644 --- a/binaries/data/mods/public/gui/credits/texts/programming.json +++ b/binaries/data/mods/public/gui/credits/texts/programming.json @@ -290,6 +290,7 @@ { "nick": "tpearson", "name": "Timothy Pearson" }, { "nick": "user1", "name": "A. C." }, { "nick": "usey11" }, + { "nick": "Vantha"}, { "nick": "vincent_c", "name": "Vincent Cheng" }, { "nick": "vinhig", "name": "Vincent Higginson" }, { "nick": "vladislavbelov", "name": "Vladislav Belov" }, diff --git a/binaries/data/mods/public/simulation/data/civs/gaul.json b/binaries/data/mods/public/simulation/data/civs/gaul.json index 114fe7caf0..e8d7938caf 100644 --- a/binaries/data/mods/public/simulation/data/civs/gaul.json +++ b/binaries/data/mods/public/simulation/data/civs/gaul.json @@ -64,6 +64,7 @@ "Divico", "Ambiorix", "Liscus", + "Orgetorix", "Valetiacus", "Viridovix" ], diff --git a/binaries/data/mods/public/simulation/data/civs/iber.json b/binaries/data/mods/public/simulation/data/civs/iber.json index e01dab63ab..9def522f9f 100644 --- a/binaries/data/mods/public/simulation/data/civs/iber.json +++ b/binaries/data/mods/public/simulation/data/civs/iber.json @@ -61,8 +61,12 @@ ], "AINames": [ "Audax", + "Calcus", "Ditalcus", "Minurus", + "Olyndicus", + "Orison", + "Tanginus", "Tautalus" ], "SkirmishReplacements": { diff --git a/binaries/data/mods/public/simulation/data/civs/maur.json b/binaries/data/mods/public/simulation/data/civs/maur.json index 1eff3bd505..ef1d00bc7f 100644 --- a/binaries/data/mods/public/simulation/data/civs/maur.json +++ b/binaries/data/mods/public/simulation/data/civs/maur.json @@ -55,12 +55,14 @@ ], "AINames": [ "Bindusara Maurya", + "Brihadratha Maurya", "Dasharatha Maurya", + "Devavarman Maurya", + "Kunala Maurya", "Samprati Maurya", "Shalishuka Maurya", - "Devavarman Maurya", "Shatadhanvan Maurya", - "Brihadratha Maurya" + "Tivala Maurya" ], "SkirmishReplacements": { "skirmish/units/default_infantry_ranged_b": "units/maur/infantry_archer_b", -- 2.11.4.GIT