Ticket #3880: autostart.patch

File autostart.patch, 3.0 KB (added by mimo, 8 years ago)
  • source/ps/GameSetup/GameSetup.cpp

     
    13241324    scriptInterface.SetProperty(settings, "AISeed", aiseed);
    13251325
    13261326    // Set player data for AIs
    1327     //      attrs.settings = { PlayerData: [ { AI: ... }, ... ] }:
     1327    //      attrs.settings = { PlayerData: [ { AI: ... }, ... ] }
     1328    //                          or = { PlayerData: [ null, { AI: ... }, ... ] } when gaia set
     1329    int i0 = 1;
     1330    JS::RootedValue player(cx);
     1331    if (scriptInterface.GetPropertyInt(playerData, 0, &player) && player.isNull())
     1332        i0 = 0;
     1333
    13281334    if (args.Has("autostart-ai"))
    13291335    {
    13301336        std::vector<CStr> aiArgs = args.GetMultiple("autostart-ai");
     
    13341340
    13351341            // Instead of overwriting existing player data, modify the array
    13361342            JS::RootedValue player(cx);
    1337             if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined())
     1343            if (!scriptInterface.GetPropertyInt(playerData, playerID-i0, &player) || player.isUndefined())
    13381344            {
    13391345                if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes")
    13401346                {
     
    13481354            CStr name = aiArgs[i].AfterFirst(":");
    13491355            scriptInterface.SetProperty(player, "AI", std::string(name));
    13501356            scriptInterface.SetProperty(player, "AIDiff", 3);
    1351             scriptInterface.SetPropertyInt(playerData, playerID-1, player);
     1357            scriptInterface.SetPropertyInt(playerData, playerID-i0, player);
    13521358        }
    13531359    }
    13541360    // Set AI difficulty
     
    13611367
    13621368            // Instead of overwriting existing player data, modify the array
    13631369            JS::RootedValue player(cx);
    1364             if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined())
     1370            if (!scriptInterface.GetPropertyInt(playerData, playerID-i0, &player) || player.isUndefined())
    13651371            {
    13661372                if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes")
    13671373                {
     
    13741380
    13751381            int difficulty = civArgs[i].AfterFirst(":").ToInt();           
    13761382            scriptInterface.SetProperty(player, "AIDiff", difficulty);
    1377             scriptInterface.SetPropertyInt(playerData, playerID-1, player);
     1383            scriptInterface.SetPropertyInt(playerData, playerID-i0, player);
    13781384        }
    13791385    }
    13801386    // Set player data for Civs
     
    13891395
    13901396                // Instead of overwriting existing player data, modify the array
    13911397                JS::RootedValue player(cx);
    1392                 if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined())
     1398                if (!scriptInterface.GetPropertyInt(playerData, playerID-i0, &player) || player.isUndefined())
    13931399                {
    13941400                    if (mapDirectory == L"skirmishes")
    13951401                    {
     
    14001406                    scriptInterface.Eval("({})", &player);
    14011407                }
    14021408           
    1403                 CStr name = civArgs[i].AfterFirst(":");         
     1409                CStr name = civArgs[i].AfterFirst(":");
    14041410                scriptInterface.SetProperty(player, "Civ", std::string(name));
    1405                 scriptInterface.SetPropertyInt(playerData, playerID-1, player);
     1411                scriptInterface.SetPropertyInt(playerData, playerID-i0, player);
    14061412            }
    14071413        }
    14081414        else