Ticket #1582: playernamespatch.3.patch
File playernamespatch.3.patch, 2.4 KB (added by , 12 years ago) |
---|
-
common/functions_utility.js
239 239 } 240 240 } 241 241 } 242 243 // ==================================================================== 244 // "Inside-out" implementation of Fisher-Yates shuffle 245 function shuffleArray(source) 246 { 247 if (!source.length) 248 return []; 249 250 var result = [source[0]]; 251 for (var i = 1; i < source.length; ++i) 252 { 253 var j = Math.floor(Math.random() * i); 254 result[i] = result[j]; 255 result[j] = source[i]; 256 } 257 return result; 258 } 259 No newline at end of file -
gamesetup/gamesetup.js
767 767 // Assign random civilizations to players with that choice 768 768 // (this is synchronized because we're the host) 769 769 var civs = [ civ.Code for each (civ in g_CivData) if (civ.SelectableInGameSetup !== false) ]; 770 771 const romanNumbers = [undefined, "I", "II", "III", "IV", "V", "VI", "VII", "VIII"]; 770 772 for (var i = 0; i < numPlayers; ++i) 771 773 { 772 774 if (g_GameAttributes.settings.PlayerData[i].Civ == "random") 773 775 g_GameAttributes.settings.PlayerData[i].Civ = civs[Math.floor(Math.random()*civs.length)]; 776 // Setting names for AI players. Check if the player is AI and the match is not a scenario 777 if ((g_GameAttributes.mapType !== "scenario")&&(g_GameAttributes.settings.PlayerData[i].AI)) 778 { 779 // Get the civ specific names 780 var civAINames = (g_CivData[g_GameAttributes.settings.PlayerData[i].Civ].AINames !== undefined ? shuffleArray(g_CivData[g_GameAttributes.settings.PlayerData[i].Civ].AINames) : g_CivData[civs[j]].Name); 781 // Choose the name 782 var usedName = 0; 783 if (i < civAINames.length) 784 var chosenName = civAINames[i]; 785 else 786 var chosenName = civAINames[Math.floor(Math.random() * civAINames[civIndex].length)]; 787 for (var j = 0; j < numPlayers; ++j) 788 if (g_GameAttributes.settings.PlayerData[j].Name.indexOf(chosenName) !== -1) 789 usedName++; 790 791 // Assign civ specific names to AI players 792 if (usedName) 793 g_GameAttributes.settings.PlayerData[i].Name = chosenName + " " + romanNumbers[usedName+1]; 794 else 795 g_GameAttributes.settings.PlayerData[i].Name = chosenName; 796 } 774 797 } 775 798 776 799 if (g_IsNetworked) … … 1356 1379 } 1357 1380 return false; 1358 1381 } 1359 1360 1361 1362