Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js
Show First 20 Lines • Show All 949 Lines • ▼ Show 20 Lines | var g_PlayerMiscElements = { | ||||
"playerColor": { | "playerColor": { | ||||
"sprite": (playerIdx) => "color:" + rgbToGuiColor(g_GameAttributes.settings.PlayerData[playerIdx].Color) + " 100", | "sprite": (playerIdx) => "color:" + rgbToGuiColor(g_GameAttributes.settings.PlayerData[playerIdx].Color) + " 100", | ||||
}, | }, | ||||
"playerConfig": { | "playerConfig": { | ||||
"hidden": (playerIdx) => !g_GameAttributes.settings.PlayerData[playerIdx].AI, | "hidden": (playerIdx) => !g_GameAttributes.settings.PlayerData[playerIdx].AI, | ||||
"onPress": (playerIdx) => function() { | "onPress": (playerIdx) => function() { | ||||
openAIConfig(playerIdx); | openAIConfig(playerIdx); | ||||
}, | }, | ||||
"tooltip": (playerIdx) => sprintf(translate("Configure AI: %(name)s - %(difficulty)s."), { | "tooltip": (playerIdx) => sprintf(translate("Configure AI: %(difficulty)s %(behavior)s %(name)s."), { | ||||
"name": translateAIName(g_GameAttributes.settings.PlayerData[playerIdx].AI), | "name": translateAIName(g_GameAttributes.settings.PlayerData[playerIdx].AI), | ||||
"difficulty": translateAIDifficulty(g_GameAttributes.settings.PlayerData[playerIdx].AIDiff) | "difficulty": translateAIDifficulty(g_GameAttributes.settings.PlayerData[playerIdx].AIDiff), | ||||
"behavior": translateAIBehavior(g_GameAttributes.settings.PlayerData[playerIdx].AIBehavior), | |||||
}), | }), | ||||
}, | }, | ||||
}; | }; | ||||
/** | /** | ||||
* Initializes some globals without touching the GUI. | * Initializes some globals without touching the GUI. | ||||
* | * | ||||
* @param {Object} attribs - context data sent by the lobby / mainmenu | * @param {Object} attribs - context data sent by the lobby / mainmenu | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function initDefaults() | function initDefaults() | ||||
{ | { | ||||
// Remove gaia from both arrays | // Remove gaia from both arrays | ||||
g_DefaultPlayerData = clone(g_Settings.PlayerDefaults.slice(1)); | g_DefaultPlayerData = clone(g_Settings.PlayerDefaults.slice(1)); | ||||
let aiDifficulty = +Engine.ConfigDB_GetValue("user", "gui.gamesetup.aidifficulty"); | let aiDifficulty = +Engine.ConfigDB_GetValue("user", "gui.gamesetup.aidifficulty"); | ||||
let aiBehavior = Engine.ConfigDB_GetValue("user", "gui.gamesetup.aibehavior"); | |||||
// Don't change the underlying defaults file, as Atlas uses that file too | // Don't change the underlying defaults file, as Atlas uses that file too | ||||
for (let i in g_DefaultPlayerData) | for (let i in g_DefaultPlayerData) | ||||
{ | { | ||||
g_DefaultPlayerData[i].Civ = "random"; | g_DefaultPlayerData[i].Civ = "random"; | ||||
g_DefaultPlayerData[i].Team = -1; | g_DefaultPlayerData[i].Team = -1; | ||||
g_DefaultPlayerData[i].AIDiff = aiDifficulty; | g_DefaultPlayerData[i].AIDiff = aiDifficulty; | ||||
g_DefaultPlayerData[i].AIBehavior = aiBehavior; | |||||
} | } | ||||
deepfreeze(g_DefaultPlayerData); | deepfreeze(g_DefaultPlayerData); | ||||
} | } | ||||
/** | /** | ||||
* Sets default values for all g_GameAttribute settings which don't have a value set. | * Sets default values for all g_GameAttribute settings which don't have a value set. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 885 Lines • ▼ Show 20 Lines | for (let i in g_GameAttributes.settings.PlayerData) | ||||
let chosenCiv = g_GameAttributes.settings.PlayerData[i].Civ || "random"; | let chosenCiv = g_GameAttributes.settings.PlayerData[i].Civ || "random"; | ||||
if (chosenCiv == "random") | if (chosenCiv == "random") | ||||
{ | { | ||||
let culture = pickRandom(cultures); | let culture = pickRandom(cultures); | ||||
chosenCiv = pickRandom(Object.keys(g_CivData).filter(civ => g_CivData[civ].Culture == culture)); | chosenCiv = pickRandom(Object.keys(g_CivData).filter(civ => g_CivData[civ].Culture == culture)); | ||||
} | } | ||||
g_GameAttributes.settings.PlayerData[i].Civ = chosenCiv; | g_GameAttributes.settings.PlayerData[i].Civ = chosenCiv; | ||||
// Pick one of the available botnames for the chosen civ | // Pick a random behavior and one of the available botnames for the chosen civ | ||||
if (g_GameAttributes.mapType === "scenario" || !g_GameAttributes.settings.PlayerData[i].AI) | if (g_GameAttributes.mapType === "scenario" || !g_GameAttributes.settings.PlayerData[i].AI) | ||||
continue; | continue; | ||||
if (g_GameAttributes.settings.PlayerData[i].AIBehavior == "random") | |||||
g_GameAttributes.settings.PlayerData[i].AIBehavior = pickRandom(g_Settings.AIBehaviors).Name; | |||||
let chosenName = pickRandom(g_CivData[chosenCiv].AINames); | let chosenName = pickRandom(g_CivData[chosenCiv].AINames); | ||||
if (!g_IsNetworked) | if (!g_IsNetworked) | ||||
chosenName = translate(chosenName); | chosenName = translate(chosenName); | ||||
// Count how many players use the chosenName | // Count how many players use the chosenName | ||||
let usedName = g_GameAttributes.settings.PlayerData.filter(pData => pData.Name && pData.Name.indexOf(chosenName) !== -1).length; | let usedName = g_GameAttributes.settings.PlayerData.filter(pData => pData.Name && pData.Name.indexOf(chosenName) !== -1).length; | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
g_LastViewedAIPlayer = playerSlot; | g_LastViewedAIPlayer = playerSlot; | ||||
Engine.PushGuiPage("page_aiconfig.xml", { | Engine.PushGuiPage("page_aiconfig.xml", { | ||||
"callback": "AIConfigCallback", | "callback": "AIConfigCallback", | ||||
"isController": g_IsController, | "isController": g_IsController, | ||||
"playerSlot": playerSlot, | "playerSlot": playerSlot, | ||||
"id": g_GameAttributes.settings.PlayerData[playerSlot].AI, | "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, | ||||
"difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff | "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff, | ||||
"behavior": g_GameAttributes.settings.PlayerData[playerSlot].AIBehavior | |||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Called after closing the dialog. | * Called after closing the dialog. | ||||
*/ | */ | ||||
function AIConfigCallback(ai) | function AIConfigCallback(ai) | ||||
{ | { | ||||
g_LastViewedAIPlayer = -1; | g_LastViewedAIPlayer = -1; | ||||
if (!ai.save || !g_IsController) | if (!ai.save || !g_IsController) | ||||
return; | return; | ||||
g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id; | g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id; | ||||
g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty; | g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty; | ||||
g_GameAttributes.settings.PlayerData[ai.playerSlot].AIBehavior = ai.behavior; | |||||
updateGameAttributes(); | updateGameAttributes(); | ||||
} | } | ||||
function reloadPlayerAssignmentChoices() | function reloadPlayerAssignmentChoices() | ||||
{ | { | ||||
let playerChoices = sortGUIDsByPlayerID().map(guid => ({ | let playerChoices = sortGUIDsByPlayerID().map(guid => ({ | ||||
"Choice": "guid:" + guid, | "Choice": "guid:" + guid, | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | for (let guid in g_PlayerAssignments) | ||||
else | else | ||||
g_PlayerAssignments[guid].player = playerID; | g_PlayerAssignments[guid].player = playerID; | ||||
break; | break; | ||||
} | } | ||||
// Transfer the AI from the target slot to the current slot. | // 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].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 - 1].AIDiff = g_GameAttributes.settings.PlayerData[newSlot].AIDiff; | ||||
g_GameAttributes.settings.PlayerData[playerID - 1].AIBehavior = g_GameAttributes.settings.PlayerData[newSlot].AIBehavior; | |||||
// Swap civilizations and colors if they aren't fixed | // Swap civilizations and colors if they aren't fixed | ||||
if (g_GameAttributes.mapType != "scenario") | if (g_GameAttributes.mapType != "scenario") | ||||
{ | { | ||||
[g_GameAttributes.settings.PlayerData[playerID - 1].Civ, g_GameAttributes.settings.PlayerData[newSlot].Civ] = | [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[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[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[newSlot].Color, g_GameAttributes.settings.PlayerData[playerID - 1].Color]; | ||||
▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator