Ticket #4099: round_v2.patch

File round_v2.patch, 12.8 KB (added by Sandarac, 8 years ago)

In the summary screen, this only seems to be an obvious issue when calculating Resources Used. I didn't add Round to stats like "Units Trained".

  • binaries/data/mods/public/gui/common/tooltips.js

     
    300300{
    301301    let totalCosts = {};
    302302    for (let r in template.cost)
    303         totalCosts[r] = Math.floor(template.cost[r] * trainNum);
     303        totalCosts[r] = Math.round(template.cost[r] * trainNum);
    304304
    305305    return totalCosts;
    306306}
     
    315315
    316316    let totalCosts = multiplyEntityCosts(template, trainNum);
    317317    if (template.cost.time)
    318         totalCosts.time = Math.ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1));
     318        totalCosts.time = Math.round(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1));
    319319
    320320    let costs = [];
    321321    for (let type in template.cost)
     
    388388            // the tooltip for wall structures.
    389389            out.push(sprintf(translate("%(resourceIcon)s %(minimum)s to %(resourceIcon)s %(maximum)s"), {
    390390                "resourceIcon": costIcon(resource),
    391                 "minimum": Math.min.apply(Math, resourceCount[resource]),
    392                 "maximum": Math.max.apply(Math, resourceCount[resource])
     391                "minimum": Math.round(Math.min(...resourceCount[resource])),
     392                "maximum": Math.round(Math.max(...resourceCount[resource]))
    393393            }));
    394394    else
    395395        for (let i = 0; i < wallTypes.length; ++i)
  • binaries/data/mods/public/gui/session/selection_details.js

     
    5151        healthBarGarrison.size = healthSize;
    5252        healthGarrison.tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), {
    5353            "label": "[font=\"sans-bold-13\"]" + translate("Hitpoints:") + "[/font]",
    54             "current": Math.ceil(totalGarrisionHealth),
    55             "max": Math.ceil(maxGarrisionHealth)
     54            "current": Math.round(totalGarrisionHealth) || 1,
     55            "max": Math.round(maxGarrisionHealth) || 1
    5656        });
    5757    }
    5858}
     
    108108            // logic comes from Foundation component.
    109109            let speed = Math.pow(entState.foundation.numBuilders, 0.7);
    110110            let timeLeft = (1.0 - entState.foundation.progress / 100.0) * template.cost.time;
    111             let timeToCompletion = Math.ceil(timeLeft/speed);
     111            let timeToCompletion = Math.round(timeLeft/speed) || 1;
    112112            Engine.GetGUIObjectByName("health").tooltip = sprintf(translatePlural("This foundation will be completed in %(seconds)s second.", "This foundation will be completed in %(seconds)s seconds.", timeToCompletion), { "seconds": timeToCompletion });
    113113        }
    114114        else
     
    115115            Engine.GetGUIObjectByName("health").tooltip = "";
    116116
    117117        Engine.GetGUIObjectByName("healthStats").caption = sprintf(translate("%(hitpoints)s / %(maxHitpoints)s"), {
    118             "hitpoints": Math.ceil(entState.hitpoints),
    119             "maxHitpoints": Math.ceil(entState.maxHitpoints)
     118            "hitpoints": Math.round(entState.hitpoints) || 1,
     119            "maxHitpoints": Math.round(entState.maxHitpoints) || 1
    120120        });
    121121    }
    122122
     
    145145                size = setCaptureBarPart(i, size);
    146146
    147147        Engine.GetGUIObjectByName("captureStats").caption = sprintf(translate("%(capturePoints)s / %(maxCapturePoints)s"), {
    148             "capturePoints": Math.ceil(entState.capturePoints[entState.player]),
    149             "maxCapturePoints": Math.ceil(entState.maxCapturePoints)
     148            "capturePoints": Math.round(entState.capturePoints[entState.player]) || 1,
     149            "maxCapturePoints": Math.round(entState.maxCapturePoints) || 1
    150150        });
    151151    }
    152152
     
    178178    {
    179179        let resources = entState.resourceSupply.isInfinite ? translate("∞") :  // Infinity symbol
    180180            sprintf(translate("%(amount)s / %(max)s"), {
    181                 "amount": Math.ceil(+entState.resourceSupply.amount),
     181                "amount": Math.round(+entState.resourceSupply.amount) || 1,
    182182                "max": entState.resourceSupply.max
    183183            });
    184184
     
    236236        {
    237237            let speedup = Math.pow((entState.foundation.numBuilders+1)/entState.foundation.numBuilders, 0.7);
    238238            let timeLeft = (1.0 - entState.foundation.progress / 100.0) * template.cost.time;
    239             let timeSpeedup = Math.ceil(timeLeft - timeLeft/speedup);
     239            let timeSpeedup = Math.round(timeLeft - timeLeft/speedup) || 1;
    240240            Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = sprintf(translatePlural("Number of builders.\nTasking another to this foundation would speed construction up by %(speedup)s second.", "Number of builders.\nTasking another to this foundation would speed construction up by %(speedup)s seconds.", timeSpeedup), { "speedup": timeSpeedup });
    241241        }
    242242        else
     
    355355
    356356        Engine.GetGUIObjectByName("healthMultiple").tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), {
    357357            "label": "[font=\"sans-bold-13\"]" + translate("Hitpoints:") + "[/font]",
    358             "current": Math.ceil(averageHealth),
    359             "max": Math.ceil(maxHealth)
     358            "current": Math.round(averageHealth) || 1,
     359            "max": Math.round(maxHealth) || 1
    360360        });
    361361    }
    362362
     
    387387
    388388        Engine.GetGUIObjectByName("captureMultiple").tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), {
    389389            "label": "[font=\"sans-bold-13\"]" + translate("Capture points:") + "[/font]",
    390             "current": Math.ceil(capturePoints[playerID]),
    391             "max": Math.ceil(maxCapturePoints)
     390            "current": Math.round(capturePoints[playerID]) || 1,
     391            "max": Math.round(maxCapturePoints) || 1
    392392        });
    393393    }
    394394
  • binaries/data/mods/public/gui/session/session.js

     
    831831        "[font=\"sans-bold-16\"]" + template.name.specific + "[/font]" + "\n" +
    832832            sprintf(translate("%(label)s %(current)s / %(max)s"), {
    833833                "label": "[font=\"sans-bold-13\"]" + translate("Health:") + "[/font]",
    834                 "current": Math.ceil(heroState.hitpoints),
    835                 "max": Math.ceil(heroState.maxHitpoints)
     834                "current": Math.round(heroState.hitpoints) || 1,
     835                "max": Math.round(heroState.maxHitpoints) || 1
    836836            }),
    837837        getAttackTooltip(heroState),
    838838        getArmorTooltip(heroState),
  • binaries/data/mods/public/gui/summary/counters.js

     
    3131    if (!divisor)
    3232        return "0%";
    3333
    34     return Math.floor(100 * divident / divisor) + "%";
     34    return Math.round(100 * divident / divisor) + "%";
    3535}
    3636
    3737function formatRatio(divident, divisor)
     
    8686            "totalSold": 0
    8787        };
    8888
    89     g_TeamHelperData[playerState.team].food += playerState.statistics.resourcesGathered.food;
    90     g_TeamHelperData[playerState.team].vegetarianFood += playerState.statistics.resourcesGathered.vegetarianFood;
     89    g_TeamHelperData[playerState.team].food += Math.round(playerState.statistics.resourcesGathered.food);
     90    g_TeamHelperData[playerState.team].vegetarianFood += Math.round(playerState.statistics.resourcesGathered.vegetarianFood);
    9191
    9292    g_TeamHelperData[playerState.team].female += playerState.statistics.unitsTrained.Female;
    9393    g_TeamHelperData[playerState.team].worker += playerState.statistics.unitsTrained.Worker;
     
    9595    g_TeamHelperData[playerState.team].enemyUnitsKilled += playerState.statistics.enemyUnitsKilled.total;
    9696    g_TeamHelperData[playerState.team].unitsLost += playerState.statistics.unitsLost.total;
    9797
    98     g_TeamHelperData[playerState.team].percentMapControlled = playerState.statistics.teamPercentMapControlled;
    99     g_TeamHelperData[playerState.team].peakPercentMapControlled = playerState.statistics.teamPeakPercentMapControlled;
     98    g_TeamHelperData[playerState.team].percentMapControlled = Math.round(playerState.statistics.teamPercentMapControlled);
     99    g_TeamHelperData[playerState.team].peakPercentMapControlled = Math.round(playerState.statistics.teamPeakPercentMapControlled);
    100100
    101     g_TeamHelperData[playerState.team].percentMapExplored = playerState.statistics.teamPercentMapExplored;
     101    g_TeamHelperData[playerState.team].percentMapExplored = Math.round(playerState.statistics.teamPercentMapExplored);
    102102
    103103    for (let type in playerState.statistics.resourcesBought)
    104         g_TeamHelperData[playerState.team].totalBought += playerState.statistics.resourcesBought[type];
     104        g_TeamHelperData[playerState.team].totalBought += Math.round(playerState.statistics.resourcesBought[type]);
    105105
    106106    for (let type in playerState.statistics.resourcesSold)
    107         g_TeamHelperData[playerState.team].totalSold += playerState.statistics.resourcesSold[type];
     107        g_TeamHelperData[playerState.team].totalSold += Math.round(playerState.statistics.resourcesSold[type]);
    108108}
    109109
    110110function calculateEconomyScore(playerState)
     
    125125
    126126function calculateExplorationScore(playerState)
    127127{
    128     return playerState.statistics.percentMapExplored * 10;
     128    return Math.round(playerState.statistics.percentMapExplored * 10);
    129129}
    130130
    131131function calculateScoreTotal(playerState)
    132132{
    133     return calculateEconomyScore(playerState) +
     133    return Math.round(calculateEconomyScore(playerState) +
    134134        calculateMilitaryScore(playerState) +
    135         calculateExplorationScore(playerState);
     135        calculateExplorationScore(playerState));
    136136}
    137137
    138138function calculateScoreTeam(counters)
     
    253253    let type = g_ResourcesTypes[position];
    254254
    255255    return formatIncome(
    256         playerState.statistics.resourcesGathered[type],
    257         playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]);
     256        Math.round(playerState.statistics.resourcesGathered[type]),
     257        Math.round(playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]));
    258258}
    259259
    260260function calculateTotalResources(playerState)
     
    264264
    265265    for (let type of g_ResourcesTypes)
    266266    {
    267         totalGathered += playerState.statistics.resourcesGathered[type];
    268         totalUsed += playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type];
     267        totalGathered += Math.round(playerState.statistics.resourcesGathered[type]);
     268        totalUsed += Math.round(playerState.statistics.resourcesUsed[type] - playerState.statistics.resourcesSold[type]);
    269269    }
    270270
    271271    return formatIncome(totalGathered, totalUsed);
     
    273273
    274274function calculateTreasureCollected(playerState)
    275275{
    276     return playerState.statistics.treasuresCollected;
     276    return Math.round(playerState.statistics.treasuresCollected);
    277277}
    278278
    279279function calculateLootCollected(playerState)
    280280{
    281     return playerState.statistics.lootCollected;
     281    return Math.round(playerState.statistics.lootCollected);
    282282}
    283283
    284284function calculateTributeSent(playerState)
    285285{
    286286    return formatIncome(
    287         playerState.statistics.tributesSent,
    288         playerState.statistics.tributesReceived);
     287        Math.round(playerState.statistics.tributesSent),
     288        Math.round(playerState.statistics.tributesReceived));
    289289}
    290290
    291291function calculateResourcesTeam(counters)
     
    333333    let type = g_ResourcesTypes[position];
    334334
    335335    return formatIncome(
    336         playerState.statistics.resourcesBought[type],
    337         playerState.statistics.resourcesSold[type]);
     336        Math.round(playerState.statistics.resourcesBought[type]),
     337        Math.round(playerState.statistics.resourcesSold[type]));
    338338}
    339339
    340340function calculateBarterEfficiency(playerState)
     
    343343    let totalSold = 0;
    344344
    345345    for (let type in playerState.statistics.resourcesBought)
    346         totalBought += playerState.statistics.resourcesBought[type];
     346        totalBought += Math.round(playerState.statistics.resourcesBought[type]);
    347347
    348348    for (let type in playerState.statistics.resourcesSold)
    349         totalSold += playerState.statistics.resourcesSold[type];
     349        totalSold += Math.round(playerState.statistics.resourcesSold[type]);
    350350
    351351    return formatPercent(totalBought, totalSold);
    352352}
     
    353353
    354354function calculateTradeIncome(playerState)
    355355{
    356     return playerState.statistics.tradeIncome;
     356    return Math.round(playerState.statistics.tradeIncome);
    357357}
    358358
    359359function calculateMarketTeam(counters)
     
    400400function calculateVegetarianRatio(playerState)
    401401{
    402402    return formatPercent(
    403         playerState.statistics.resourcesGathered.vegetarianFood,
    404         playerState.statistics.resourcesGathered.food);
     403        Math.round(playerState.statistics.resourcesGathered.vegetarianFood),
     404        Math.round(playerState.statistics.resourcesGathered.food));
    405405}
    406406
    407407function calculateFeminization(playerState)
     
    420420
    421421function calculateMapExploration(playerState)
    422422{
    423     return playerState.statistics.percentMapExplored + "%";
     423    return Math.round(playerState.statistics.percentMapExplored) + "%";
    424424}
    425425
    426426function calculateMapFinalControl(playerState)
    427427{
    428     return playerState.statistics.percentMapControlled + "%";
     428    return Math.round(playerState.statistics.percentMapControlled) + "%";
    429429}
    430430
    431431function calculateMapPeakControl(playerState)
    432432{
    433     return playerState.statistics.peakPercentMapControlled + "%";
     433    return Math.round(playerState.statistics.peakPercentMapControlled) + "%";
    434434}
    435435
    436436function calculateMiscellaneous(counters)