Ticket #3150: summary_counters_v2.patch
File summary_counters_v2.patch, 13.5 KB (added by , 3 years ago) 


binaries/data/mods/public/gui/credits/texts/programming.json
83 83 {"nick": "h20", "name": "Daniel Wilhelm"}, 84 84 {"nick": "historic_bruno", "name": "Ben Brian"}, 85 85 {"nick": "idanwin"}, 86 {"nick": "Imarok", "name": "J. S."}, 86 87 {"nick": "infyquest", "name": "Vijay Kiran Kamuju"}, 87 88 {"nick": "IronNerd", "name": "Matthew McMullan"}, 88 89 {"nick": "Itms", "name": "Nicolas Auvray"}, 
binaries/data/mods/public/gui/summary/counters.js
1 1 // FUNCTIONS FOR CALCULATING SCORES 2 var g_Team MiscHelperData = [];2 var g_TeamHelperData = []; 3 3 4 4 function resetDataHelpers() 5 5 { 6 g_Team MiscHelperData = [];6 g_TeamHelperData = []; 7 7 } 8 8 9 9 function updateCountersPlayer(playerState, counters, idGUI) … … 15 15 } 16 16 } 17 17 18 function calculateEconomyScore(playerState, position) 18 // Calculates the data for the team counters that can only got via payerState 19 // and saves it to g_TeamHelperData 20 function calculateTeamCounters(playerState) 19 21 { 22 if (!g_TeamHelperData[playerState.team]) 23 g_TeamHelperData[playerState.team] = { 24 "food": 0, 25 "vegetarianFood": 0, 26 "female": 0, 27 "worker": 0, 28 "enemyUnitsKilled": 0, 29 "unitsLost": 0, 30 "percentMapControlled": 0, 31 "peakPercentMapControlled": 0, 32 "percentMapExplored": 0, 33 "totalBought": 0, 34 "totalSold": 0 35 }; 36 37 g_TeamHelperData[playerState.team].food += playerState.statistics.resourcesGathered.food; 38 g_TeamHelperData[playerState.team].vegetarianFood += playerState.statistics.resourcesGathered.vegetarianFood; 39 40 g_TeamHelperData[playerState.team].female += playerState.statistics.unitsTrained.Female; 41 g_TeamHelperData[playerState.team].worker += playerState.statistics.unitsTrained.Worker; 42 43 g_TeamHelperData[playerState.team].enemyUnitsKilled += playerState.statistics.enemyUnitsKilled.total; 44 g_TeamHelperData[playerState.team].unitsLost += playerState.statistics.unitsLost.total; 45 46 g_TeamHelperData[playerState.team].percentMapControlled = playerState.statistics.teamPercentMapControlled; 47 g_TeamHelperData[playerState.team].peakPercentMapControlled = playerState.statistics.teamPeakPercentMapControlled; 48 49 g_TeamHelperData[playerState.team].percentMapExplored = playerState.statistics.teamPercentMapExplored; 50 51 for (let type in playerState.statistics.resourcesBought) 52 g_TeamHelperData[playerState.team].totalBought += playerState.statistics.resourcesBought[type]; 53 54 for (let type in playerState.statistics.resourcesSold) 55 g_TeamHelperData[playerState.team].totalSold += playerState.statistics.resourcesSold[type]; 56 } 57 58 function calculateEconomyScore(playerState) 59 { 20 60 let total = 0; 21 61 for (let type in playerState.statistics.resourcesGathered) 22 62 total += playerState.statistics.resourcesGathered[type]; … … 24 64 return Math.round(total / 10); 25 65 } 26 66 27 function calculateMilitaryScore(playerState , position)67 function calculateMilitaryScore(playerState) 28 68 { 29 69 return Math.round((playerState.statistics.enemyUnitsKilledValue + 30 70 playerState.statistics.enemyBuildingsDestroyedValue) / 10); 31 71 } 32 72 33 function calculateExplorationScore(playerState , position)73 function calculateExplorationScore(playerState) 34 74 { 35 75 return playerState.statistics.percentMapExplored * 10; 36 76 } 37 77 38 function calculateScoreTotal(playerState , position)78 function calculateScoreTotal(playerState) 39 79 { 40 80 return calculateEconomyScore(playerState) + 41 81 calculateMilitaryScore(playerState) + … … 49 89 if (t == 1) 50 90 continue; 51 91 92 let teamTotalScore = 0; 52 93 for (let w in counters) 53 94 { 54 95 let total = 0; 55 for (let p = 0; p < g_Teams[t]; ++p) 56 total += (+Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]").caption); 96 // w == 2 is the team exploration score 97 // The players exploration score can't be added because there might be regions both players explored 98 if (w == 2) 99 total = g_TeamHelperData[t].percentMapExplored * 10; 100 else 101 for (let p = 0; p < g_Teams[t]; ++p) 102 total += +Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]").caption; 57 103 104 if ( w != 3) 105 teamTotalScore += total; 106 else 107 total = teamTotalScore; 108 58 109 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = total; 59 110 } 60 111 } … … 119 170 g_OutcomeColor + (playerState.statistics.resourcesUsed[type]  playerState.statistics.resourcesSold[type]) + '[/color]'; 120 171 } 121 172 122 function calculateTotalResources(playerState , position)173 function calculateTotalResources(playerState) 123 174 { 124 175 let totalGathered = 0; 125 176 let totalUsed = 0; … … 133 184 return g_IncomeColor + totalGathered + '[/color] / ' + g_OutcomeColor + totalUsed + '[/color]'; 134 185 } 135 186 136 function calculateTreasureCollected(playerState , position)187 function calculateTreasureCollected(playerState) 137 188 { 138 189 return playerState.statistics.treasuresCollected; 139 190 } 140 191 141 function calculateLootCollected(playerState , position)192 function calculateLootCollected(playerState) 142 193 { 143 194 return playerState.statistics.lootCollected; 144 195 } 145 196 146 function calculateTributeSent(playerState , position)197 function calculateTributeSent(playerState) 147 198 { 148 199 return g_IncomeColor + playerState.statistics.tributesSent + "[/color] / " + 149 200 g_OutcomeColor + playerState.statistics.tributesReceived + "[/color]"; … … 192 243 } 193 244 } 194 245 195 function calculateResourceExchanged(playerState , position)246 function calculateResourceExchanged(playerState , position) 196 247 { 197 248 let type = g_ResourcesTypes[position]; 198 249 return g_IncomeColor + '+' + playerState.statistics.resourcesBought[type] + '[/color] ' + … … 199 250 g_OutcomeColor + '' + playerState.statistics.resourcesSold[type] + '[/color]'; 200 251 } 201 252 202 function calculateBa tteryEfficiency(playerState, position)253 function calculateBarterEfficiency(playerState) 203 254 { 204 255 let totalBought = 0; 205 256 let totalSold = 0; … … 213 264 return Math.floor(totalSold > 0 ? (totalBought / totalSold) * 100 : 0) + "%"; 214 265 } 215 266 216 function calculateTradeIncome(playerState , position)267 function calculateTradeIncome(playerState) 217 268 { 218 269 return playerState.statistics.tradeIncome; 219 270 } … … 250 301 } 251 302 } 252 303 253 if (w >= 4) 304 if(w == 4) 305 teamTotal = Math.floor(g_TeamHelperData[t].totalSold > 0 ? (g_TeamHelperData[t].totalBought / g_TeamHelperData[t].totalSold) * 100 : 0) + "%" 306 else if (w > 4) 254 307 teamTotal = total.i +(w == 4 ? "%" : ""); 255 308 else 256 teamTotal = g_IncomeColor + '+' + total.i + '[/color] ' + g_ IncomeColor + '' + total.o + '[/color]';309 teamTotal = g_IncomeColor + '+' + total.i + '[/color] ' + g_OutcomeColor + '' + total.o + '[/color]'; 257 310 258 311 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal; 259 312 } … … 260 313 } 261 314 } 262 315 263 function calculateVegetarianRatio(playerState , position)316 function calculateVegetarianRatio(playerState) 264 317 { 265 if (!g_TeamMiscHelperData[playerState.team])266 g_TeamMiscHelperData[playerState.team] = [];267 268 if (!g_TeamMiscHelperData[playerState.team][position])269 g_TeamMiscHelperData[playerState.team][position] = { "food": 0, "vegetarianFood": 0 };270 271 318 if (playerState.statistics.resourcesGathered.vegetarianFood && playerState.statistics.resourcesGathered.food) 272 {273 g_TeamMiscHelperData[playerState.team][position].food += playerState.statistics.resourcesGathered.food;274 g_TeamMiscHelperData[playerState.team][position].vegetarianFood += playerState.statistics.resourcesGathered.vegetarianFood;275 319 return Math.floor((playerState.statistics.resourcesGathered.vegetarianFood / playerState.statistics.resourcesGathered.food) * 100) + "%"; 276 }277 320 else 278 321 return 0 + "%"; 279 322 } 280 323 281 function calculateFeminization(playerState , position)324 function calculateFeminization(playerState) 282 325 { 283 if (!g_TeamMiscHelperData[playerState.team])284 g_TeamMiscHelperData[playerState.team] = [];285 286 if (!g_TeamMiscHelperData[playerState.team][position])287 g_TeamMiscHelperData[playerState.team][position] = { "Female": 0, "Worker": 0 };288 289 326 if (playerState.statistics.unitsTrained.Worker && playerState.statistics.unitsTrained.Female) 290 {291 g_TeamMiscHelperData[playerState.team][position].Female = playerState.statistics.unitsTrained.Female;292 g_TeamMiscHelperData[playerState.team][position].Worker = playerState.statistics.unitsTrained.Worker;293 327 return Math.floor((playerState.statistics.unitsTrained.Female / playerState.statistics.unitsTrained.Worker) * 100) + "%"; 294 }295 328 else 296 329 return 0 + "%"; 297 330 } 298 331 299 function calculateKillDeathRatio(playerState , position)332 function calculateKillDeathRatio(playerState) 300 333 { 301 if (!g_TeamMiscHelperData[playerState.team])302 g_TeamMiscHelperData[playerState.team] = [];303 304 if (!g_TeamMiscHelperData[playerState.team][position])305 g_TeamMiscHelperData[playerState.team][position] = { "enemyUnitsKilled": 0, "unitsLost": 0 };306 307 g_TeamMiscHelperData[playerState.team][position].enemyUnitsKilled = playerState.statistics.enemyUnitsKilled.total;308 g_TeamMiscHelperData[playerState.team][position].unitsLost = playerState.statistics.unitsLost.total;309 310 334 if (!playerState.statistics.enemyUnitsKilled.total) 311 335 return g_DefaultDecimal; 312 336 … … 316 340 return Math.round((playerState.statistics.enemyUnitsKilled.total / playerState.statistics.unitsLost.total)*100)/100; 317 341 } 318 342 319 function calculateMapExploration(playerState , position)343 function calculateMapExploration(playerState) 320 344 { 321 if (!g_TeamMiscHelperData[playerState.team])322 g_TeamMiscHelperData[playerState.team] = [];323 324 g_TeamMiscHelperData[playerState.team][position] = playerState.statistics.teamPercentMapExplored;325 326 345 return playerState.statistics.percentMapExplored + "%"; 327 346 } 328 347 329 function calculateMapFinalControl(playerState , position)348 function calculateMapFinalControl(playerState) 330 349 { 331 if (!g_TeamMiscHelperData[playerState.team])332 g_TeamMiscHelperData[playerState.team] = [];333 334 g_TeamMiscHelperData[playerState.team][position] = playerState.statistics.teamPercentMapControlled;335 336 350 return playerState.statistics.percentMapControlled + "%"; 337 351 } 338 352 339 function calculateMapPeakControl(playerState , position)353 function calculateMapPeakControl(playerState) 340 354 { 341 if (!g_TeamMiscHelperData[playerState.team])342 g_TeamMiscHelperData[playerState.team] = [];343 344 g_TeamMiscHelperData[playerState.team][position] = playerState.statistics.teamPeakPercentMapControlled;345 346 355 return playerState.statistics.peakPercentMapControlled + "%"; 347 356 } 348 357 … … 358 367 let teamTotal = "undefined"; 359 368 360 369 if (w == 0) 361 teamTotal = (g_Team MiscHelperData[t][w].food == 0 ? "0" : Math.floor((g_TeamMiscHelperData[t][w].vegetarianFood / g_TeamMiscHelperData[t][w].food) * 100)) + "%";370 teamTotal = (g_TeamHelperData[t].food == 0 ? "0" : Math.floor((g_TeamHelperData[t].vegetarianFood / g_TeamHelperData[t].food) * 100)) + "%"; 362 371 else if (w == 1) 363 teamTotal = (g_Team MiscHelperData[t][w].Worker == 0 ? "0" : Math.floor((g_TeamMiscHelperData[t][w].Female / g_TeamMiscHelperData[t][w].Worker) * 100)) + "%";372 teamTotal = (g_TeamHelperData[t].worker == 0 ? "0" : Math.floor((g_TeamHelperData[t].female / g_TeamHelperData[t].worker) * 100)) + "%"; 364 373 else if (w == 2) 365 374 { 366 if (!g_Team MiscHelperData[t][w].enemyUnitsKilled)375 if (!g_TeamHelperData[t].enemyUnitsKilled) 367 376 teamTotal = g_DefaultDecimal; 368 else if (!g_Team MiscHelperData[t][w].unitsLost) // and enemyUnitsKilled.total > 0377 else if (!g_TeamHelperData[t].unitsLost) // and enemyUnitsKilled.total > 0 369 378 teamTotal = g_InfiniteSymbol; // infinity symbol 370 379 else 371 teamTotal = Math.round((g_Team MiscHelperData[t][w].enemyUnitsKilled / g_TeamMiscHelperData[t][w].unitsLost) * 100) / 100;380 teamTotal = Math.round((g_TeamHelperData[t].enemyUnitsKilled / g_TeamHelperData[t].unitsLost) * 100) / 100; 372 381 } 373 else if (w >= 3) 374 teamTotal = g_TeamMiscHelperData[t][w] + "%"; 382 else if (w == 3) 383 teamTotal = g_TeamHelperData[t].percentMapExplored + "%"; 384 else if (w == 4) 385 teamTotal = g_TeamHelperData[t].percentMapControlled + "%"; 386 else if (w == 5) 387 teamTotal = g_TeamHelperData[t].peakPercentMapControlled + "%"; 375 388 376 389 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal; 377 390 } 
binaries/data/mods/public/gui/summary/layout.js
113 113 { "width": 100, "fn": calculateResourceExchanged }, 114 114 { "width": 100, "fn": calculateResourceExchanged }, 115 115 { "width": 100, "fn": calculateResourceExchanged }, 116 { "width": 100, "fn": calculateBa tteryEfficiency },116 { "width": 100, "fn": calculateBarterEfficiency }, 117 117 { "width": 100, "fn": calculateTradeIncome } 118 118 ], 119 119 "teamCounterFn": calculateMarketTeam 
binaries/data/mods/public/gui/summary/summary.js
119 119 120 120 // Update counters 121 121 updateCountersPlayer(playerState, panelInfo.counters, playerCounterValue); 122 123 // Calculate g_TeamHelperData 124 calculateTeamCounters(playerState); 122 125 } 123 126 // Update team counters 124 127 let teamCounterFn = panelInfo.teamCounterFn;