Ticket #1582: playernames.patch

File playernames.patch, 2.1 KB (added by O.Davoodi, 12 years ago)
  • gamesetup.js

     
    269269                updateGameAttributes();
    270270            }
    271271        };
    272        
    273272
    274273        // Set events
    275274        var civ = getGUIObjectByName("playerCiv["+i+"]");
     
    760759    // Assign random civilizations to players with that choice
    761760    //  (this is synchronized because we're the host)
    762761    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) ];
    763763    for (var i = 0; i < numPlayers; ++i)
    764764    {
    765765        if (g_GameAttributes.settings.PlayerData[i].Civ == "random")
    766766            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        }
    767798    }
    768799   
    769800    if (g_IsNetworked)
     
    13191350    return false;
    13201351}
    13211352
     1353// A function to get roman numbers from 1 to 8 which is needed for AI name assignment
     1354function getRomanNumber(number)
     1355{
     1356    switch (number)
     1357    {
     1358    case 1:
     1359        return "I";
     1360   
     1361    case 2:
     1362        return "II";
    13221363
     1364    case 3:
     1365        return "III";
    13231366
     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}
    13241386
     1387
     1388