From eaef00e05ccb706c0211dc6e46c2e29ef4eb1a4a Mon Sep 17 00:00:00 2001 From: FloPinguin <25036848+FloPinguin@users.noreply.github.com> Date: Fri, 9 Jan 2026 04:58:27 +0100 Subject: [PATCH] =?UTF-8?q?Some=20little=20HumansVsNations=20improvements?= =?UTF-8?q?=20before=20public=20games=20launch=20=F0=9F=A4=96=20(#2825)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description: - Added `generateUniqueNationName()` to `NationCreation` because I saw a duplicate name while spawning 300 nations on Pangaea 😄 - Switched HumansVsNations public game difficulty from hard to impossible because I realized how crazy strong troop donations between humans are (in an enzo HVN stream). Maybe I have to make nations donate troops to each other, we will see... Playtests won't tell the truth because the players attending these are probably better than the usual OF player. I will try to check the HVN winrate via API after launch ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin --- src/core/game/NationCreation.ts | 62 ++++++++++++++++++++++----------- src/server/MapPlaylist.ts | 4 ++- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/core/game/NationCreation.ts b/src/core/game/NationCreation.ts index 3e4d15807..b2bdc0b70 100644 --- a/src/core/game/NationCreation.ts +++ b/src/core/game/NationCreation.ts @@ -69,9 +69,11 @@ export function createNationsForGame( // If we need more nations than defined in manifest, create additional ones const nations: Nation[] = manifestNations.map(toNation); + const usedNames = new Set(nations.map((n) => n.playerInfo.name)); const additionalCount = targetNationCount - manifestNations.length; for (let i = 0; i < additionalCount; i++) { - const name = generateNationName(random); + const name = generateUniqueNationName(random, usedNames); + usedNames.add(name); nations.push( new Nation( undefined, @@ -97,6 +99,45 @@ export function getCompactMapNationCount( return manifestNationCount; } +function generateUniqueNationName( + random: PseudoRandom, + usedNames: Set, +): string { + for (let attempt = 0; attempt < 1000; attempt++) { + const name = generateNationName(random); + if (!usedNames.has(name)) { + return name; + } + } + // Fallback if we can't generate unique name (extremely unlikely) + // Append a number to ensure uniqueness + let counter = 1; + const baseName = generateNationName(random); + while (usedNames.has(`${baseName} ${counter}`)) { + counter++; + } + return `${baseName} ${counter}`; +} + +function generateNationName(random: PseudoRandom): string { + const template = NAME_TEMPLATES[random.nextInt(0, NAME_TEMPLATES.length)]; + const noun = NOUNS[random.nextInt(0, NOUNS.length)]; + + const result: string[] = []; + + for (const part of template) { + if (part === PLURAL_NOUN) { + result.push(pluralize(noun)); + } else if (part === NOUN) { + result.push(noun); + } else { + result.push(part); + } + } + + return result.join(" "); +} + const PLURAL_NOUN = Symbol("plural!"); const NOUN = Symbol("noun!"); @@ -290,25 +331,6 @@ const NOUNS = [ "Penguin", ]; -function generateNationName(random: PseudoRandom): string { - const template = NAME_TEMPLATES[random.nextInt(0, NAME_TEMPLATES.length)]; - const noun = NOUNS[random.nextInt(0, NOUNS.length)]; - - const result: string[] = []; - - for (const part of template) { - if (part === PLURAL_NOUN) { - result.push(pluralize(noun)); - } else if (part === NOUN) { - result.push(noun); - } else { - result.push(part); - } - } - - return result.join(" "); -} - // Words from NOUNS that need irregular "-oes" plural const O_TO_OES = new Set(["Potato", "Tomato"]); diff --git a/src/server/MapPlaylist.ts b/src/server/MapPlaylist.ts index 7544aa4c8..aaff17264 100644 --- a/src/server/MapPlaylist.ts +++ b/src/server/MapPlaylist.ts @@ -121,7 +121,9 @@ export class MapPlaylist { gameMapSize: isCompact ? GameMapSize.Compact : GameMapSize.Normal, publicGameModifiers: { isCompact, isRandomSpawn }, difficulty: - playerTeams === HumansVsNations ? Difficulty.Hard : Difficulty.Easy, + playerTeams === HumansVsNations + ? Difficulty.Impossible + : Difficulty.Easy, infiniteGold: false, infiniteTroops: false, maxTimerValue: undefined,