Ticket #3804: gamesetup.js.3.patch

File gamesetup.js.3.patch, 1.9 KB (added by Vladislav Belov, 8 years ago)
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    873873function savePersistMatchSettings()
    874874{
    875875    let attributes = Engine.ConfigDB_GetValue("user", "persistmatchsettings") == "true" ? g_GameAttributes : {};
     876
     877    // Fill players with default AIs
     878    for (let i = 0; i < attributes.settings.PlayerData.length; ++i)
     879        if (!attributes.settings.PlayerData[i].AI)
     880            attributes.settings.PlayerData[i].AI = g_DefaultPlayerData[i].AI;
     881
    876882    Engine.WriteJSONFile(g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP, attributes);
    877883}
    878884
     
    15701576    // Player slots are indexed from 0 as Gaia is omitted.
    15711577    let newPlayerID = newSlot + 1;
    15721578    let playerID = g_PlayerAssignments[guid].player;
     1579    let outdatedAttributes = false;
    15731580
    15741581    // Attempt to swap the player or AI occupying the target slot,
    15751582    // if any, into the slot this player is currently in.
     
    15901597
    15911598        // Transfer the AI from the target slot to the current slot.
    15921599        g_GameAttributes.settings.PlayerData[playerID - 1].AI = g_GameAttributes.settings.PlayerData[newSlot].AI;
     1600
     1601        // Swap civilizations only if they aren't fixed
     1602        if (g_GameAttributes.mapType != "scenario")
     1603        {
     1604            [g_GameAttributes.settings.PlayerData[playerID - 1].Civ, g_GameAttributes.settings.PlayerData[newSlot].Civ] =
     1605                [g_GameAttributes.settings.PlayerData[newSlot].Civ, g_GameAttributes.settings.PlayerData[playerID - 1].Civ];
     1606
     1607            if (!g_IsInGuiUpdate)
     1608                outdatedAttributes = true;
     1609        }
    15931610    }
    15941611
    15951612    if (g_IsNetworked)
     
    15991616
    16001617    // Remove AI from this player slot
    16011618    g_GameAttributes.settings.PlayerData[newSlot].AI = "";
     1619
     1620    if (outdatedAttributes)
     1621        updateGameAttributes();
    16021622}
    16031623
    16041624function submitChatInput()