Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/session.js
Show First 20 Lines • Show All 1,461 Lines • ▼ Show 20 Lines | function reportGame() | ||||
let resourcesCounterTypes = [ | let resourcesCounterTypes = [ | ||||
"resourcesGathered", | "resourcesGathered", | ||||
"resourcesUsed", | "resourcesUsed", | ||||
"resourcesSold", | "resourcesSold", | ||||
"resourcesBought" | "resourcesBought" | ||||
]; | ]; | ||||
let misc = [ | |||||
"tradeIncome", | |||||
"tributesSent", | |||||
"tributesReceived", | |||||
"treasuresCollected", | |||||
"lootCollected", | |||||
"percentMapExplored" | |||||
]; | |||||
let playerStatistics = {}; | let playerStatistics = {}; | ||||
// Unit Stats | // Unit Stats | ||||
for (let unitCounterType of unitsCountersTypes) | for (let unitCounterType of unitsCountersTypes) | ||||
{ | { | ||||
if (!playerStatistics[unitCounterType]) | if (!playerStatistics[unitCounterType]) | ||||
playerStatistics[unitCounterType] = { }; | playerStatistics[unitCounterType] = { }; | ||||
for (let unitsClass of unitsClasses) | for (let unitsClass of unitsClasses) | ||||
Show All 18 Lines | function reportGame() | ||||
{ | { | ||||
if (!playerStatistics[resourcesCounterType]) | if (!playerStatistics[resourcesCounterType]) | ||||
playerStatistics[resourcesCounterType] = { }; | playerStatistics[resourcesCounterType] = { }; | ||||
for (let resourcesType of resourcesTypes) | for (let resourcesType of resourcesTypes) | ||||
playerStatistics[resourcesCounterType][resourcesType] = ""; | playerStatistics[resourcesCounterType][resourcesType] = ""; | ||||
} | } | ||||
playerStatistics.resourcesGathered.vegetarianFood = ""; | playerStatistics.resourcesGathered.vegetarianFood = ""; | ||||
playerStatistics.tradeIncome = ""; | for (let type of misc) | ||||
// Tribute | playerStatistics[type] = ""; | ||||
playerStatistics.tributesSent = ""; | |||||
playerStatistics.tributesReceived = ""; | |||||
// Total | // Total | ||||
playerStatistics.economyScore = ""; | playerStatistics.economyScore = ""; | ||||
playerStatistics.militaryScore = ""; | playerStatistics.militaryScore = ""; | ||||
playerStatistics.totalScore = ""; | playerStatistics.totalScore = ""; | ||||
// Various | |||||
playerStatistics.treasuresCollected = ""; | |||||
playerStatistics.lootCollected = ""; | |||||
playerStatistics.feminisation = ""; | |||||
playerStatistics.percentMapExplored = ""; | |||||
let mapName = g_GameAttributes.settings.Name; | let mapName = g_GameAttributes.settings.Name; | ||||
let playerStates = ""; | let playerStates = ""; | ||||
let playerCivs = ""; | let playerCivs = ""; | ||||
let teams = ""; | let teams = ""; | ||||
let teamsLocked = true; | let teamsLocked = true; | ||||
// Serialize the statistics for each player into a comma-separated list. | // Serialize the statistics for each player into a comma-separated list. | ||||
// Ignore gaia | // Ignore gaia | ||||
for (let i = 1; i < extendedSimState.players.length; ++i) | for (let i = 1; i < extendedSimState.players.length; ++i) | ||||
{ | { | ||||
let player = extendedSimState.players[i]; | let player = extendedSimState.players[i]; | ||||
let maxIndex = player.sequences.time.length - 1; | |||||
playerStates += player.state + ","; | playerStates += player.state + ","; | ||||
playerCivs += player.civ + ","; | playerCivs += player.civ + ","; | ||||
teams += player.team + ","; | teams += player.team + ","; | ||||
teamsLocked = teamsLocked && player.teamsLocked; | teamsLocked = teamsLocked && player.teamsLocked; | ||||
for (let resourcesCounterType of resourcesCounterTypes) | for (let resourcesCounterType of resourcesCounterTypes) | ||||
for (let resourcesType of resourcesTypes) | for (let resourcesType of resourcesTypes) | ||||
playerStatistics[resourcesCounterType][resourcesType] += player.statistics[resourcesCounterType][resourcesType] + ","; | playerStatistics[resourcesCounterType][resourcesType] += player.sequences[resourcesCounterType][resourcesType][maxIndex] + ","; | ||||
playerStatistics.resourcesGathered.vegetarianFood += player.statistics.resourcesGathered.vegetarianFood + ","; | playerStatistics.resourcesGathered.vegetarianFood += player.sequences.resourcesGathered.vegetarianFood[maxIndex] + ","; | ||||
for (let unitCounterType of unitsCountersTypes) | for (let unitCounterType of unitsCountersTypes) | ||||
for (let unitsClass of unitsClasses) | for (let unitsClass of unitsClasses) | ||||
playerStatistics[unitCounterType][unitsClass] += player.statistics[unitCounterType][unitsClass] + ","; | playerStatistics[unitCounterType][unitsClass] += player.sequences[unitCounterType][unitsClass][maxIndex] + ","; | ||||
for (let buildingCounterType of buildingsCountersTypes) | for (let buildingCounterType of buildingsCountersTypes) | ||||
for (let buildingsClass of buildingsClasses) | for (let buildingsClass of buildingsClasses) | ||||
playerStatistics[buildingCounterType][buildingsClass] += player.statistics[buildingCounterType][buildingsClass] + ","; | playerStatistics[buildingCounterType][buildingsClass] += player.sequences[buildingCounterType][buildingsClass][maxIndex] + ","; | ||||
let total = 0; | let total = 0; | ||||
for (let type in player.statistics.resourcesGathered) | for (let type in player.sequences.resourcesGathered) | ||||
total += player.statistics.resourcesGathered[type]; | total += player.sequences.resourcesGathered[type][maxIndex]; | ||||
playerStatistics.economyScore += total + ","; | playerStatistics.economyScore += total + ","; | ||||
playerStatistics.militaryScore += Math.round((player.statistics.enemyUnitsKilledValue + | playerStatistics.militaryScore += Math.round((player.sequences.enemyUnitsKilledValue[maxIndex] + | ||||
player.statistics.enemyBuildingsDestroyedValue) / 10) + ","; | player.sequences.enemyBuildingsDestroyedValue[maxIndex]) / 10) + ","; | ||||
playerStatistics.totalScore += (total + Math.round((player.statistics.enemyUnitsKilledValue + | playerStatistics.totalScore += (total + Math.round((player.sequences.enemyUnitsKilledValue[maxIndex] + | ||||
player.statistics.enemyBuildingsDestroyedValue) / 10)) + ","; | player.sequences.enemyBuildingsDestroyedValue[maxIndex]) / 10)) + ","; | ||||
playerStatistics.tradeIncome += player.statistics.tradeIncome + ","; | |||||
playerStatistics.tributesSent += player.statistics.tributesSent + ","; | for (let type of misc) | ||||
playerStatistics.tributesReceived += player.statistics.tributesReceived + ","; | playerStatistics[type] += player.sequences[type][maxIndex] + ","; | ||||
playerStatistics.percentMapExplored += player.statistics.percentMapExplored + ","; | |||||
playerStatistics.treasuresCollected += player.statistics.treasuresCollected + ","; | |||||
playerStatistics.lootCollected += player.statistics.lootCollected + ","; | |||||
} | } | ||||
// Send the report with serialized data | // Send the report with serialized data | ||||
let reportObject = {}; | let reportObject = {}; | ||||
reportObject.timeElapsed = extendedSimState.timeElapsed; | reportObject.timeElapsed = extendedSimState.timeElapsed; | ||||
reportObject.playerStates = playerStates; | reportObject.playerStates = playerStates; | ||||
reportObject.playerID = Engine.GetPlayerID(); | reportObject.playerID = Engine.GetPlayerID(); | ||||
reportObject.matchID = g_GameAttributes.matchID; | reportObject.matchID = g_GameAttributes.matchID; | ||||
Show All 21 Lines | for (let type of unitsClasses) | ||||
reportObject["enemy"+type+"UnitsKilled"] = playerStatistics.enemyUnitsKilled[type]; | reportObject["enemy"+type+"UnitsKilled"] = playerStatistics.enemyUnitsKilled[type]; | ||||
} | } | ||||
for (let type of buildingsClasses) | for (let type of buildingsClasses) | ||||
{ | { | ||||
reportObject[(type.substr(0,1)).toLowerCase()+type.substr(1)+"BuildingsConstructed"] = playerStatistics.buildingsConstructed[type]; | reportObject[(type.substr(0,1)).toLowerCase()+type.substr(1)+"BuildingsConstructed"] = playerStatistics.buildingsConstructed[type]; | ||||
reportObject[(type.substr(0,1)).toLowerCase()+type.substr(1)+"BuildingsLost"] = playerStatistics.buildingsLost[type]; | reportObject[(type.substr(0,1)).toLowerCase()+type.substr(1)+"BuildingsLost"] = playerStatistics.buildingsLost[type]; | ||||
reportObject["enemy"+type+"BuildingsDestroyed"] = playerStatistics.enemyBuildingsDestroyed[type]; | reportObject["enemy"+type+"BuildingsDestroyed"] = playerStatistics.enemyBuildingsDestroyed[type]; | ||||
} | } | ||||
reportObject.tributesSent = playerStatistics.tributesSent; | for (let type of misc) | ||||
reportObject.tributesReceived = playerStatistics.tributesReceived; | reportObject[type] = playerStatistics[type]; | ||||
reportObject.percentMapExplored = playerStatistics.percentMapExplored; | |||||
reportObject.treasuresCollected = playerStatistics.treasuresCollected; | |||||
reportObject.lootCollected = playerStatistics.lootCollected; | |||||
reportObject.tradeIncome = playerStatistics.tradeIncome; | |||||
Engine.SendGameReport(reportObject); | Engine.SendGameReport(reportObject); | ||||
} | } |
Wildfire Games · Phabricator