Ticket #3216: t3216_capture_statistics_v10_rebasedv2.patch

File t3216_capture_statistics_v10_rebasedv2.patch, 19.9 KB (added by Imarok, 8 years ago)

rebased the patch. Not ready for reviewing

  • binaries/data/mods/public/gui/summary/counters.js

     
    6666function calculateMilitaryScore(playerState)
    6767{
    6868    return Math.round((playerState.statistics.enemyUnitsKilledValue +
    69         playerState.statistics.enemyBuildingsDestroyedValue) / 10);
     69        playerState.statistics.enemyBuildingsDestroyedValue +
     70        playerState.statistics.buildingsCapturedValue) / 10);
    7071}
    7172
    7273function calculateExplorationScore(playerState)
     
    114115{
    115116    let type = g_BuildingsTypes[position];
    116117    return g_TrainedColor + playerState.statistics.buildingsConstructed[type] + '[/color] / ' +
    117         g_LostColor + playerState.statistics.buildingsLost[type] + '[/color] / ' +
    118         g_KilledColor + playerState.statistics.enemyBuildingsDestroyed[type] + '[/color]';
     118        g_KilledColor + playerState.statistics.enemyBuildingsDestroyed[type] + '[/color]\n' +
     119        g_CapturedColor + playerState.statistics.buildingsCaptured[type] + '[/color] / ' +
     120        g_LostColor + playerState.statistics.buildingsLost[type] + '[/color]\n';
    119121}
    120122
    121 function calculateColorsTeam(counters)
     123function calculateBuildingsTeam(counters)
    122124{
    123125    for (let t in g_Teams)
    124126    {
     
    128130        for (let w in counters)
    129131        {
    130132            let total = {
     133                constructed : 0,
     134                destroyed : 0,
     135                captured : 0,   
     136                lost : 0
     137            };
     138            for (let p = 0; p < g_Teams[t]; ++p)
     139            {
     140                let caption = Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]").caption;
     141                // clean [Color=""], [/Color] and white space for make the sum more easy
     142                caption = caption.replace(/\[([\w\' \\\"\/\=]*)\]|[\t\r \f]/g, "");
     143
     144                let splitCaption = caption.split("\n");
     145                let first = splitCaption[0].split("/");
     146                let second = splitCaption[1].split("/");
     147
     148                total.constructed += (+first[0]);
     149                total.destroyed += (+first[1]);
     150                total.captured += (+second[0]);
     151                total.lost += (+second[1]);
     152            }
     153            let teamTotal = TRAINED_COLOR + total.constructed + '[/color] / ' +
     154                KILLED_COLOR + total.destroyed + '[/color]\n' +
     155                CAPTURED_COLOR + total.captured + '[/color] / ' +
     156                LOST_COLOR + total.lost + '[/color]\n';
     157
     158            Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = teamTotal;
     159        }
     160    }
     161}
     162
     163function calculateUnitsTeam(counters)
     164{
     165    for (let t in g_Teams)
     166        {
     167        if (t == -1)
     168            continue;
     169
     170        for (let w in counters)
     171        {
     172            let total = {
    131173                "c": 0,
    132174                "l": 0,
    133175                "d": 0
  • binaries/data/mods/public/gui/summary/layout.js

     
    99        ],
    1010        "titleHeadings": [],
    1111        "counters": [   // counters on score panel
    12             { "width": 100, "fn": calculateEconomyScore },
    13             { "width": 100, "fn": calculateMilitaryScore },
    14             { "width": 100, "fn": calculateExplorationScore },
    15             { "width": 100, "fn": calculateScoreTotal}
     12            { "width": 100, "fn": calculateEconomyScore, "verticalOffset": 12 },
     13            { "width": 100, "fn": calculateMilitaryScore, "verticalOffset": 12 },
     14            { "width": 100, "fn": calculateExplorationScore, "verticalOffset": 12 },
     15            { "width": 100, "fn": calculateScoreTotal, "verticalOffset": 12 }
    1616        ],
    1717        "teamCounterFn": calculateScoreTeam
    1818    },
     
    2929            { "caption": translate("Wonders"), "yStart": 34, "width": 85 }
    3030        ],
    3131        "titleHeadings": [
    32             { "caption": translate("Buildings Statistics (Constructed / Lost / Destroyed)"), "yStart": 16, "width": (85 * 7 + 105) },   // width = 700
     32            {
     33                "caption": sprintf(translate("Buildings Statistics (%(constructed)s / %(destroyed)s / %(captured)s / %(lost)s)"),
     34                            {
     35                                constructed: g_TrainedColor + translate("Constructed") + '[/color]',
     36                                destroyed: g_KilledColor + translate("Destroyed") + '[/color]',
     37                                captured: g_CapturedColor + translate("Captured") + '[/color]',
     38                                lost: g_LostColor + translate("Lost") + '[/color]'
     39                            }),
     40                "yStart": 16,
     41                "width": (85 * 7 + 105)
     42            },  // width = 735
    3343        ],
    3444        "counters": [   // counters on buildings panel
    35             { "width": 105, "fn": calculateBuildings },
    36             { "width": 85, "fn": calculateBuildings },
    37             { "width": 85, "fn": calculateBuildings },
    38             { "width": 85, "fn": calculateBuildings },
    39             { "width": 85, "fn": calculateBuildings },
    40             { "width": 85, "fn": calculateBuildings },
    41             { "width": 85, "fn": calculateBuildings },
    42             { "width": 85, "fn": calculateBuildings }
     45            { "width": 105, "fn": calculateBuildings, "verticalOffset": 3},
     46            { "width": 85, "fn": calculateBuildings, "verticalOffset": 3},
     47            { "width": 85, "fn": calculateBuildings, "verticalOffset": 3},
     48            { "width": 85, "fn": calculateBuildings, "verticalOffset": 3},
     49            { "width": 85, "fn": calculateBuildings, "verticalOffset": 3},
     50            { "width": 85, "fn": calculateBuildings, "verticalOffset": 3},
     51            { "width": 85, "fn": calculateBuildings, "verticalOffset": 3},
     52            { "width": 85, "fn": calculateBuildings, "verticalOffset": 3}
    4353        ],
    44         "teamCounterFn": calculateColorsTeam
     54        "teamCounterFn": calculateBuildingsTeam
    4555    },
    4656    {   // units panel
    4757        "headings": [   // headings on units panel
     
    5666            { "caption": translate("Traders"), "yStart": 34, "width": 100 }
    5767        ],
    5868        "titleHeadings": [
    59             { "caption": translate("Units Statistics (Trained / Lost / Killed)"), "yStart": 16, "width": (100 * 7 + 120) }, // width = 820
     69            {
     70                "caption": sprintf(translate("Units Statistics (%(trained)s / %(lost)s / %(killed)s)"),
     71                            {
     72                                trained: g_TrainedColor + translate("Trained") + '[/color]',
     73                                lost: g_LostColor + translate("Lost") + '[/color]',
     74                                killed: g_KilledColor + translate("Killed") + '[/color]'
     75                            }),
     76                "yStart": 16,
     77                "width": (100 * 7 + 120)
     78            },  // width = 720
    6079        ],
    6180        "counters": [   // counters on units panel
    62             { "width": 120, "fn": calculateUnits },
    63             { "width": 100, "fn": calculateUnits },
    64             { "width": 100, "fn": calculateUnits },
    65             { "width": 100, "fn": calculateUnits },
    66             { "width": 100, "fn": calculateUnits },
    67             { "width": 100, "fn": calculateUnits },
    68             { "width": 100, "fn": calculateUnits },
    69             { "width": 100, "fn": calculateUnits }
     81            { "width": 120, "fn": calculateUnits, "verticalOffset": 12 },
     82            { "width": 100, "fn": calculateUnits, "verticalOffset": 12 },
     83            { "width": 100, "fn": calculateUnits, "verticalOffset": 12 },
     84            { "width": 100, "fn": calculateUnits, "verticalOffset": 12 },
     85            { "width": 100, "fn": calculateUnits, "verticalOffset": 12 },
     86            { "width": 100, "fn": calculateUnits, "verticalOffset": 12 },
     87            { "width": 100, "fn": calculateUnits, "verticalOffset": 12 },
     88            { "width": 100, "fn": calculateUnits, "verticalOffset": 12 }
    7089        ],
    71         "teamCounterFn": calculateColorsTeam
     90        "teamCounterFn": calculateUnitsTeam
    7291    },
    7392    {   // resources panel
    7493        "headings": [   // headings on resources panel
     
    7897            { "caption": translate("Stone"), "yStart": 34, "width": 100 },
    7998            { "caption": translate("Metal"), "yStart": 34, "width": 100 },
    8099            { "caption": translate("Total"), "yStart": 34, "width": 110 },
    81             { "caption": translate("Tributes (Sent / Received)"), "yStart": 16, "width": 121 },
     100            {
     101                "caption": sprintf(translate("Tributes \n(%(sent)s / %(received)s)"),
     102                            {
     103                                sent: g_IncomeColor + translate("Sent") + '[/color]',
     104                                received: g_OutcomeColor + translate("Received") + '[/color]'
     105                            }),
     106                "yStart": 16,
     107                "width": 121
     108            },
    82109            { "caption": translate("Treasures collected"), "yStart": 16, "width": 100 },
    83110            { "caption": translate("Loot"), "yStart": 16, "width": 100 }
    84111        ],
    85112        "titleHeadings": [
    86             { "caption": translate("Resource Statistics (Gathered / Used)"), "yStart": 16, "width": (100 * 4 + 110) }, // width = 510
     113            {
     114                "caption": sprintf(translate("Resource Statistics (%(gathered)s / %(used)s)"),
     115                            {
     116                                gathered: g_IncomeColor + translate("Gathered") + '[/color]',
     117                                used: g_OutcomeColor + translate("Used") + '[/color]'
     118                            }),
     119                "yStart": 16,
     120                "width": (100 * 4 + 110)
     121            }, // width = 510
    87122        ],
    88123        "counters": [   // counters on resources panel
    89             { "width": 100, "fn": calculateResources },
    90             { "width": 100, "fn": calculateResources },
    91             { "width": 100, "fn": calculateResources },
    92             { "width": 100, "fn": calculateResources },
    93             { "width": 110, "fn": calculateTotalResources },
    94             { "width": 121, "fn": calculateTributeSent },
    95             { "width": 100, "fn": calculateTreasureCollected },
    96             { "width": 100, "fn": calculateLootCollected }
     124            { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
     125            { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
     126            { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
     127            { "width": 100, "fn": calculateResources, "verticalOffset": 12 },
     128            { "width": 110, "fn": calculateTotalResources, "verticalOffset": 12 },
     129            { "width": 121, "fn": calculateTributeSent, "verticalOffset": 12 },
     130            { "width": 100, "fn": calculateTreasureCollected, "verticalOffset": 12 },
     131            { "width": 100, "fn": calculateLootCollected, "verticalOffset": 12 }
    97132        ],
    98133        "teamCounterFn": calculateResourcesTeam
    99134    },
     
    109144        ],
    110145        "titleHeadings": [],
    111146        "counters": [   // counters on market panel
    112             { "width": 100, "fn": calculateResourceExchanged },
    113             { "width": 100, "fn": calculateResourceExchanged },
    114             { "width": 100, "fn": calculateResourceExchanged },
    115             { "width": 100, "fn": calculateResourceExchanged },
    116             { "width": 100, "fn": calculateBarterEfficiency },
    117             { "width": 100, "fn": calculateTradeIncome }
     147            { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
     148            { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
     149            { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
     150            { "width": 100, "fn": calculateResourceExchanged, "verticalOffset": 12 },
     151            { "width": 100, "fn": calculateBarterEfficiency, "verticalOffset": 12 },
     152            { "width": 100, "fn": calculateTradeIncome, "verticalOffset": 12 }
    118153        ],
    119154        "teamCounterFn": calculateMarketTeam
    120155    },
     
    132167            { "caption": translate("Map control"), "xOffset": 400, "yStart": 16, "width": 200 }
    133168        ],
    134169        "counters": [   // counters on miscellaneous panel
    135             { "width": 100, "fn": calculateVegetarianRatio },
    136             { "width": 100, "fn": calculateFeminization },
    137             { "width": 100, "fn": calculateKillDeathRatio },
    138             { "width": 100, "fn": calculateMapExploration },
    139             { "width": 100, "fn": calculateMapPeakControl },
    140             { "width": 100, "fn": calculateMapFinalControl }
     170            { "width": 100, "fn": calculateVegetarianRatio, "verticalOffset": 12 },
     171            { "width": 100, "fn": calculateFeminization, "verticalOffset": 12 },
     172            { "width": 100, "fn": calculateKillDeathRatio, "verticalOffset": 12 },
     173            { "width": 100, "fn": calculateMapExploration, "verticalOffset": 12 },
     174            { "width": 100, "fn": calculateMapPeakControl, "verticalOffset": 12 },
     175            { "width": 100, "fn": calculateMapFinalControl, "verticalOffset": 12 }
    141176        ],
    142177        "teamCounterFn": calculateMiscellaneous
    143178    }
     
    214249        for (let w in counters)
    215250        {
    216251            counterObject = Engine.GetGUIObjectByName("valueData[" + p + "][" + w + "]");
    217             counterObject.size = left + " 6 " + (left + counters[w].width) + " 100%";
     252            counterObject.size =  left + " " + counters[w].verticalOffset + " " + (left + counters[w].width) + " 100%";
    218253            counterObject.hidden = false;
    219254            left += counters[w].width;
    220255        }
     
    229264            for (let w in counters)
    230265            {
    231266                counterObject = Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + p + "][" + w + "]");
    232                 counterObject.size = left + " 6 " + (left + counters[w].width) + " 100%";
     267                counterObject.size = left + " " + counters[w].verticalOffset + " " + (left + counters[w].width) + " 100%";
    233268                counterObject.hidden = false;
    234269
    235270                if (g_Teams[t])
    236271                {
    237                     let yStart = 30 + g_Teams[t] * (g_PlayerBoxYSize + g_PlayerBoxGap) + 2;
     272                    let yStart = 25 + g_Teams[t] * (g_PlayerBoxYSize + g_PlayerBoxGap) + 3 + counters[w].verticalOffset;
    238273                    counterTotalObject = Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]");
    239274                    counterTotalObject.size = (left + 20) + " " + yStart + " " + (left + counters[w].width) + " 100%";
    240275                    counterTotalObject.hidden = false;
     
    272307        Engine.GetGUIObjectByName("teamNameHeadingt["+i+"]").caption = "Team "+(i+1);
    273308
    274309        let teamHeading = Engine.GetGUIObjectByName("teamHeadingt["+i+"]");
    275         let yStartTotal = 30 + g_Teams[i] * (g_PlayerBoxYSize + g_PlayerBoxGap) + 2;
    276         teamHeading.size = "50 "+yStartTotal+" 100% "+(yStartTotal+20);
     310        let yStartTotal = 30 + g_Teams[i] * (g_PlayerBoxYSize + g_PlayerBoxGap) + 10;
     311        teamHeading.size = "50 " + yStartTotal + " 100% " + (yStartTotal + 20);
    277312        teamHeading.caption = translate("Team total");
    278313    }
    279314
  • binaries/data/mods/public/gui/summary/summary.js

     
    33// const for filtering long collective headings
    44const g_LongHeadingWidth = 250;
    55// Vertical size of player box
    6 const g_PlayerBoxYSize = 30;
     6const g_PlayerBoxYSize = 40;
    77// Gap between players boxes
    88const g_PlayerBoxGap = 2;
    99// Alpha for player box
     
    1111// Alpha for player color box
    1212const g_PlayerColorBoxAlpha = " 255";
    1313// yStart value for spacing teams boxes (and noTeamsBox)
    14 const g_TeamsBoxYStart = 65;
     14const g_TeamsBoxYStart = 40;
    1515// Colors used for units and buildings
    1616const g_TrainedColor = '[color="201 255 200"]';
    1717const g_LostColor = '[color="255 213 213"]';
    1818const g_KilledColor = '[color="196 198 255"]';
     19const g_CapturedColor = '[color="255 255 157"]';
    1920
    2021const g_BuildingsTypes = [ "total", "House", "Economic", "Outpost", "Military", "Fortress", "CivCentre", "Wonder" ];
    2122const g_UnitsTypes = [ "total", "Infantry", "Worker", "Cavalry", "Champion", "Hero", "Ship", "Trader" ];
  • binaries/data/mods/public/gui/summary/summary.xml

     
    1414
    1515    <!-- After settings.js, which defines g_Settings and g_MaxPlayers. -->
    1616    <script file="gui/summary/counters.js"/>
     17    <script file="gui/summary/summary.js"/>
    1718    <script file="gui/summary/layout.js"/>
    18     <script file="gui/summary/summary.js"/>
    1919
    2020    <object type="image"
    2121        style="ModernWindow"
     
    122122                    <object size="0 30 100% 100%">
    123123                        <repeat count="8" var="n">
    124124                            <object type="image" name="playerBoxt[i][n]" size="10 0 10 30" hidden="true">
    125                                 <object name="playerColorBoxt[i][n]" type="image" size="10 4 30 24"/>
    126                                 <object name="playerNamet[i][n]" type="text"  size="40 2 208 100%" style="ModernLeftLabelText" />
    127                                 <object name="civIcont[i][n]" type="image" size="208 0 240 32"/>
     125                                <object type="image" sprite="ForegroundBox" size="10 9 34 33">
     126                                    <object name="playerColorBoxt[i][n]" type="image" size="2 2 22 22"/>
     127                                </object>
     128                                <object name="playerNamet[i][n]" type="text"  size="40 2 208 100%" style="ModernLeftLabelText"/>
     129                                <object name="civIcont[i][n]" type="image" size="208 5 240 37"/>
    128130                                <repeat var="x" count="8">
    129131                                    <object name="valueDataTeam[i][n][x]" type="text" style="ModernTabLabelText">
    130132                                    </object>
     
    143145            <object type="image" name="noTeamsBox" size="0 65 100% 100%-50" hidden="true">
    144146                <repeat count="8">
    145147                    <object type="image" name="playerBox[n]" size="10 0 10 30" hidden="true">
    146                         <object type="image" sprite="ForegroundBox" size="10 4 34 28">
     148                        <object type="image" sprite="ForegroundBox" size="10 9 34 33">
    147149                            <object name="playerColorBox[n]" type="image" size="2 2 22 22"/>
    148150                        </object>
    149151                        <object name="playerName[n]" type="text"  size="40 2 208 100%" style="ModernLeftLabelText"/>
    150                         <object name="civIcon[n]" type="image" size="208 0 240 32"/>
     152                        <object name="civIcon[n]" type="image" size="208 5 240 37"/>
    151153                        <repeat var="x" count="8">
    152154                            <object name="valueData[n][x]" type="text" style="ModernTabLabelText">
    153155                            </object>
  • binaries/data/mods/public/simulation/components/Capturable.js

     
    151151        if (this.cp[i] >= this.cp[bestPlayer])
    152152            bestPlayer = +i;
    153153
     154    let cmpLostPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
     155    if (cmpLostPlayerStatisticsTracker)
     156        cmpLostPlayerStatisticsTracker.LostEntity(this.entity);
     157
    154158    cmpOwnership.SetOwner(bestPlayer);
     159
     160    let cmpCapturedPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
     161    if (cmpCapturedPlayerStatisticsTracker)
     162        cmpCapturedPlayerStatisticsTracker.CapturedBuilding(this.entity);
    155163};
    156164
    157165Capturable.prototype.GetRegenRate = function()
  • binaries/data/mods/public/simulation/components/StatisticsTracker.js

     
    9393        "total": 0
    9494        };
    9595    this.enemyBuildingsDestroyedValue = 0;
     96    this.buildingsCaptured = {
     97        "House": 0,
     98        "Economic": 0,
     99        "Outpost": 0,
     100        "Military": 0,
     101        "Fortress": 0,
     102        "CivCentre": 0,
     103        "Wonder": 0,
     104        "total": 0
     105    };
     106    this.buildingsCapturedValue = 0;
    96107    // resources
    97108    this.resourcesGathered = {
    98109        "food": 0,
     
    152163        "unitsLostValue": this.unitsLostValue,
    153164        "enemyUnitsKilled": this.enemyUnitsKilled,
    154165        "enemyUnitsKilledValue": this.enemyUnitsKilledValue,
    155         "buildingsConstructed": this.buildingsConstructed,
    156         "buildingsLost": this.buildingsLost,
     166        "buildingsConstructed": this.buildingsConstructed,
     167        "buildingsLost": this.buildingsLost,
    157168        "buildingsLostValue": this.buildingsLostValue,
    158169        "enemyBuildingsDestroyed": this.enemyBuildingsDestroyed,
    159170        "enemyBuildingsDestroyedValue": this.enemyBuildingsDestroyedValue,
     171        "buildingsCaptured": this.buildingsCaptured,
     172        "buildingsCapturedValue": this.buildingsCapturedValue,
    160173        "resourcesGathered": this.resourcesGathered,
    161174        "resourcesUsed": this.resourcesUsed,
    162175        "resourcesSold": this.resourcesSold,
    163         "resourcesBought": this.resourcesBought,
    164         "tributesSent": this.tributesSent,
     176        "resourcesBought": this.resourcesBought,
     177        "tributesSent": this.tributesSent,
    165178        "tributesReceived": this.tributesReceived,
    166179        "tradeIncome": this.tradeIncome,
    167180        "treasuresCollected": this.treasuresCollected,
     
    306319    }
    307320};
    308321
    309 /**
    310  * @param type Generic type of resource (string)
    311  * @param amount Amount of resource, whick should be added (integer)
    312  * @param specificType Specific type of resource (string, optional)
    313  */
     322StatisticsTracker.prototype.CapturedBuilding = function(capturedBuilding)
     323{
     324    let cmpCapturedBuildingIdentity = Engine.QueryInterface(capturedBuilding, IID_Identity);
     325    let cmpCost = Engine.QueryInterface(capturedBuilding, IID_Cost);
     326    let costs = cmpCost.GetResourceCosts();
     327
     328    for (let type of this.buildingsClasses)
     329        this.CounterIncrement(cmpCapturedBuildingIdentity, "buildingsCaptured", type);
     330   
     331    this.buildingsCaptured.total++;
     332   
     333    for (let i in costs)
     334        this.buildingsCapturedValue += costs[i];
     335};
     336
     337/**
     338 * @param type Generic type of resource (string)
     339 * @param amount Amount of resource, whick should be added (integer)
     340 * @param specificType Specific type of resource (string, optional)
     341 */
    314342StatisticsTracker.prototype.IncreaseResourceGatheredCounter = function(type, amount, specificType)
    315343{
    316344    this.resourcesGathered[type] += amount;