Ticket #4193: 4193-loot-tooltip.3.patch

File 4193-loot-tooltip.3.patch, 21.9 KB (added by Mate-86, 8 years ago)
  • data/mods/public/globalscripts/LootHelper.js

     
     1/*
     2Helper to calculate the loot used by gui and simulation.
     3*/
     4
     5function calculateLootResources(targetEntities, looterEntity)
     6{
     7    var totalResources = {};
     8
     9    for (let targetEntity of targetEntities)
     10    {
     11        var cmpLoot = Engine.QueryInterface(targetEntity, IID_Loot);
     12        if (!cmpLoot)
     13            continue;
     14
     15        // Loot resources as defined in the templates
     16        var resources = cmpLoot.GetResources();
     17       
     18        if (looterEntity)
     19            for (let type in resources)
     20                resources[type] = ApplyValueModificationsToEntity("Looter/Resource/"+type, resources[type], looterEntity);
     21       
     22        // Loot resources that killed enemies carried
     23        var cmpResourceGatherer = Engine.QueryInterface(targetEntity, IID_ResourceGatherer);
     24        if (cmpResourceGatherer)
     25            for (let resource of cmpResourceGatherer.GetCarryingStatus())
     26                resources[resource.type] += resource.amount;
     27
     28        // Loot resources traders carry
     29        var cmpTrader = Engine.QueryInterface(targetEntity, IID_Trader);
     30        if (cmpTrader)
     31        {
     32            let carriedGoods = cmpTrader.GetGoods();
     33            if (carriedGoods.amount)
     34            {
     35                resources[carriedGoods.type] +=
     36                    + (carriedGoods.amount.traderGain || 0)
     37                    + (carriedGoods.amount.market1Gain || 0)
     38                    + (carriedGoods.amount.market2Gain || 0);
     39            }
     40        }
     41
     42        for (let type in resources)
     43            totalResources[type] += resources[type];
     44    }
     45
     46    return totalResources;
     47}
     48 No newline at end of file
  • data/mods/public/globalscripts/Templates.js

     
     1const lootTypes = ["xp", "food", "wood", "stone", "metal"];
     2
    13/**
    24 * Gets an array of all classes for this identity template
    35 */
     
    244246            "rate": getEntityValue("Heal/Rate")
    245247        };
    246248
     249    if (template.Loot)
     250    {
     251        ret.loot = {};
     252        for (let type of lootTypes)
     253        {
     254            if (template.Loot[type])
     255                ret.loot[type] = getEntityValue("Loot/" + type);
     256        }
     257    }
     258
    247259    if (template.Obstruction)
    248260    {
    249261        ret.obstruction = {
  • data/mods/public/gui/common/setup_resources.xml

     
    2525        sprite="stretched:session/icons/resources/time_small.png"
    2626        size="16 16"
    2727    />
     28    <icon name="icon_xp"
     29        sprite="stretched:session/icons/resources/xp_small.png"
     30        size="16 16"
     31    />
    2832</setup>
  • data/mods/public/gui/common/tooltips.js

     
    575575    return headerFont(translate("Classes:")) + ' ' +
    576576        bodyFont(template.visibleIdentityClasses.map(c => translate(c)).join(translate(", ")));
    577577}
     578
     579function getLootTooltip(template)
     580{
     581    if (!template.loot)
     582        return "";
     583
     584    let loots = [];
     585    for (let type in template.loot)
     586        loots.push(sprintf(translate("%(component)s %(loot)s"), {
     587            "component": costIcon(type),
     588            "loot": template.loot[type]
     589    }));
     590   
     591    return headerFont(translate("Loot") + ": ") + loots.join(" ");
     592}
  • data/mods/public/gui/credits/texts/programming.json

     
    122122            {"nick": "MarkT", "name": "Mark Thompson"},
    123123            {"nick": "Markus"},
    124124            {"nick": "Matei", "name": "Matei Zaharia"},
     125            {"nick": "Mate-86", "name": "Mate Kovacs"},
    125126            {"nick": "MattDoerksen", "name": "Matt Doerksen"},
    126127            {"nick": "mattlott", "name": "Matt Lott"},
    127128            {"nick": "maveric", "name": "Anton Protko"},
  • data/mods/public/gui/session/selection_details.js

     
    291291        getBuildRateTooltip,
    292292        getSpeedTooltip,
    293293        getGarrisonTooltip,
    294         getProjectilesTooltip
     294        getProjectilesTooltip,
     295        getLootTooltip
    295296    ].map(func => func(entState)).filter(tip => tip).join("\n");
    296297
    297298    let iconTooltips = [];
     
    320321    let capturePoints = (new Array(g_MaxPlayers + 1)).fill(0);
    321322    let playerID = 0;
    322323    let totalResourcesCarried = {};
     324    let totalTrade = {};
     325    let totalLoot = {};
    323326
    324327    for (let i = 0; i < selection.length; ++i)
    325328    {
    326329        let entState = GetEntityState(selection[i]);
     330        let extEntState = GetExtendedEntityState(selection[i]);
    327331        if (!entState)
    328332            continue;
    329333        playerID = entState.player; // trust that all selected entities have the same owner
     
    338342            capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]);
    339343        }
    340344
     345        if (extEntState.loot)
     346        {
     347            for (let type of lootTypes)
     348            {
     349                totalLoot[type] = (totalLoot[type] || 0) + extEntState.loot[type];
     350            }
     351        }
     352
    341353        if (entState.resourceCarrying && entState.resourceCarrying.length)
    342354        {
    343355            let carrying = entState.resourceCarrying[0];
    344356            totalResourcesCarried[carrying.type] = (totalResourcesCarried[carrying.type] || 0) + carrying.amount;
    345357        }
     358
     359        if (entState.trader && entState.trader.goods)
     360        {
     361            let totalGain = entState.trader.goods.amount.traderGain;
     362            if (entState.trader.goods.amount.market1Gain)
     363                totalGain += entState.trader.goods.amount.market1Gain;
     364            if (entState.trader.goods.amount.market2Gain)
     365                totalGain += entState.trader.goods.amount.market2Gain;
     366
     367            totalTrade[entState.trader.goods.type] = totalGain;
     368        }
    346369    }
    347370
     371    /*for (let type of lootTypes)
     372    {
     373        totalLoot[type] += totalResourcesCarried[type] || 0;
     374        totalLoot[type] += totalTrade[type] || 0;
     375        if (totalLoot[type] == 0)
     376            delete totalLoot[type];
     377    }*/
     378    totalLoot = calculateLootResources(selection);
     379
    348380    Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0;
    349381    if (averageHealth > 0)
    350382    {
     
    394426
    395427    let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits");
    396428    numberOfUnits.caption = selection.length;
    397     numberOfUnits.tooltip = Object.keys(totalResourcesCarried).map(res =>
    398         costIcon(res) + totalResourcesCarried[res]
    399     ).join(" ");
    400429
     430    numberOfUnits.tooltip = "";
     431
     432    if (Object.keys(totalResourcesCarried).length > 0)
     433        numberOfUnits.tooltip = translate("Carrying") + ": " + Object.keys(totalResourcesCarried).map(res =>
     434            costIcon(res) + totalResourcesCarried[res]).join(" ") + "\n";
     435
     436    numberOfUnits.tooltip += translate("Loot") + ": " + Object.keys(totalLoot).map(res =>
     437        costIcon(res) + totalLoot[res]).join(" ");
     438
    401439    // Unhide Details Area
    402440    Engine.GetGUIObjectByName("detailsAreaMultiple").hidden = false;
    403441    Engine.GetGUIObjectByName("detailsAreaSingle").hidden = true;
  • data/mods/public/gui/session/session.js

     
    11431143        "Cavalry",
    11441144        "Champion",
    11451145        "Hero",
     1146        "Siege",
    11461147        "Ship",
    11471148        "Trader"
    11481149    ];
  • data/mods/public/gui/structree/draw.js

     
    1414    getProjectilesTooltip,
    1515    getSpeedTooltip,
    1616    getGatherTooltip,
    17     getPopulationBonusTooltip
     17    getPopulationBonusTooltip,
     18    getLootTooltip
    1819];
    1920
    2021/**
  • data/mods/public/gui/summary/counters.js

     
    55    g_TeamHelperData = [];
    66}
    77
    8 function formatTrained(trained, lost, killed)
     8function formatTrained(trained, killed, lost)
    99{
    1010    return g_TrainedColor + trained + '[/color] / ' +
    11         g_LostColor + lost + '[/color] / ' +
    12         g_KilledColor + killed + '[/color]';
     11        g_KilledColor + killed + '[/color] / ' +
     12        g_LostColor + lost + '[/color]';
    1313}
    1414
    1515function formatCaptured(constructed, destroyed, captured, lost)
     
    217217
    218218        for (let w in counters)
    219219        {
    220             let total = {
    221                 "constructed": 0,
    222                 "lost": 0,
    223                 "destroyed": 0
     220            let total =
     221            {
     222                "trained": 0,
     223                "killed": 0,
     224                "captured" : 0,
     225                "lost": 0
    224226            };
    225227
    226228            for (let p = 0; p < g_Teams[t]; ++p)
    227229            {
    228                 let splitCaption = cleanGUICaption(t, p, w).split("/");
     230                if (w == 0 || w == 6)
     231                {
     232                    let splitCaption = cleanGUICaption(t, p, w, false).split("\n");
     233                    let first = splitCaption[0].split("/");
     234                    let second = splitCaption[1].split("/");
    229235
    230                 total.constructed += +splitCaption[0];
    231                 total.lost += +splitCaption[1];
    232                 total.destroyed += +splitCaption[2];
     236                    total.trained += +first[0];
     237                    total.killed += +first[1];
     238                    total.captured += +second[0];
     239                    total.lost += +second[1];
     240                }
     241                else
     242                {
     243                    let splitCaption = cleanGUICaption(t, p, w).split("/");
     244                    total.trained += +splitCaption[0];
     245                    total.killed += +splitCaption[1];
     246                    total.lost += +splitCaption[2];
     247                }
    233248            }
    234249
    235             Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption =
    236                 formatTrained(total.constructed, total.lost, total.destroyed);
     250            let formattedCaption = "";
     251
     252            if (w == 0 || w == 6)
     253                formattedCaption = formatCaptured(total.trained, total.killed, total.captured, total.lost);
     254            else
     255                formattedCaption = formatTrained(total.trained, total.killed, total.lost);
     256
     257            Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = formattedCaption;
    237258        }
    238259    }
    239260}
    240261
     262function calculateUnitsWithCaptured(playerState, position)
     263{
     264    let type = g_UnitsTypes[position];
     265
     266    return formatCaptured(
     267        playerState.statistics.unitsTrained[type],
     268        playerState.statistics.enemyUnitsKilled[type],
     269        playerState.statistics.unitsCaptured[type],
     270        playerState.statistics.unitsLost[type]);
     271}
     272
    241273function calculateUnits(playerState, position)
    242274{
    243275    let type = g_UnitsTypes[position];
     
    244276
    245277    return formatTrained(
    246278        playerState.statistics.unitsTrained[type],
    247         playerState.statistics.unitsLost[type],
    248         playerState.statistics.enemyUnitsKilled[type]);
     279        playerState.statistics.enemyUnitsKilled[type],
     280        playerState.statistics.unitsLost[type]);
    249281}
    250282
    251283function calculateResources(playerState, position)
  • data/mods/public/gui/summary/layout.js

     
    5656    "units": {
    5757        "headings": [
    5858            { "caption": translate("Player name"), "yStart": 26, "width": 200 },
    59             { "caption": translate("Total"), "yStart": 34, "width": 120 },
    60             { "caption": translate("Infantry"), "yStart": 34, "width": 100 },
    61             { "caption": translate("Worker"), "yStart": 34, "width": 100 },
    62             { "caption": translate("Cavalry"), "yStart": 34, "width": 100 },
    63             { "caption": translate("Champion"), "yStart": 34, "width": 100 },
    64             { "caption": translate("Heroes"), "yStart": 34, "width": 100 },
    65             { "caption": translate("Navy"), "yStart": 34, "width": 100 },
    66             { "caption": translate("Traders"), "yStart": 34, "width": 100 }
     59            { "caption": translate("Total"), "yStart": 34, "width": 105 },
     60            { "caption": translate("Infantry"), "yStart": 34, "width": 85 },
     61            { "caption": translate("Worker"), "yStart": 34, "width": 85 },
     62            { "caption": translate("Cavalry"), "yStart": 34, "width": 85 },
     63            { "caption": translate("Champion"), "yStart": 34, "width": 85 },
     64            { "caption": translate("Heroes"), "yStart": 34, "width": 85 },
     65            { "caption": translate("Siege"), "yStart": 34, "width": 85 },
     66            { "caption": translate("Navy"), "yStart": 34, "width": 85 },
     67            { "caption": translate("Traders"), "yStart": 34, "width": 85 }
    6768        ],
    6869        "titleHeadings": [
    6970            {
    70                 "caption": sprintf(translate("Units Statistics (%(trained)s / %(lost)s / %(killed)s)"),
     71                "caption": sprintf(translate("Units Statistics (%(trained)s / %(killed)s / %(captured)s / %(lost)s)"),
    7172                    {
    7273                        "trained": g_TrainedColor + translate("Trained") + '[/color]',
    73                         "lost": g_LostColor + translate("Lost") + '[/color]',
    74                         "killed": g_KilledColor + translate("Killed") + '[/color]'
     74                        "killed": g_KilledColor + translate("Killed") + '[/color]',
     75                        "captured": g_CapturedColor + translate("Captured") + '[/color]',
     76                        "lost": g_LostColor + translate("Lost") + '[/color]'
    7577                    }),
    7678                "yStart": 16,
    7779                "width": (100 * 7 + 120)
     
    7880            },  // width = 820
    7981        ],
    8082        "counters": [
    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 }
     83            { "width": 105, "fn": calculateUnitsWithCaptured, "verticalOffset": 3 },
     84            { "width": 85, "fn": calculateUnits, "verticalOffset": 12 },
     85            { "width": 85, "fn": calculateUnits, "verticalOffset": 12 },
     86            { "width": 85, "fn": calculateUnits, "verticalOffset": 12 },
     87            { "width": 85, "fn": calculateUnits, "verticalOffset": 12 },
     88            { "width": 85, "fn": calculateUnits, "verticalOffset": 12 },
     89            { "width": 105, "fn": calculateUnitsWithCaptured, "verticalOffset": 3 },
     90            { "width": 85, "fn": calculateUnits, "verticalOffset": 12 },
     91            { "width": 85, "fn": calculateUnits, "verticalOffset": 12 }
    8992        ],
    9093        "teamCounterFn": calculateUnitsTeam
    9194    },
  • data/mods/public/gui/summary/summary.js

     
    1 const g_MaxHeadingTitle= 8;
     1const g_MaxHeadingTitle= 9;
    22
    33// const for filtering long collective headings
    44const g_LongHeadingWidth = 250;
     
    1616const g_CapturedColor = '[color="255 255 157"]';
    1717
    1818const g_BuildingsTypes = [ "total", "House", "Economic", "Outpost", "Military", "Fortress", "CivCentre", "Wonder" ];
    19 const g_UnitsTypes = [ "total", "Infantry", "Worker", "Cavalry", "Champion", "Hero", "Ship", "Trader" ];
     19const g_UnitsTypes = [ "total", "Infantry", "Worker", "Cavalry", "Champion", "Hero", "Siege", "Ship", "Trader" ];
    2020const g_ResourcesTypes = [ "food", "wood", "stone", "metal" ];
    2121
    2222// Colors used for gathered and traded resources
  • data/mods/public/gui/summary/summary.xml

     
    103103                <object name="playerNameHeading" type="text" style="ModernLeftTabLabelText">
    104104                    <translatableAttribute id="caption">Player name</translatableAttribute>
    105105                </object>
    106                 <repeat var="x" count="8">
     106                <repeat var="x" count="9">
    107107                    <object name="titleHeading[x]" type="text" style="ModernTabLabelText">
    108108                    </object>
    109109                </repeat>
    110                 <repeat var="x" count="8">
     110                <repeat var="x" count="9">
    111111                    <object name="Heading[x]" type="text" style="ModernTabLabelText">
    112112                    </object>
    113113                </repeat>
     
    124124                                </object>
    125125                                <object name="playerNamet[i][n]" type="text" size="40 2 208 100%" style="ModernLeftLabelText"/>
    126126                                <object name="civIcont[i][n]" type="image" size="208 5 240 37" />
    127                                 <repeat var="x" count="8">
     127                                <repeat var="x" count="9">
    128128                                    <object name="valueDataTeam[i][n][x]" type="text" style="ModernTabLabelText">
    129129                                    </object>
    130130                                </repeat>
     
    132132                        </repeat>
    133133                    </object>
    134134                    <object name="teamHeadingt[i]" type="text" style="ModernLeftTabLabelText"/>
    135                     <repeat var="x" count="8">
     135                    <repeat var="x" count="9">
    136136                        <object name="valueDataTeam[i][x]" type="text" style="ModernTabLabelText">
    137137                        </object>
    138138                    </repeat>
     
    147147                        </object>
    148148                        <object name="playerName[n]" type="text" size="40 2 208 100%" style="ModernLeftLabelText"/>
    149149                        <object name="civIcon[n]" type="image" size="208 5 240 37"/>
    150                         <repeat var="x" count="8">
     150                        <repeat var="x" count="9">
    151151                            <object name="valueData[n][x]" type="text" style="ModernTabLabelText">
    152152                            </object>
    153153                        </repeat>
  • data/mods/public/simulation/components/Capturable.js

     
    159159
    160160    let cmpCapturedPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
    161161    if (cmpCapturedPlayerStatisticsTracker)
    162         cmpCapturedPlayerStatisticsTracker.CapturedBuilding(this.entity);
     162        cmpCapturedPlayerStatisticsTracker.CapturedEntity(this.entity);
    163163};
    164164
    165165Capturable.prototype.GetRegenRate = function()
  • data/mods/public/simulation/components/GuiInterface.js

     
    421421        "barterMarket": null,
    422422        "buildingAI": null,
    423423        "heal": null,
     424        "loot": null,
    424425        "obstruction": null,
    425426        "turretParent":null,
    426427        "promotion": null,
     
    568569            "healableClasses": cmpHeal.GetHealableClasses(),
    569570        };
    570571
     572    let cmpLoot = Engine.QueryInterface(ent, IID_Loot);
     573    if (cmpLoot)
     574    {
     575        let resources = cmpLoot.GetResources();
     576        ret.loot = {
     577            "xp": cmpLoot.GetXp(),
     578            "food": resources.food,
     579            "wood": resources.wood,
     580            "stone": resources.stone,
     581            "metal": resources.metal
     582        };
     583    }
     584
    571585    let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
    572586    if (cmpUnitMotion)
    573587        ret.speed = {
  • data/mods/public/simulation/components/StatisticsTracker.js

     
    1212        "Cavalry",
    1313        "Champion",
    1414        "Hero",
     15        "Siege",
    1516        "Ship",
    1617        "Trader"
    1718    ];
     
    2223        "Cavalry": 0,
    2324        "Champion": 0,
    2425        "Hero": 0,
     26        "Siege": 0,
    2527        "Ship": 0,
    2628        "Trader": 0,
    2729        "total": 0
     
    3335        "Cavalry": 0,
    3436        "Champion": 0,
    3537        "Hero": 0,
     38        "Siege": 0,
    3639        "Ship": 0,
    3740        "Trader": 0,
    3841        "total": 0
     
    4548        "Cavalry": 0,
    4649        "Champion": 0,
    4750        "Hero": 0,
     51        "Siege": 0,
    4852        "Ship": 0,
    4953        "Trader": 0,
    5054        "total": 0
    5155    };
    5256    this.enemyUnitsKilledValue = 0;
     57    this.unitsCaptured = {
     58        "Infantry": 0,
     59        "Worker": 0,
     60        "Female": 0,
     61        "Cavalry": 0,
     62        "Champion": 0,
     63        "Hero": 0,
     64        "Siege": 0,
     65        "Ship": 0,
     66        "Trader": 0,
     67        "total": 0
     68    };
     69    this.unitsCapturedValue = 0;
    5370
    5471    this.buildingsClasses = [
    5572        "House",
     
    163180        "unitsLostValue": this.unitsLostValue,
    164181        "enemyUnitsKilled": this.enemyUnitsKilled,
    165182        "enemyUnitsKilledValue": this.enemyUnitsKilledValue,
     183        "unitsCaptured": this.unitsCaptured,
     184        "unitsCapturedValue": this.unitsCapturedValue,
    166185        "buildingsConstructed": this.buildingsConstructed,
    167186        "buildingsLost": this.buildingsLost,
    168187        "buildingsLostValue": this.buildingsLostValue,
     
    308327    }
    309328};
    310329
    311 StatisticsTracker.prototype.CapturedBuilding = function(capturedBuilding)
     330StatisticsTracker.prototype.CapturedEntity = function(capturedEntity)
    312331{
    313     let cmpCapturedBuildingIdentity = Engine.QueryInterface(capturedBuilding, IID_Identity);
    314     if (!cmpCapturedBuildingIdentity)
     332    let cmpCapturedEntityIdentity = Engine.QueryInterface(capturedEntity, IID_Identity);
     333    if (!cmpCapturedEntityIdentity)
    315334        return;
    316335
    317     for (let type of this.buildingsClasses)
    318         this.CounterIncrement(cmpCapturedBuildingIdentity, "buildingsCaptured", type);
     336    if (cmpCapturedEntityIdentity.HasClass("Unit"))
     337    {
     338        for (let type of this.unitsClasses)
     339            this.CounterIncrement(cmpCapturedEntityIdentity, "unitsCaptured", type);
    319340
    320     ++this.buildingsCaptured.total;
     341        ++this.unitsCaptured.total;
    321342
    322     let cmpCost = Engine.QueryInterface(capturedBuilding, IID_Cost);
    323     if (!cmpCost)
    324         return;
     343        let cmpCost = Engine.QueryInterface(capturedEntity, IID_Cost);
     344        if (!cmpCost)
     345            return;
    325346
    326     let costs = cmpCost.GetResourceCosts();
    327     for (let type in costs)
    328         this.buildingsCapturedValue += costs[type];
     347        let costs = cmpCost.GetResourceCosts();
     348        for (let type in costs)
     349            this.unitsCapturedValue += costs[type];
     350    }
     351
     352    if (cmpCapturedEntityIdentity.HasClass("Structure"))
     353    {
     354        for (let type of this.buildingsClasses)
     355            this.CounterIncrement(cmpCapturedEntityIdentity, "buildingsCaptured", type);
     356
     357        ++this.buildingsCaptured.total;
     358
     359        let cmpCost = Engine.QueryInterface(capturedEntity, IID_Cost);
     360        if (!cmpCost)
     361            return;
     362
     363        let costs = cmpCost.GetResourceCosts();
     364        for (let type in costs)
     365            this.buildingsCapturedValue += costs[type];
     366    }
    329367};
    330368
    331369/**
  • data/mods/public/simulation/components/tests/test_GuiInterface.js

     
    535535    },
    536536    buildingAI: null,
    537537    heal: null,
     538    loot: null,
    538539    obstruction: null,
    539540    turretParent: null,
    540541    promotion: null,