diff --git a/binaries/data/mods/public/gui/gamesetup/gamesetup.js b/binaries/data/mods/public/gui/gamesetup/gamesetup.js
index 5f71e4a..658bf06 100644
a
|
b
|
var g_AssignedCount = 0;
|
74 | 74 | // tick handler |
75 | 75 | var g_LoadingState = 0; // 0 = not started, 1 = loading, 2 = loaded |
76 | 76 | |
| 77 | // Used when restoring previously saved game settings in networked games. |
| 78 | // Used for assigning the host player to the slot he/she previously was at. |
| 79 | var g_HostPlayerSlot = -1; |
| 80 | |
77 | 81 | //////////////////////////////////////////////////////////////////////////////////////////////// |
78 | 82 | |
79 | 83 | function init(attribs) |
… |
… |
function handleNetMessage(message)
|
480 | 484 | |
481 | 485 | // Update the player list |
482 | 486 | g_PlayerAssignments = message.hosts; |
| 487 | |
| 488 | // Assign the host player to the previously selected slot. |
| 489 | if (g_HostPlayerSlot > 0) |
| 490 | { |
| 491 | g_GameAttributes.settings.PlayerData[g_HostPlayerSlot].AI = g_AIs[0].id; |
| 492 | updateGameAttributes(); |
| 493 | swapPlayers(Object.keys(g_PlayerAssignments)[0], g_HostPlayerSlot); |
| 494 | g_HostPlayerSlot = -1; |
| 495 | } |
| 496 | |
483 | 497 | updatePlayerList(); |
484 | 498 | if (g_PlayerAssignments[newPlayer] && g_PlayerAssignments[newPlayer].player != -1) |
485 | 499 | resetReady = true; |
… |
… |
function loadGameAttributes()
|
717 | 731 | mapSettings.Seed = Math.floor(Math.random() * 65536); |
718 | 732 | mapSettings.AISeed = Math.floor(Math.random() * 65536); |
719 | 733 | |
| 734 | var aiCodes = [ ai.id for each (ai in g_AIs) ]; |
| 735 | var civListCodes = [ civ.Code for each (civ in g_CivData) if (civ.SelectableInGameSetup !== false) ]; |
| 736 | civListCodes.push("random"); |
| 737 | |
| 738 | g_HostPlayerSlot = -1; |
| 739 | var playerData = mapSettings.PlayerData; |
| 740 | if (playerData) |
| 741 | { |
| 742 | for (var i = 0; i < playerData.length; ++i) |
| 743 | { |
| 744 | // Discard previously unassigned/player slots |
| 745 | if (aiCodes.indexOf(playerData[i].AI) < 0) |
| 746 | playerData[i].AI = aiCodes[0]; |
| 747 | |
| 748 | if (playerData[i].isHostPlayer) |
| 749 | { |
| 750 | g_HostPlayerSlot = i; |
| 751 | playerData[i].isHostPlayer = undefined; |
| 752 | } |
| 753 | |
| 754 | // Validate player civs. |
| 755 | if (civListCodes.indexOf(playerData[i].Civ) <0) |
| 756 | playerData[i].Civ = "random"; |
| 757 | } |
| 758 | } |
| 759 | |
720 | 760 | // TODO: Check new attributes for being semantically correct. |
721 | 761 | g_GameAttributes = attrs; |
722 | 762 | |
… |
… |
function loadGameAttributes()
|
745 | 785 | g_IsInGuiUpdate = false; |
746 | 786 | |
747 | 787 | onGameAttributesChange(); |
| 788 | |
| 789 | // Assign the host player to the previously selected slot. |
| 790 | if (g_HostPlayerSlot > 0 && !g_IsNetworked) |
| 791 | { |
| 792 | Engine.GetGUIObjectByName("playerAssignment["+g_HostPlayerSlot+"]").selected = 0; |
| 793 | g_HostPlayerSlot = -1; |
| 794 | } |
| 795 | // If it's a networked game, assign the host player slot as soon as the first player data arrives in handleNetMessage() |
748 | 796 | } |
749 | 797 | |
750 | 798 | function saveGameAttributes() |
751 | 799 | { |
752 | | var attributes = Engine.ConfigDB_GetValue("user", "persistmatchsettings") == "true" ? g_GameAttributes : {}; |
| 800 | var attributes = {}; |
| 801 | if(Engine.ConfigDB_GetValue("user", "persistmatchsettings") == "true") |
| 802 | { |
| 803 | attributes = g_GameAttributes; |
| 804 | |
| 805 | // Assign a flag that determines the first real player |
| 806 | if (g_PlayerAssignments) |
| 807 | { |
| 808 | var hostGuid = Object.keys(g_PlayerAssignments)[0]; |
| 809 | var hostPlayerIndex = g_PlayerAssignments[hostGuid].player - 1; |
| 810 | |
| 811 | if (hostPlayerIndex >= 0 && attributes.settings.PlayerData.length > hostPlayerIndex) |
| 812 | attributes.settings.PlayerData[hostPlayerIndex].isHostPlayer=true; |
| 813 | } |
| 814 | } |
| 815 | |
753 | 816 | Engine.WriteJSONFile(g_IsNetworked ? FILEPATH_MATCHSETTINGS_MP : FILEPATH_MATCHSETTINGS_SP, attributes); |
754 | 817 | } |
755 | 818 | //////////////////////////////////////////////////////////////////////////////////////////////// |