Changeset View
Standalone View
binaries/data/mods/public/gui/summary/counters.js
var g_TeamHelperData = []; | var g_TeamHelperData = []; | ||||
function resetDataHelpers() | function resetDataHelpers() | ||||
{ | { | ||||
g_TeamHelperData = []; | g_TeamHelperData = []; | ||||
} | } | ||||
function formatTrained(trained, killed, lost) | function calculatePercent(divident, divisor) | ||||
{ | { | ||||
return g_TrainedColor + trained + '[/color] / ' + | return { "percent": divisor ? Math.floor(100 * divident / divisor) : 0 }; | ||||
bb: Looks strange to return an object here, but correct seeing code below. | |||||
Not Done Inline Actions(Agree with bb, but maybe this is a must have in summary screen land) elexis: (Agree with bb, but maybe this is a must have in summary screen land) | |||||
g_KilledColor + killed + '[/color] / ' + | |||||
g_LostColor + lost + '[/color]'; | |||||
} | } | ||||
function formatCaptured(constructed, destroyed, captured, lost) | function calculateRatio(divident, divisor) | ||||
{ | { | ||||
return g_TrainedColor + constructed + '[/color] / ' + | return divident ? Math.round(divident / divisor * 100) / 100 : 0; | ||||
Not Done Inline ActionsInfinity walked out of range? bb: Infinity walked out of range? | |||||
Not Done Inline ActionsInfinity will just be Infinity and the graph code has to manage displaying Infinity Imarok: Infinity will just be `Infinity` and the graph code has to manage displaying `Infinity` | |||||
Done Inline Actions.toFixed? elexis: .toFixed? | |||||
Not Done Inline Actionsthx elexis: thx | |||||
g_KilledColor + destroyed + '[/color]\n' + | |||||
g_CapturedColor + captured + '[/color] / ' + | |||||
g_LostColor + lost + '[/color]\n'; | |||||
} | } | ||||
function formatIncome(income, outcome) | function formatValue(values) | ||||
Not Done Inline ActionsShould find a more specific name to prevent name collisions elexis: Should find a more specific name to prevent name collisions | |||||
{ | { | ||||
return g_IncomeColor + income + '[/color] / ' + | if (typeof values != "object") | ||||
g_OutcomeColor + outcome + '[/color]'; | return values === Infinity ? g_InfinitySymbol : values; | ||||
Done Inline Actionsg_InfinitySymbol or g_Infinity elexis: g_InfinitySymbol or g_Infinity | |||||
Done Inline ActionsAh, right, that name was there already. So either revert or rename all occurances. elexis: Ah, right, that name was there already. So either revert or rename all occurances. | |||||
Not Done Inline ActionsThis still looks broken. g_InfinitySymbol refered to, but g_InfiniteSymbol defined. Consult jshint. elexis: This still looks broken. `g_InfinitySymbol` refered to, but `g_InfiniteSymbol` defined. Consult… | |||||
Not Done Inline Actions:O true... Imarok: :O true... | |||||
} | |||||
function formatPercent(divident, divisor) | let ret = ""; | ||||
for (let type in values) | |||||
{ | { | ||||
Not Done Inline ActionsWhat is this thing actually? A postfix? A delimiter? elexis: What is this thing actually? A postfix? A delimiter? | |||||
if (!divisor) | let color = g_SummaryColors[type]; | ||||
return "0%"; | switch (type) | ||||
Done Inline Actionswhitespace? bb: whitespace? | |||||
Not Done Inline ActionsThe data in this switch statement needs to be kept in sync with the other 2 arrays. g_Bla = { "key": { "color":" "...", "title:" "...", "postfix": "%" }, .... }; This should still use a sprintf once the summary screen doesn't parse GUI strings anymore to query data. elexis: The data in this switch statement needs to be kept in sync with the other 2 arrays.
It is… | |||||
return Math.floor(100 * divident / divisor) + "%"; | |||||
} | |||||
function formatRatio(divident, divisor) | |||||
{ | { | ||||
if (!divident) | case "percent": | ||||
Not Done Inline ActionsI guess default color is used bb: I guess default color is used | |||||
return "0.00"; | ret += values[type] + "%"; | ||||
break; | |||||
if (!divisor) | case "constructed": | ||||
return g_InfiniteSymbol; | case "trained": | ||||
case "captured": | |||||
return Math.round(divident / divisor * 100) / 100; | case "gathered": | ||||
case "sent": | |||||
case "bought": | |||||
case "income": | |||||
Not Done Inline ActionsCan't this become infinity for some reason (in a mod)? It might look odd indeed an infinity income/outcome, but perhaps support that anyhow. bb: Can't this become infinity for some reason (in a mod)? It might look odd indeed an infinity… | |||||
Not Done Inline ActionsWhen someone changes the code, so that some of the values can be Infinity, he has to change the code here, so that it works. Imarok: When someone changes the code, so that some of the values can be Infinity, he has to change the… | |||||
ret += color + values[type] + '[/color] / '; | |||||
Not Done Inline Actionsstring concatenation is something which should be considered impossible in JS (if you don't know what I'm hinting at, ask) elexis: string concatenation is something which should be considered impossible in JS (if you don't… | |||||
break; | |||||
case "destroyed": | |||||
case "killed": | |||||
case "lost": | |||||
case "used": | |||||
case "received": | |||||
case "sold": | |||||
case "outcome": | |||||
ret += color + values[type] + '[/color]\n'; | |||||
break; | |||||
} | |||||
} | |||||
return ret; | |||||
} | } | ||||
/** | /** | ||||
* Remove color tags, whitespace, + and % to read numerical values from the GUI objects. | * Remove color tags, whitespace, + and % to read numerical values from the GUI objects. | ||||
* Remove \n only when removeLineFeed == true | * Remove \n only when removeLineFeed == true | ||||
* TODO: access the data directly instead of this ugly hack. | * TODO: access the data directly instead of this ugly hack. | ||||
*/ | */ | ||||
function cleanGUICaption(team, player, counter, removeLineFeed = true) | function cleanGUICaption(team, player, counter, removeLineFeed = true) | ||||
{ | { | ||||
let caption = Engine.GetGUIObjectByName("valueDataTeam[" + team + "][" + player + "][" + counter + "]").caption; | let caption = Engine.GetGUIObjectByName("valueDataTeam[" + team + "][" + player + "][" + counter + "]").caption; | ||||
if (removeLineFeed) | if (removeLineFeed) | ||||
return caption.replace(/\[([\w\' \\\"\/\=]*)\]|\+|\%|\s/g, ""); | return caption.replace(/\[([\w\' \\\"\/\=]*)\]|\+|\%|\s/g, ""); | ||||
else | else | ||||
return caption.replace(/\[([\w\' \\\"\/\=]*)\]|[\t\r \f]/g, ""); | return caption.replace(/\[([\w\' \\\"\/\=]*)\]|[\t\r \f]/g, ""); | ||||
} | } | ||||
function updateCountersPlayer(playerState, counters, idGUI) | function updateCountersPlayer(playerState, counters, headings, idGUI) | ||||
{ | { | ||||
let index = playerState.sequences.time.length - 1; | |||||
for (let w in counters) | for (let w in counters) | ||||
{ | { | ||||
let fn = counters[w].fn; | let fn = counters[w].fn; | ||||
Engine.GetGUIObjectByName(idGUI + "[" + w + "]").caption = fn && fn(playerState, w); | Engine.GetGUIObjectByName(idGUI + "[" + w + "]").caption = formatValue(fn && fn(playerState, index, headings[+w+1].identifier)); | ||||
} | } | ||||
} | } | ||||
/** | |||||
Done Inline ActionsSome JSDocs would be good for this function bb: Some JSDocs would be good for this function | |||||
* Add two arrays element-wise. So addArray({1,2},{7,42}) will result in {8,44}. | |||||
Done Inline Actions{} are objects, not arrays elexis: {} are objects, not arrays | |||||
Done Inline Actionsman, true :D Imarok: man, true :D | |||||
Done Inline ActionsAdd whitespaces in the arrays. bb: Add whitespaces in the arrays. | |||||
* | |||||
* @param {Array} array1 - first summand. | |||||
* @param {Array} array2 - second summand. | |||||
Done Inline ActionsComments should only be added if they state something that isn't self-evident, so explain or remove elexis: Comments should only be added if they state something that isn't self-evident, so explain or… | |||||
Not Done Inline ActionsA summand is a number, not an array. Since you already explained how it works above, not sure about the @params. elexis: A summand is a number, not an array. Since you already explained how it works above, not sure… | |||||
Not Done Inline ActionsIt doesn't really hurt. More comments are better than too less Imarok: It doesn't really hurt. More comments are better than too less | |||||
* @returns {Array} the element-wise sum of array1 and array2. | |||||
*/ | |||||
Done Inline Actionsadd periods bb: add periods | |||||
function addArray(array1, array2) | |||||
Not Done Inline ActionsSince that function is used in only one function, perhaps we can make this ugliness a local variable of that function elexis: Since that function is used in only one function, perhaps we can make this ugliness a local… | |||||
Not Done Inline ActionsMay be used in other functions in the future life of counters.js Imarok: May be used in other functions in the future life of counters.js | |||||
{ | |||||
array1 = array1.map((value, index) => value + array2[index]); | |||||
} | |||||
// Updates g_TeamHelperData by appending some data from playerState | // Updates g_TeamHelperData by appending some data from playerState | ||||
function calculateTeamCounters(playerState) | function calculateTeamCounters(playerState) | ||||
{ | { | ||||
if (!g_TeamHelperData[playerState.team]) | if (!g_TeamHelperData[playerState.team]) | ||||
g_TeamHelperData[playerState.team] = { | { | ||||
"food": 0, | g_TeamHelperData[playerState.team] = {}; | ||||
"vegetarianFood": 0, | for (let value of ["food", "vegetarianFood", "femaleCitizen", "worker", "enemyUnitsKilled", | ||||
"femaleCitizen": 0, | "unitsLost", "percentMapControlled", "peakPercentMapControlled", | ||||
"worker": 0, | "percentMapExplored", "totalBought", "totalSold"]) | ||||
Not Done Inline Actionsshouldn't we have a global for this array? bb: shouldn't we have a global for this array? | |||||
Not Done Inline Actionswhy that? Imarok: why that?
afaics its only used once | |||||
Not Done Inline Actionssounds weird that there is food but not the other types elexis: sounds weird that there is food but not the other types | |||||
Not Done Inline ActionsThat could be part of that same one global array that contains all our manifest data elexis: That could be part of that same one global array that contains all our manifest data | |||||
Not Done Inline ActionsTeam counters will be refactored in another patch Imarok: Team counters will be refactored in another patch | |||||
"enemyUnitsKilled": 0, | g_TeamHelperData[playerState.team][value] = new Array(playerState.sequences.time.length).fill(0); | ||||
"unitsLost": 0, | } | ||||
"percentMapControlled": 0, | |||||
"peakPercentMapControlled": 0, | |||||
"percentMapExplored": 0, | |||||
"totalBought": 0, | |||||
"totalSold": 0 | |||||
}; | |||||
g_TeamHelperData[playerState.team].food += playerState.statistics.resourcesGathered.food; | addArray(g_TeamHelperData[playerState.team].food, playerState.sequences.resourcesGathered.food); | ||||
g_TeamHelperData[playerState.team].vegetarianFood += playerState.statistics.resourcesGathered.vegetarianFood; | addArray(g_TeamHelperData[playerState.team].vegetarianFood, playerState.sequences.resourcesGathered.vegetarianFood); | ||||
g_TeamHelperData[playerState.team].femaleCitizen += playerState.statistics.unitsTrained.FemaleCitizen; | addArray(g_TeamHelperData[playerState.team].femaleCitizen, playerState.sequences.unitsTrained.FemaleCitizen); | ||||
g_TeamHelperData[playerState.team].worker += playerState.statistics.unitsTrained.Worker; | addArray(g_TeamHelperData[playerState.team].worker, playerState.sequences.unitsTrained.Worker); | ||||
g_TeamHelperData[playerState.team].enemyUnitsKilled += playerState.statistics.enemyUnitsKilled.total; | addArray(g_TeamHelperData[playerState.team].enemyUnitsKilled, playerState.sequences.enemyUnitsKilled.total); | ||||
g_TeamHelperData[playerState.team].unitsLost += playerState.statistics.unitsLost.total; | addArray(g_TeamHelperData[playerState.team].unitsLost, playerState.sequences.unitsLost.total); | ||||
g_TeamHelperData[playerState.team].percentMapControlled = playerState.statistics.teamPercentMapControlled; | g_TeamHelperData[playerState.team].percentMapControlled = playerState.sequences.teamPercentMapControlled; | ||||
g_TeamHelperData[playerState.team].peakPercentMapControlled = playerState.statistics.teamPeakPercentMapControlled; | g_TeamHelperData[playerState.team].peakPercentMapControlled = playerState.sequences.teamPeakPercentMapControlled; | ||||
g_TeamHelperData[playerState.team].percentMapExplored = playerState.statistics.teamPercentMapExplored; | g_TeamHelperData[playerState.team].percentMapExplored = playerState.sequences.teamPercentMapExplored; | ||||
for (let type in playerState.statistics.resourcesBought) | for (let type in playerState.sequences.resourcesBought) | ||||
g_TeamHelperData[playerState.team].totalBought += playerState.statistics.resourcesBought[type]; | addArray(g_TeamHelperData[playerState.team].totalBought, playerState.sequences.resourcesBought[type]); | ||||
for (let type in playerState.statistics.resourcesSold) | for (let type in playerState.sequences.resourcesSold) | ||||
g_TeamHelperData[playerState.team].totalSold += playerState.statistics.resourcesSold[type]; | addArray(g_TeamHelperData[playerState.team].totalSold, playerState.sequences.resourcesSold[type]); | ||||
} | } | ||||
function calculateEconomyScore(playerState) | function calculateEconomyScore(playerState, index) | ||||
{ | { | ||||
let total = 0; | let total = 0; | ||||
for (let type in playerState.statistics.resourcesGathered) | for (let type in playerState.sequences.resourcesGathered) | ||||
total += playerState.statistics.resourcesGathered[type]; | total += playerState.sequences.resourcesGathered[type][index]; | ||||
return Math.round(total / 10); | return Math.round(total / 10); | ||||
} | } | ||||
function calculateMilitaryScore(playerState) | function calculateMilitaryScore(playerState, index) | ||||
{ | { | ||||
return Math.round((playerState.statistics.enemyUnitsKilledValue + | return Math.round((playerState.sequences.enemyUnitsKilledValue[index] + | ||||
playerState.statistics.enemyBuildingsDestroyedValue + | playerState.sequences.enemyBuildingsDestroyedValue[index] + | ||||
playerState.statistics.buildingsCapturedValue) / 10); | playerState.sequences.buildingsCapturedValue[index]) / 10); | ||||
} | } | ||||
function calculateExplorationScore(playerState) | function calculateExplorationScore(playerState, index) | ||||
{ | { | ||||
return playerState.statistics.percentMapExplored * 10; | return playerState.sequences.percentMapExplored[index] * 10; | ||||
} | } | ||||
function calculateScoreTotal(playerState) | function calculateScoreTotal(playerState, index) | ||||
{ | { | ||||
return calculateEconomyScore(playerState) + | return calculateEconomyScore(playerState, index) + | ||||
calculateMilitaryScore(playerState) + | calculateMilitaryScore(playerState, index) + | ||||
calculateExplorationScore(playerState); | calculateExplorationScore(playerState, index); | ||||
} | } | ||||
function calculateScoreTeam(counters) | function calculateScoreTeam(counters, index) | ||||
{ | { | ||||
for (let t in g_Teams) | for (let t in g_Teams) | ||||
{ | { | ||||
if (t == -1) | if (t == -1) | ||||
continue; | continue; | ||||
let teamTotalScore = 0; | let teamTotalScore = 0; | ||||
for (let w in counters) | for (let w in counters) | ||||
{ | { | ||||
let total = 0; | let total = 0; | ||||
if (w == 2) // Team exploration score (not additive) | if (w == 2) // Team exploration score (not additive) | ||||
total = g_TeamHelperData[t].percentMapExplored * 10; | total = g_TeamHelperData[t].percentMapExplored[index] * 10; | ||||
else | else | ||||
for (let p = 0; p < g_Teams[t]; ++p) | for (let p = 0; p < g_Teams[t]; ++p) | ||||
total += +Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]").caption; | total += +Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]").caption; | ||||
if (w < 3) | if (w < 3) | ||||
{ | { | ||||
teamTotalScore += total; | teamTotalScore += total; | ||||
Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = total; | Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = total; | ||||
} | } | ||||
else | else | ||||
Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotalScore; | Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotalScore; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
function calculateBuildings(playerState, position) | function calculateBuildings(playerState, index, type) | ||||
{ | { | ||||
let type = g_BuildingsTypes[position]; | return { | ||||
return formatCaptured( | "constructed": playerState.sequences.buildingsConstructed[type][index], | ||||
playerState.statistics.buildingsConstructed[type], | "destroyed": playerState.sequences.enemyBuildingsDestroyed[type][index], | ||||
playerState.statistics.enemyBuildingsDestroyed[type], | "captured": playerState.sequences.buildingsCaptured[type][index], | ||||
playerState.statistics.buildingsCaptured[type], | "lost": playerState.sequences.buildingsLost[type][index] | ||||
playerState.statistics.buildingsLost[type]); | }; | ||||
} | } | ||||
function calculateBuildingsTeam(counters) | function calculateBuildingsTeam(counters, index) | ||||
{ | { | ||||
for (let t in g_Teams) | for (let t in g_Teams) | ||||
{ | { | ||||
if (t == -1) | if (t == -1) | ||||
continue; | continue; | ||||
for (let w in counters) | for (let w in counters) | ||||
{ | { | ||||
Show All 12 Lines | for (let w in counters) | ||||
total.constructed += +first[0]; | total.constructed += +first[0]; | ||||
total.destroyed += +first[1]; | total.destroyed += +first[1]; | ||||
total.captured += +second[0]; | total.captured += +second[0]; | ||||
total.lost += +second[1]; | total.lost += +second[1]; | ||||
} | } | ||||
Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = | Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = | ||||
formatCaptured(total.constructed, total.destroyed, total.captured, total.lost); | formatValue(total); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
function calculateUnitsTeam(counters) | function calculateUnitsTeam(counters, index) | ||||
Done Inline Actionsindex argument unused, since value is obtained by a hack, lholding it seems ok for consistency bb: index argument unused, since value is obtained by a hack, lholding it seems ok for consistency | |||||
{ | { | ||||
for (let t in g_Teams) | for (let t in g_Teams) | ||||
{ | { | ||||
if (t == -1) | if (t == -1) | ||||
continue; | continue; | ||||
for (let w in counters) | for (let w in counters) | ||||
{ | { | ||||
let total = | let total = | ||||
{ | { | ||||
"trained": 0, | "trained": 0, | ||||
"killed": 0, | "killed": 0, | ||||
"captured" : 0, | "captured" : 0, | ||||
"lost": 0 | "lost": 0 | ||||
}; | }; | ||||
for (let p = 0; p < g_Teams[t]; ++p) | for (let p = 0; p < g_Teams[t]; ++p) | ||||
{ | { | ||||
if (w == 0 || w == 6) | |||||
{ | |||||
let splitCaption = cleanGUICaption(t, p, w, false).split("\n"); | let splitCaption = cleanGUICaption(t, p, w, false).split("\n"); | ||||
let first = splitCaption[0].split("/"); | let first = splitCaption[0].split("/"); | ||||
let second = splitCaption[1].split("/"); | |||||
total.trained += +first[0]; | total.trained += +first[0]; | ||||
total.killed += +first[1]; | total.killed += +first[1]; | ||||
if (w == 0 || w == 6) | |||||
{ | |||||
let second = splitCaption[1].split("/"); | |||||
total.captured += +second[0]; | total.captured += +second[0]; | ||||
total.lost += +second[1]; | total.lost += +second[1]; | ||||
} | } | ||||
else | else | ||||
{ | total.lost += +splitCaption[1]; | ||||
let splitCaption = cleanGUICaption(t, p, w).split("/"); | |||||
Not Done Inline Actionsthe split seems to be different here bb: the split seems to be different here | |||||
total.trained += +splitCaption[0]; | |||||
total.killed += +splitCaption[1]; | |||||
total.lost += +splitCaption[2]; | |||||
} | |||||
} | } | ||||
let formattedCaption = ""; | if (w != 0 && w != 6) | ||||
delete total.captured; | |||||
Not Done Inline Actionsonce upon a time on trac, there was a wip diff replacing those odd numbers with string checks elexis: once upon a time on trac, there was a wip diff replacing those odd numbers with string checks | |||||
Not Done Inline ActionsThis is not part of this patch. Imarok: This is not part of this patch.
(I plan to do a cleanup patch for that afterwards.) | |||||
Not Done Inline Actions(Hm, can't find the ticket) elexis: (Hm, can't find the ticket) | |||||
if (w == 0 || w == 6) | |||||
formattedCaption = formatCaptured(total.trained, total.killed, total.captured, total.lost); | |||||
else | |||||
formattedCaption = formatTrained(total.trained, total.killed, total.lost); | |||||
Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = formattedCaption; | Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = formatValue(total); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
function calculateUnitsWithCaptured(playerState, position) | function calculateUnitsWithCaptured(playerState, index, type) | ||||
{ | { | ||||
let type = g_UnitsTypes[position]; | return { | ||||
"trained": playerState.sequences.unitsTrained[type][index], | |||||
return formatCaptured( | "killed": playerState.sequences.enemyUnitsKilled[type][index], | ||||
playerState.statistics.unitsTrained[type], | "captured": playerState.sequences.unitsCaptured[type][index], | ||||
playerState.statistics.enemyUnitsKilled[type], | "lost": playerState.sequences.unitsLost[type][index] | ||||
playerState.statistics.unitsCaptured[type], | }; | ||||
playerState.statistics.unitsLost[type]); | |||||
} | } | ||||
function calculateUnits(playerState, position) | function calculateUnits(playerState, index, type) | ||||
{ | { | ||||
let type = g_UnitsTypes[position]; | return { | ||||
"trained": playerState.sequences.unitsTrained[type][index], | |||||
return formatTrained( | "killed": playerState.sequences.enemyUnitsKilled[type][index], | ||||
playerState.statistics.unitsTrained[type], | "lost": playerState.sequences.unitsLost[type][index] | ||||
playerState.statistics.enemyUnitsKilled[type], | }; | ||||
playerState.statistics.unitsLost[type]); | |||||
} | } | ||||
function calculateResources(playerState, position) | function calculateResources(playerState, index, type) | ||||
{ | { | ||||
let type = g_ResourceData.GetCodes()[position]; | return { | ||||
"gathered": playerState.sequences.resourcesGathered[type][index], | |||||
return formatIncome( | "used": playerState.sequences.resourcesUsed[type][index] - playerState.sequences.resourcesSold[type][index] | ||||
playerState.statistics.resourcesGathered[type], | }; | ||||
playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]); | |||||
} | } | ||||
function calculateTotalResources(playerState) | function calculateTotalResources(playerState, index) | ||||
{ | { | ||||
let totalGathered = 0; | let totalGathered = 0; | ||||
let totalUsed = 0; | let totalUsed = 0; | ||||
for (let type of g_ResourceData.GetCodes()) | for (let type of g_ResourceData.GetCodes()) | ||||
{ | { | ||||
totalGathered += playerState.statistics.resourcesGathered[type]; | totalGathered += playerState.sequences.resourcesGathered[type][index]; | ||||
totalUsed += playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]; | totalUsed += playerState.sequences.resourcesUsed[type][index] - playerState.sequences.resourcesSold[type][index]; | ||||
} | } | ||||
return formatIncome(totalGathered, totalUsed); | return { "gathered": totalGathered, "used": totalUsed }; | ||||
} | } | ||||
function calculateTreasureCollected(playerState) | function calculateTreasureCollected(playerState, index) | ||||
{ | { | ||||
return playerState.statistics.treasuresCollected; | return playerState.sequences.treasuresCollected[index]; | ||||
} | } | ||||
function calculateLootCollected(playerState) | function calculateLootCollected(playerState, index) | ||||
{ | { | ||||
return playerState.statistics.lootCollected; | return playerState.sequences.lootCollected[index]; | ||||
} | } | ||||
function calculateTributeSent(playerState) | function calculateTributeSent(playerState, index) | ||||
{ | { | ||||
return formatIncome( | return { | ||||
playerState.statistics.tributesSent, | "sent": playerState.sequences.tributesSent[index], | ||||
playerState.statistics.tributesReceived); | "received": playerState.sequences.tributesReceived[index] | ||||
}; | |||||
Done Inline Actionssemicolomn bb: semicolomn | |||||
} | } | ||||
function calculateResourcesTeam(counters) | function calculateResourcesTeam(counters, index) | ||||
{ | { | ||||
for (let t in g_Teams) | for (let t in g_Teams) | ||||
{ | { | ||||
if (t == -1) | if (t == -1) | ||||
continue; | continue; | ||||
for (let w in counters) | for (let w in counters) | ||||
{ | { | ||||
Show All 15 Lines | for (let w in counters) | ||||
total.income += +splitCaption[0]; | total.income += +splitCaption[0]; | ||||
total.outcome += +splitCaption[1]; | total.outcome += +splitCaption[1]; | ||||
} | } | ||||
} | } | ||||
let teamTotal; | let teamTotal; | ||||
if (w >= 6) | if (w >= 6) | ||||
teamTotal = total.income; | teamTotal = total.income; | ||||
else if (w == 5) | |||||
teamTotal = { "sent": total.income, "received": total.outcome }; | |||||
else | else | ||||
teamTotal = formatIncome(total.income, total.outcome); | teamTotal = { "gathered": total.income, "used": total.outcome }; | ||||
Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal; | Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = formatValue(teamTotal); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
function calculateResourceExchanged(playerState, position) | function calculateResourceExchanged(playerState, index, type) | ||||
{ | { | ||||
let type = g_ResourceData.GetCodes()[position]; | return { | ||||
"bought": playerState.sequences.resourcesBought[type][index], | |||||
return formatIncome( | "sold": playerState.sequences.resourcesSold[type][index] | ||||
playerState.statistics.resourcesBought[type], | }; | ||||
playerState.statistics.resourcesSold[type]); | |||||
} | } | ||||
function calculateBarterEfficiency(playerState) | function calculateBarterEfficiency(playerState, index) | ||||
{ | { | ||||
let totalBought = 0; | let totalBought = 0; | ||||
let totalSold = 0; | let totalSold = 0; | ||||
for (let type in playerState.statistics.resourcesBought) | for (let type in playerState.sequences.resourcesBought) | ||||
totalBought += playerState.statistics.resourcesBought[type]; | totalBought += playerState.sequences.resourcesBought[type][index]; | ||||
for (let type in playerState.statistics.resourcesSold) | for (let type in playerState.sequences.resourcesSold) | ||||
totalSold += playerState.statistics.resourcesSold[type]; | totalSold += playerState.sequences.resourcesSold[type][index]; | ||||
return formatPercent(totalBought, totalSold); | return calculatePercent(totalBought, totalSold); | ||||
} | } | ||||
function calculateTradeIncome(playerState) | function calculateTradeIncome(playerState, index) | ||||
{ | { | ||||
return playerState.statistics.tradeIncome; | return playerState.sequences.tradeIncome[index]; | ||||
} | } | ||||
function calculateMarketTeam(counters) | function calculateMarketTeam(counters, index) | ||||
{ | { | ||||
for (let t in g_Teams) | for (let t in g_Teams) | ||||
{ | { | ||||
if (t == -1) | if (t == -1) | ||||
continue; | continue; | ||||
for (let w in counters) | for (let w in counters) | ||||
{ | { | ||||
Show All 13 Lines | for (let w in counters) | ||||
let splitCaption = caption.split("/"); | let splitCaption = caption.split("/"); | ||||
total.income += +splitCaption[0]; | total.income += +splitCaption[0]; | ||||
total.outcome += +splitCaption[1]; | total.outcome += +splitCaption[1]; | ||||
} | } | ||||
} | } | ||||
let teamTotal; | let teamTotal; | ||||
if (w == 4) | if (w == 4) | ||||
teamTotal = formatPercent(g_TeamHelperData[t].totalBought, g_TeamHelperData[t].totalSold); | teamTotal = calculatePercent(g_TeamHelperData[t].totalBought[index], g_TeamHelperData[t].totalSold[index]); | ||||
else if (w > 4) | else if (w > 4) | ||||
teamTotal = total.income; | teamTotal = total.income; | ||||
else | else | ||||
teamTotal = formatIncome(total.income, total.outcome); | teamTotal = total; | ||||
Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal; | Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = formatValue(teamTotal); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
function calculateVegetarianRatio(playerState) | function calculateVegetarianRatio(playerState, index) | ||||
{ | { | ||||
return formatPercent( | return calculatePercent( | ||||
playerState.statistics.resourcesGathered.vegetarianFood, | playerState.sequences.resourcesGathered.vegetarianFood[index], | ||||
playerState.statistics.resourcesGathered.food); | playerState.sequences.resourcesGathered.food[index]); | ||||
} | } | ||||
function calculateFeminization(playerState) | function calculateFeminization(playerState, index) | ||||
{ | { | ||||
return formatPercent( | return calculatePercent( | ||||
playerState.statistics.unitsTrained.FemaleCitizen, | playerState.sequences.unitsTrained.FemaleCitizen[index], | ||||
playerState.statistics.unitsTrained.Worker); | playerState.sequences.unitsTrained.Worker[index]); | ||||
} | } | ||||
function calculateKillDeathRatio(playerState) | function calculateKillDeathRatio(playerState, index) | ||||
{ | { | ||||
return formatRatio( | return calculateRatio( | ||||
playerState.statistics.enemyUnitsKilled.total, | playerState.sequences.enemyUnitsKilled.total[index], | ||||
playerState.statistics.unitsLost.total); | playerState.sequences.unitsLost.total[index]); | ||||
} | } | ||||
function calculateMapExploration(playerState) | function calculateMapExploration(playerState, index) | ||||
{ | { | ||||
return playerState.statistics.percentMapExplored + "%"; | return { "percent": playerState.sequences.percentMapExplored[index] }; | ||||
} | } | ||||
function calculateMapFinalControl(playerState) | function calculateMapFinalControl(playerState, index) | ||||
{ | { | ||||
return playerState.statistics.percentMapControlled + "%"; | return { "percent": playerState.sequences.percentMapControlled[index] }; | ||||
} | } | ||||
function calculateMapPeakControl(playerState) | function calculateMapPeakControl(playerState, index) | ||||
{ | { | ||||
return playerState.statistics.peakPercentMapControlled + "%"; | return { "percent": playerState.sequences.peakPercentMapControlled[index] }; | ||||
} | } | ||||
function calculateMiscellaneous(counters) | function calculateMiscellaneousTeam(counters, index) | ||||
{ | { | ||||
for (let t in g_Teams) | for (let t in g_Teams) | ||||
{ | { | ||||
if (t == -1) | if (t == -1) | ||||
continue; | continue; | ||||
for (let w in counters) | for (let w in counters) | ||||
{ | { | ||||
let teamTotal; | let teamTotal; | ||||
if (w == 0) | if (w == 0) | ||||
teamTotal = formatPercent(g_TeamHelperData[t].vegetarianFood, g_TeamHelperData[t].food); | teamTotal = calculatePercent(g_TeamHelperData[t].vegetarianFood[index], g_TeamHelperData[t].food[index]); | ||||
else if (w == 1) | else if (w == 1) | ||||
teamTotal = formatPercent(g_TeamHelperData[t].femaleCitizen, g_TeamHelperData[t].worker); | teamTotal = calculatePercent(g_TeamHelperData[t].femaleCitizen[index], g_TeamHelperData[t].worker[index]); | ||||
else if (w == 2) | else if (w == 2) | ||||
teamTotal = formatRatio(g_TeamHelperData[t].enemyUnitsKilled, g_TeamHelperData[t].unitsLost); | teamTotal = calculateRatio(g_TeamHelperData[t].enemyUnitsKilled[index], g_TeamHelperData[t].unitsLost[index]); | ||||
else if (w == 3) | else if (w == 3) | ||||
teamTotal = g_TeamHelperData[t].percentMapExplored + "%"; | teamTotal = { "percent": g_TeamHelperData[t].percentMapExplored[index] }; | ||||
Done Inline ActionscalculatePercent? elexis: calculatePercent? | |||||
Not Done Inline ActionsNope, as the value already is given as percent. Imarok: Nope, as the value already is given as percent. | |||||
else if (w == 4) | else if (w == 4) | ||||
teamTotal = g_TeamHelperData[t].peakPercentMapControlled + "%"; | teamTotal = { "percent": g_TeamHelperData[t].peakPercentMapControlled[index] }; | ||||
else if (w == 5) | else if (w == 5) | ||||
teamTotal = g_TeamHelperData[t].percentMapControlled + "%"; | teamTotal = { "percent": g_TeamHelperData[t].percentMapControlled[index] }; | ||||
Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal; | Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = formatValue(teamTotal); | ||||
} | } | ||||
} | } | ||||
} | } |
Looks strange to return an object here, but correct seeing code below.