Index: binaries/data/mods/public/gui/gamesetup/gamesetup.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -429,7 +429,7 @@ if (g_GameAttributes.mapType != "scenario") g_GameAttributes.settings = { - "PlayerData": g_DefaultPlayerData.slice(0, 4) + "PlayerData": g_DefaultPlayerData.slice(0, 5) //What's that slice for? and why ,4) }; reloadMapFilterList(); @@ -484,12 +484,12 @@ "tooltip": (hoverIdx) => translate("Select number of players."), "labels": () => g_NumPlayersList, "ids": () => g_NumPlayersList, - "default": () => g_MaxPlayers - 1, + "default": () => 0, // This is not working, see the splice of PlayerDefaults above which sets the "default" "defined": () => g_GameAttributes.settings.PlayerData !== undefined, - "get": () => g_GameAttributes.settings.PlayerData.length, + "get": () => g_GameAttributes.settings.PlayerData.length-1, "enabled": () => g_GameAttributes.mapType == "random", "select": (idx) => { - let num = idx + 1; + let num = idx + 2; let pData = g_GameAttributes.settings.PlayerData; g_GameAttributes.settings.PlayerData = num > pData.length ? @@ -504,7 +504,7 @@ "tooltip": (hoverIdx) => { let popCap = g_PopulationCapacities.Population[hoverIdx]; - let players = g_GameAttributes.settings.PlayerData.length; + let players = g_GameAttributes.settings.PlayerData.length-1; if (hoverIdx == -1 || popCap * players <= g_PopulationCapacityRecommendation) return translate("Select population limit."); @@ -627,14 +627,14 @@ "colors": (idx) => g_PlayerAssignmentList.Color || [], "ids": (idx) => g_PlayerAssignmentList.Choice || [], "default": (idx) => "ai:petra", - "defined": (idx) => idx < g_GameAttributes.settings.PlayerData.length, + "defined": (idx) => idx < g_GameAttributes.settings.PlayerData.length-1, "get": (idx) => { for (let guid in g_PlayerAssignments) if (g_PlayerAssignments[guid].player == idx + 1) return "guid:" + guid; for (let ai of g_Settings.AIDescriptions) - if (g_GameAttributes.settings.PlayerData[idx].AI == ai.id) + if (g_GameAttributes.settings.PlayerData[idx+1].AI == ai.id) return "ai:" + ai.id; return "unassigned"; @@ -649,10 +649,10 @@ else if (g_PlayerAssignments.local.player == idx+1) g_PlayerAssignments.local.player = -1; - g_GameAttributes.settings.PlayerData[idx].AI = choice.startsWith("ai:") ? choice.substr(3) : ""; + g_GameAttributes.settings.PlayerData[idx+1].AI = choice.startsWith("ai:") ? choice.substr(3) : ""; } else - swapPlayers(choice.substr("guid:".length), idx); + swapPlayers(choice.substr("guid:".length), idx+1); }, "autocomplete": 100, }, @@ -660,10 +660,10 @@ "labels": (idx) => g_PlayerTeamList.label, "ids": (idx) => g_PlayerTeamList.id, "default": (idx) => 0, - "defined": (idx) => g_GameAttributes.settings.PlayerData[idx].Team !== undefined, - "get": (idx) => g_GameAttributes.settings.PlayerData[idx].Team, + "defined": (idx) => g_GameAttributes.settings.PlayerData[idx+1].Team !== undefined, + "get": (idx) => g_GameAttributes.settings.PlayerData[idx+1].Team, "select": (selectedIdx, idx) => { - g_GameAttributes.settings.PlayerData[idx].Team = selectedIdx - 1; + g_GameAttributes.settings.PlayerData[idx+1].Team = selectedIdx - 1; }, "enabled": () => g_GameAttributes.mapType != "scenario", }, @@ -673,10 +673,10 @@ "colors": (idx) => g_PlayerCivList.color, "ids": (idx) => g_PlayerCivList.code, "default": (idx) => 0, - "defined": (idx) => g_GameAttributes.settings.PlayerData[idx].Civ !== undefined, - "get": (idx) => g_GameAttributes.settings.PlayerData[idx].Civ, + "defined": (idx) => g_GameAttributes.settings.PlayerData[idx+1].Civ !== undefined, + "get": (idx) => g_GameAttributes.settings.PlayerData[idx+1].Civ, "select": (selectedIdx, idx) => { - g_GameAttributes.settings.PlayerData[idx].Civ = g_PlayerCivList.code[selectedIdx]; + g_GameAttributes.settings.PlayerData[idx+1].Civ = g_PlayerCivList.code[selectedIdx]; }, "enabled": () => g_GameAttributes.mapType != "scenario", "autocomplete": 0, @@ -686,17 +686,18 @@ "colors": (idx) => g_PlayerColorPickerList.map(color => rgbToGuiColor(color)), "ids": (idx) => g_PlayerColorPickerList.map((color, index) => index), "default": (idx) => idx, - "defined": (idx) => g_GameAttributes.settings.PlayerData[idx].Color !== undefined, - "get": (idx) => g_PlayerColorPickerList.indexOf(g_GameAttributes.settings.PlayerData[idx].Color), + "defined": (idx) => g_GameAttributes.settings.PlayerData[idx+1].Color !== undefined, + "get": (idx) => g_PlayerColorPickerList.indexOf(g_GameAttributes.settings.PlayerData[idx+1].Color), "select": (selectedIdx, idx) => { +// TODO make this ignore gaia again, instead of handling it like all others let playerData = g_GameAttributes.settings.PlayerData; // If someone else has that color, give that player the old color let pData = playerData.find(pData => sameColor(g_PlayerColorPickerList[selectedIdx], pData.Color)); if (pData) - pData.Color = playerData[idx].Color; + pData.Color = playerData[idx+1].Color; - playerData[idx].Color = g_PlayerColorPickerList[selectedIdx]; + playerData[idx+1].Color = g_PlayerColorPickerList[selectedIdx]; ensureUniquePlayerColors(playerData); }, "enabled": () => g_GameAttributes.mapType != "scenario", @@ -894,12 +895,12 @@ }, "playerName": { "caption": (idx) => { - let pData = g_GameAttributes.settings.PlayerData[idx]; + let pData = g_GameAttributes.settings.PlayerData[idx+1]; let assignedGUID = Object.keys(g_PlayerAssignments).find( guid => g_PlayerAssignments[guid].player == idx + 1); - let name = translate(pData.Name || g_DefaultPlayerData[idx].Name); + let name = translate(pData.Name || g_DefaultPlayerData[idx+1].Name); if (g_IsNetworked) name = @@ -911,10 +912,10 @@ }, }, "playerColor": { - "sprite": (idx) => "color:" + rgbToGuiColor(g_GameAttributes.settings.PlayerData[idx].Color) + " 100", + "sprite": (idx) => "color:" + rgbToGuiColor(g_GameAttributes.settings.PlayerData[idx+1].Color) + " 100", }, "playerConfig": { - "hidden": (idx) => !g_GameAttributes.settings.PlayerData[idx].AI, + "hidden": (idx) => !g_GameAttributes.settings.PlayerData[idx+1].AI, "onPress": (idx) => function() { openAIConfig(idx); }, @@ -971,13 +972,15 @@ function initDefaults() { - // Remove gaia from both arrays g_DefaultPlayerData = g_Settings.PlayerDefaults; - g_DefaultPlayerData.shift(); // Don't change the underlying defaults file, as Atlas uses that file too + +// TODO ignore gaia again (or just add setting that are hidden and keep them this way for (let i in g_DefaultPlayerData) { +if (i == 0) + continue; g_DefaultPlayerData[i].Civ = "random"; g_DefaultPlayerData[i].Team = -1; } @@ -997,7 +1000,8 @@ g_Checkboxes[checkbox].set(g_Checkboxes[checkbox].default()); for (let dropdown in g_PlayerDropdowns) - for (let i = 0; i < g_GameAttributes.settings.PlayerData.length; ++i) + // TODO this sounds strange, should maybe just do -1 here and do +1 in a few other places? + for (let i = 0; i < g_GameAttributes.settings.PlayerData.length-1; ++i) if (!isControlArrayElementHidden(i) && !g_PlayerDropdowns[dropdown].defined(i)) g_PlayerDropdowns[dropdown].select(g_PlayerDropdowns[dropdown].default(i), i); } @@ -1315,8 +1319,9 @@ return; } +// TODO ignore gaia let freeSlot = g_GameAttributes.settings.PlayerData.findIndex((v,i) => - Object.keys(g_PlayerAssignments).every(guid => g_PlayerAssignments[guid].player != i+1) + i!=0 && Object.keys(g_PlayerAssignments).every(guid => g_PlayerAssignments[guid].player != i) ); // Client is not and cannot become assigned as player @@ -1325,7 +1330,7 @@ // Assign the joining client to the free slot if (g_IsController && !isRejoiningPlayer) - Engine.AssignNetworkPlayer(freeSlot + 1, newGUID); + Engine.AssignNetworkPlayer(freeSlot, newGUID); resetReadyData(); } @@ -1484,8 +1489,9 @@ let playerData = mapSettings.PlayerData; if (playerData && g_GameAttributes.mapType != "scenario") for (let i in playerData) - if (!g_CivData[playerData[i].Civ] || !g_CivData[playerData[i].Civ].SelectableInGameSetup) - playerData[i].Civ = "random"; + if (i != 0) + if (!g_CivData[playerData[i].Civ] || !g_CivData[playerData[i].Civ].SelectableInGameSetup) + playerData[i].Civ = "random"; // Apply map settings let newMapData = loadMapData(mapName); @@ -1522,17 +1528,15 @@ function sanitizePlayerData(playerData) { - // Remove gaia - if (playerData.length && !playerData[0]) - playerData.shift(); - playerData.forEach((pData, index) => { - // Use defaults if the map doesn't specify a value for (let prop in g_DefaultPlayerData[index]) if (!(prop in pData)) pData[prop] = g_DefaultPlayerData[index][prop]; + if (index == 0) + return; + // Replace colors with the best matching color of PlayerDefaults if (g_GameAttributes.mapType != "scenario") { @@ -1542,7 +1546,7 @@ } // If there is a player in that slot, then there can't be an AI - if (Object.keys(g_PlayerAssignments).some(guid => g_PlayerAssignments[guid].player == index + 1)) + if (Object.keys(g_PlayerAssignments).some(guid => g_PlayerAssignments[guid].player == index)) pData.AI = ""; }); @@ -1669,13 +1673,13 @@ for (let prop in mapSettings) g_GameAttributes.settings[prop] = mapSettings[prop]; - unassignInvalidPlayers(g_GameAttributes.settings.PlayerData.length); + unassignInvalidPlayers(g_GameAttributes.settings.PlayerData.length); // TODO? supplementDefaults(); } function isControlArrayElementHidden(idx) { - return idx !== undefined && idx >= g_GameAttributes.settings.PlayerData.length; + return idx !== undefined && idx+1 >= g_GameAttributes.settings.PlayerData.length; } /** @@ -1804,6 +1808,9 @@ // Determine random civs and botnames for (let i in g_GameAttributes.settings.PlayerData) { + if (i == 0) + continue; + // Pick a random civ of a random culture let chosenCiv = g_GameAttributes.settings.PlayerData[i].Civ || "random"; if (chosenCiv == "random") @@ -1833,7 +1840,7 @@ { let player = g_PlayerAssignments[guid]; if (player.player > 0) // not observer or GAIA - g_GameAttributes.settings.PlayerData[player.player - 1].Name = player.name; + g_GameAttributes.settings.PlayerData[player.player].Name = player.name; } // Seed used for both map generation and simulation @@ -1843,6 +1850,8 @@ // Used for identifying rated game reports for the lobby g_GameAttributes.matchID = Engine.GetMatchID(); +warn(uneval(g_GameAttributes)); + if (g_IsNetworked) { Engine.SetNetworkGameAttributes(g_GameAttributes); @@ -1854,9 +1863,11 @@ let playerID = -1; for (let i in g_GameAttributes.settings.PlayerData) { - let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); + if (i == 0) + continue; + let assignBox = Engine.GetGUIObjectByName("playerAssignment["+(i-1)+"]"); if (assignBox.list_data[assignBox.selected] == "guid:local") - playerID = +i+1; + playerID = +i; } Engine.StartGame(g_GameAttributes, playerID); @@ -1987,8 +1998,8 @@ "callback": "AIConfigCallback", "isController": g_IsController, "playerSlot": playerSlot, - "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, - "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff + "id": g_GameAttributes.settings.PlayerData[playerSlot+1].AI, + "difficulty": g_GameAttributes.settings.PlayerData[playerSlot+1].AIDiff }); } @@ -2002,8 +2013,8 @@ if (!ai.save || !g_IsController) return; - g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id; - g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty; + g_GameAttributes.settings.PlayerData[ai.playerSlot+1].AI = ai.id; + g_GameAttributes.settings.PlayerData[ai.playerSlot+1].AIDiff = ai.difficulty; updateGameAttributes(); } @@ -2039,8 +2050,8 @@ function swapPlayers(guid, newSlot) { - // Player slots are indexed from 0 as Gaia is omitted. - let newPlayerID = newSlot + 1; + // Player slots are indexed from 0 as Gaia is omitted. // TODO not valid anymore + let newPlayerID = newSlot; // TODO just rename one let playerID = g_PlayerAssignments[guid].player; // Attempt to swap the player or AI occupying the target slot, @@ -2061,16 +2072,16 @@ } // Transfer the AI from the target slot to the current slot. - g_GameAttributes.settings.PlayerData[playerID - 1].AI = g_GameAttributes.settings.PlayerData[newSlot].AI; - g_GameAttributes.settings.PlayerData[playerID - 1].AIDiff = g_GameAttributes.settings.PlayerData[newSlot].AIDiff; + g_GameAttributes.settings.PlayerData[playerID].AI = g_GameAttributes.settings.PlayerData[newSlot].AI; + g_GameAttributes.settings.PlayerData[playerID].AIDiff = g_GameAttributes.settings.PlayerData[newSlot].AIDiff; // Swap civilizations and colors if they aren't fixed if (g_GameAttributes.mapType != "scenario") { - [g_GameAttributes.settings.PlayerData[playerID - 1].Civ, g_GameAttributes.settings.PlayerData[newSlot].Civ] = - [g_GameAttributes.settings.PlayerData[newSlot].Civ, g_GameAttributes.settings.PlayerData[playerID - 1].Civ]; - [g_GameAttributes.settings.PlayerData[playerID - 1].Color, g_GameAttributes.settings.PlayerData[newSlot].Color] = - [g_GameAttributes.settings.PlayerData[newSlot].Color, g_GameAttributes.settings.PlayerData[playerID - 1].Color]; + [g_GameAttributes.settings.PlayerData[playerID].Civ, g_GameAttributes.settings.PlayerData[newSlot].Civ] = + [g_GameAttributes.settings.PlayerData[newSlot].Civ, g_GameAttributes.settings.PlayerData[playerID].Civ]; + [g_GameAttributes.settings.PlayerData[playerID].Color, g_GameAttributes.settings.PlayerData[newSlot].Color] = + [g_GameAttributes.settings.PlayerData[newSlot].Color, g_GameAttributes.settings.PlayerData[playerID].Color]; } } @@ -2117,7 +2128,7 @@ let color = g_ColorRegular; if (playerID > 0) { - color = g_GameAttributes.settings.PlayerData[playerID - 1].Color; + color = g_GameAttributes.settings.PlayerData[playerID].Color; // Enlighten playercolor to improve readability let [h, s, l] = rgbToHsl(color.r, color.g, color.b); @@ -2171,7 +2182,8 @@ function resetCivilizations() { for (let i in g_GameAttributes.settings.PlayerData) - g_GameAttributes.settings.PlayerData[i].Civ = "random"; + if (i != 0) + g_GameAttributes.settings.PlayerData[i].Civ = "random"; updateGameAttributes(); } @@ -2179,7 +2191,8 @@ function resetTeams() { for (let i in g_GameAttributes.settings.PlayerData) - g_GameAttributes.settings.PlayerData[i].Team = -1; + if (i != 0) + g_GameAttributes.settings.PlayerData[i].Team = -1; updateGameAttributes(); } @@ -2237,7 +2250,7 @@ { let pData = { "Name": g_PlayerAssignments[guid].name }; - if (g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1]) + if (g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player]) ++connectedPlayers; else pData.Team = "observer"; @@ -2277,7 +2290,7 @@ "mapType": g_GameAttributes.mapType, "victoryCondition": g_GameAttributes.settings.GameType, "nbp": clients.connectedPlayers, - "maxnbp": g_GameAttributes.settings.PlayerData.length, + "maxnbp": g_GameAttributes.settings.PlayerData.length-1, "players": clients.list, "stunIP": g_StunEndpoint ? g_StunEndpoint.ip : "", "stunPort": g_StunEndpoint ? g_StunEndpoint.port : "", Index: binaries/data/mods/public/maps/skirmishes/Acropolis Bay (2).xml =================================================================== --- binaries/data/mods/public/maps/skirmishes/Acropolis Bay (2).xml +++ binaries/data/mods/public/maps/skirmishes/Acropolis Bay (2).xml @@ -46,11 +46,10 @@ "Name": "Acropolis Bay (2)", "PlayerData": [ { - "Name": "Player 1" + "Civ": "gaia" }, - { - "Name": "Player 2" - } + {}, + {} ], "Preview": "acropolis_bay.png", "RevealMap": false Index: binaries/data/mods/public/simulation/helpers/Player.js =================================================================== --- binaries/data/mods/public/simulation/helpers/Player.js +++ binaries/data/mods/public/simulation/helpers/Player.js @@ -18,9 +18,11 @@ if (!(rawData && rawData.PlayerData)) throw("Player.js: Error reading player_defaults.json"); +warn(uneval(settings.PlayerData)); + // Add gaia to simplify iteration - if (settings.PlayerData && settings.PlayerData[0]) - settings.PlayerData.unshift(null); +// if (settings.PlayerData && settings.PlayerData[0]) +// settings.PlayerData.unshift(null); var playerDefaults = rawData.PlayerData; var playerData = settings.PlayerData;