Ticket #3150: team_exploration_score_v5.3.patch

File team_exploration_score_v5.3.patch, 11.7 KB (added by Imarok, 8 years ago)

Move teamHelperData calcuations into an seperate file and fix the map exploration score. Also done some cleanup.

  • binaries/data/mods/public/gui/credits/texts/programming.json

     
    8383            {"nick": "h20", "name": "Daniel Wilhelm"},
    8484            {"nick": "historic_bruno", "name": "Ben Brian"},
    8585            {"nick": "idanwin"},
     86            {"nick": "Imarok", "name": "J. S."},
    8687            {"nick": "infyquest", "name": "Vijay Kiran Kamuju"},
    8788            {"nick": "IronNerd", "name": "Matthew McMullan"},
    8889            {"nick": "Itms", "name": "Nicolas Auvray"},
  • binaries/data/mods/public/gui/summary/counters.js

     
    11// FUNCTIONS FOR CALCULATING SCORES
    2 var g_TeamMiscHelperData = [];
     2var g_TeamHelperData = [];
    33
    44function resetDataHelpers()
    55{
    6     g_TeamMiscHelperData = [];
     6    g_TeamHelperData = [];
    77}
    88
    99function updateCountersPlayer(playerState, counters, idGUI)
     
    1515    }
    1616}
    1717
    18 function calculateEconomyScore(playerState, position)
     18function calculateTeamCounters(playerState)
    1919{
     20    if (!g_TeamHelperData[playerState.team])
     21        g_TeamHelperData[playerState.team] = {
     22            "food": 0,
     23            "vegetarianFood": 0,
     24            "female": 0,
     25            "worker": 0,
     26            "enemyUnitsKilled": 0,
     27            "unitsLost": 0,
     28            "percentMapControlled": 0,
     29            "peakPercentMapControlled": 0,
     30            "percentMapExplored": 0,
     31        };
     32
     33    g_TeamHelperData[playerState.team].food += playerState.statistics.resourcesGathered.food;
     34    g_TeamHelperData[playerState.team].vegetarianFood += playerState.statistics.resourcesGathered.vegetarianFood;
     35
     36    g_TeamHelperData[playerState.team].female = playerState.statistics.unitsTrained.Female;
     37    g_TeamHelperData[playerState.team].worker = playerState.statistics.unitsTrained.Worker;
     38
     39    g_TeamHelperData[playerState.team].enemyUnitsKilled = playerState.statistics.enemyUnitsKilled.total;
     40    g_TeamHelperData[playerState.team].unitsLost = playerState.statistics.unitsLost.total;
     41
     42    g_TeamHelperData[playerState.team].percentMapControlled = playerState.statistics.teamPercentMapControlled;
     43    g_TeamHelperData[playerState.team].peakPercentMapControlled = playerState.statistics.teamPeakPercentMapControlled;
     44
     45    g_TeamHelperData[playerState.team].percentMapExplored = playerState.statistics.teamPercentMapExplored;
     46}
     47
     48function calculateEconomyScore(playerState)
     49{
    2050    let total = 0;
    2151    for (let type in playerState.statistics.resourcesGathered)
    2252        total += playerState.statistics.resourcesGathered[type];
     
    2454    return Math.round(total / 10);
    2555}
    2656
    27 function calculateMilitaryScore(playerState, position)
     57function calculateMilitaryScore(playerState)
    2858{
    2959    return Math.round((playerState.statistics.enemyUnitsKilledValue +
    3060        playerState.statistics.enemyBuildingsDestroyedValue) / 10);
    3161}
    3262
    33 function calculateExplorationScore(playerState, position)
     63function calculateExplorationScore(playerState)
    3464{
    3565    return playerState.statistics.percentMapExplored * 10;
    3666}
    3767
    38 function calculateScoreTotal(playerState, position)
     68function calculateScoreTotal(playerState)
    3969{
    4070    return calculateEconomyScore(playerState) +
    4171        calculateMilitaryScore(playerState) +
     
    5282        for (let w in counters)
    5383        {
    5484            let total = 0;
    55             for (let p = 0; p < g_Teams[t]; ++p)
    56                 total += (+Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]").caption);
     85            // w == 2 is the team exploration score
     86            // The players exploration score can't be added because there might be regions both players explored
     87            if(w == 2) 
     88                total = g_TeamHelperData[t].percentMapExplored * 10;
     89            else
     90                for (let p = 0; p < g_Teams[t]; ++p)
     91                    total += +Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]").caption;
    5792
    5893            Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = total;
    5994        }
     
    119154        g_OutcomeColor + (playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]) + '[/color]';
    120155}
    121156
    122 function calculateTotalResources(playerState, position)
     157function calculateTotalResources(playerState)
    123158{
    124159    let totalGathered = 0;
    125160    let totalUsed = 0;
     
    133168    return g_IncomeColor + totalGathered + '[/color] / ' + g_OutcomeColor + totalUsed + '[/color]';
    134169}
    135170
    136 function calculateTreasureCollected(playerState, position)
     171function calculateTreasureCollected(playerState)
    137172{
    138173    return playerState.statistics.treasuresCollected;
    139174}
    140175
    141 function calculateLootCollected(playerState, position)
     176function calculateLootCollected(playerState)
    142177{
    143178    return playerState.statistics.lootCollected;
    144179}
    145180
    146 function calculateTributeSent(playerState, position)
     181function calculateTributeSent(playerState)
    147182{
    148183    return g_IncomeColor + playerState.statistics.tributesSent + "[/color] / " +
    149184           g_OutcomeColor + playerState.statistics.tributesReceived + "[/color]";
     
    192227    }
    193228}
    194229
    195 function calculateResourceExchanged(playerState, position)
     230function calculateResourceExchanged(playerState)
    196231{
    197232    let type = g_ResourcesTypes[position];
    198233    return g_IncomeColor + '+' + playerState.statistics.resourcesBought[type] + '[/color] ' +
     
    199234        g_OutcomeColor + '-' + playerState.statistics.resourcesSold[type] + '[/color]';
    200235}
    201236
    202 function calculateBatteryEfficiency(playerState, position)
     237function calculateBatteryEfficiency(playerState)
    203238{
    204239    let totalBought = 0;
    205240    let totalSold = 0;
     
    213248    return Math.floor(totalSold > 0 ? (totalBought / totalSold) * 100 : 0) + "%";
    214249}
    215250
    216 function calculateTradeIncome(playerState, position)
     251function calculateTradeIncome(playerState)
    217252{
    218253    return playerState.statistics.tradeIncome;
    219254}
     
    260295    }
    261296}
    262297
    263 function calculateVegetarianRatio(playerState, position)
     298function calculateVegetarianRatio(playerState)
    264299{
    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 
    271300    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;
    275301        return Math.floor((playerState.statistics.resourcesGathered.vegetarianFood / playerState.statistics.resourcesGathered.food) * 100) + "%";
    276     }
    277302    else
    278303        return 0 + "%";
    279304}
    280305
    281 function calculateFeminization(playerState, position)
     306function calculateFeminization(playerState)
    282307{
    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 
    289308    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;
    293309        return Math.floor((playerState.statistics.unitsTrained.Female / playerState.statistics.unitsTrained.Worker) * 100) + "%";
    294     }
    295310    else
    296311        return 0 + "%";
    297312}
    298313
    299 function calculateKillDeathRatio(playerState, position)
     314function calculateKillDeathRatio(playerState)
    300315{
    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 
    310316    if (!playerState.statistics.enemyUnitsKilled.total)
    311317        return g_DefaultDecimal;
    312318
     
    316322    return Math.round((playerState.statistics.enemyUnitsKilled.total / playerState.statistics.unitsLost.total)*100)/100;
    317323}
    318324
    319 function calculateMapExploration(playerState, position)
     325function calculateMapExploration(playerState)
    320326{
    321     if (!g_TeamMiscHelperData[playerState.team])
    322         g_TeamMiscHelperData[playerState.team] = [];
    323 
    324     g_TeamMiscHelperData[playerState.team][position] = playerState.statistics.teamPercentMapExplored;
    325 
    326327    return playerState.statistics.percentMapExplored + "%";
    327328}
    328329
    329 function calculateMapFinalControl(playerState, position)
     330function calculateMapFinalControl(playerState)
    330331{
    331     if (!g_TeamMiscHelperData[playerState.team])
    332         g_TeamMiscHelperData[playerState.team] = [];
    333 
    334     g_TeamMiscHelperData[playerState.team][position] = playerState.statistics.teamPercentMapControlled;
    335 
    336332    return playerState.statistics.percentMapControlled + "%";
    337333}
    338334
    339 function calculateMapPeakControl(playerState, position)
     335function calculateMapPeakControl(playerStaten)
    340336{
    341     if (!g_TeamMiscHelperData[playerState.team])
    342         g_TeamMiscHelperData[playerState.team] = [];
    343 
    344     g_TeamMiscHelperData[playerState.team][position] = playerState.statistics.teamPeakPercentMapControlled;
    345 
    346337    return playerState.statistics.peakPercentMapControlled + "%";
    347338}
    348339
     
    358349            let teamTotal = "undefined";
    359350
    360351            if (w == 0)
    361                 teamTotal = (g_TeamMiscHelperData[t][w].food == 0 ? "0" : Math.floor((g_TeamMiscHelperData[t][w].vegetarianFood / g_TeamMiscHelperData[t][w].food) * 100)) + "%";
     352                teamTotal = (g_TeamHelperData[t].food == 0 ? "0" : Math.floor((g_TeamHelperData[t].vegetarianFood / g_TeamHelperData[t].food) * 100)) + "%";
    362353            else if (w == 1)
    363                 teamTotal = (g_TeamMiscHelperData[t][w].Worker == 0 ? "0" : Math.floor((g_TeamMiscHelperData[t][w].Female / g_TeamMiscHelperData[t][w].Worker) * 100)) + "%";
     354                teamTotal = (g_TeamHelperData[t].worker == 0 ? "0" : Math.floor((g_TeamHelperData[t].female / g_TeamHelperData[t].worker) * 100)) + "%";
    364355            else if (w == 2)
    365356            {
    366                 if (!g_TeamMiscHelperData[t][w].enemyUnitsKilled)
     357                if (!g_TeamHelperData[t].enemyUnitsKilled)
    367358                    teamTotal = g_DefaultDecimal;
    368                 else if (!g_TeamMiscHelperData[t][w].unitsLost) // and enemyUnitsKilled.total > 0
     359                else if (!g_TeamHelperData[t].unitsLost)    // and enemyUnitsKilled.total > 0
    369360                    teamTotal = g_InfiniteSymbol; // infinity symbol
    370361                else
    371                     teamTotal = Math.round((g_TeamMiscHelperData[t][w].enemyUnitsKilled / g_TeamMiscHelperData[t][w].unitsLost) * 100) / 100;
     362                    teamTotal = Math.round((g_TeamHelperData[t].enemyUnitsKilled / g_TeamHelperData[t].unitsLost) * 100) / 100;
    372363            }
    373             else if (w >= 3)
    374                 teamTotal = g_TeamMiscHelperData[t][w] + "%";
     364            else if (w == 3)
     365                teamTotal = g_TeamHelperData[t].percentMapExplored + "%";
     366            else if (w == 4)
     367                teamTotal = g_TeamHelperData[t].percentMapControlled + "%";
     368            else if (w == 5)
     369                teamTotal = g_TeamHelperData[t].peakPercentMapControlled + "%";
    375370
    376             Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal;
     371            Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal + "%";
    377372        }
    378373    }
    379374}
  • binaries/data/mods/public/gui/summary/summary.js

     
    119119
    120120        // Update counters
    121121        updateCountersPlayer(playerState, panelInfo.counters, playerCounterValue);
     122
     123        // Calculate g_TeamHelperData
     124        calculateTeamCounters(playerState);
    122125    }
    123126    // Update team counters
    124127    let teamCounterFn = panelInfo.teamCounterFn;