Ticket #1582: playernames.patch
File playernames.patch, 2.1 KB (added by , 12 years ago) |
---|
-
gamesetup.js
269 269 updateGameAttributes(); 270 270 } 271 271 }; 272 273 272 274 273 // Set events 275 274 var civ = getGUIObjectByName("playerCiv["+i+"]"); … … 760 759 // Assign random civilizations to players with that choice 761 760 // (this is synchronized because we're the host) 762 761 var civs = [ civ.Code for each (civ in g_CivData) if (civ.SelectableInGameSetup !== false) ]; 762 var civAINames = [ civ.AINames for each (civ in g_CivData) if (civ.SelectableInGameSetup !== false) ]; 763 763 for (var i = 0; i < numPlayers; ++i) 764 764 { 765 765 if (g_GameAttributes.settings.PlayerData[i].Civ == "random") 766 766 g_GameAttributes.settings.PlayerData[i].Civ = civs[Math.floor(Math.random()*civs.length)]; 767 if ((g_GameAttributes.mapType !== "scenario")&&(g_GameAttributes.settings.PlayerData[i].AI)) 768 { 769 var civIndex; 770 for (var j = 0; j < civs.length; ++j) 771 { 772 if (civs[j] == g_GameAttributes.settings.PlayerData[i].Civ) 773 { 774 civIndex = j; 775 break; 776 } 777 } 778 779 var usedName = 0; 780 var chosenName = civAINames[civIndex][Math.floor(Math.random() * civAINames[civIndex].length)]; 781 for (var j = 0; j < numPlayers; ++j) 782 { 783 if (g_GameAttributes.settings.PlayerData[j].Name.indexOf(chosenName) > -1) 784 { 785 usedName++; 786 } 787 } 788 789 if (usedName) 790 { 791 g_GameAttributes.settings.PlayerData[i].Name = chosenName + " " + getRomanNumber(usedName+1); 792 } 793 else 794 { 795 g_GameAttributes.settings.PlayerData[i].Name = chosenName; 796 } 797 } 767 798 } 768 799 769 800 if (g_IsNetworked) … … 1319 1350 return false; 1320 1351 } 1321 1352 1353 // A function to get roman numbers from 1 to 8 which is needed for AI name assignment 1354 function getRomanNumber(number) 1355 { 1356 switch (number) 1357 { 1358 case 1: 1359 return "I"; 1360 1361 case 2: 1362 return "II"; 1322 1363 1364 case 3: 1365 return "III"; 1323 1366 1367 case 4: 1368 return "IV"; 1369 1370 case 5: 1371 return "V"; 1372 1373 case 6: 1374 return "VI"; 1375 1376 case 7: 1377 return "VII"; 1378 1379 case 8: 1380 return "VIII"; 1381 1382 default: 1383 return number; 1384 } 1385 } 1324 1386 1387 1388