Ticket #3818: costroundinthesim.diff

File costroundinthesim.diff, 4.7 KB (added by fatherbushido, 8 years ago)
  • binaries/data/mods/public/globalscripts/Templates.js

    function GetTemplateDataHelper(template,  
    188188        };
    189189
    190190    if (template.Cost)
    191191    {
    192192        ret.cost = {};
    193         if (template.Cost.Resources.food)
    194             ret.cost.food = getEntityValue("Cost/Resources/food");
    195 
    196         if (template.Cost.Resources.wood)
    197             ret.cost.wood = getEntityValue("Cost/Resources/wood");
    198 
    199         if (template.Cost.Resources.stone)
    200             ret.cost.stone = getEntityValue("Cost/Resources/stone");
    201 
    202         if (template.Cost.Resources.metal)
    203             ret.cost.metal = getEntityValue("Cost/Resources/metal");
     193        for (let r in template.Cost.Resources)
     194            ret.cost[r] = Math.round(getEntityValue("Cost/Resources/"+r));
    204195
    205196        if (template.Cost.Population)
    206197            ret.cost.population = getEntityValue("Cost/Population");
    207198
    208199        if (template.Cost.PopulationBonus)
  • binaries/data/mods/public/gui/common/tooltips.js

    function getBuildRateTooltip(template)  
    312312 */
    313313function multiplyEntityCosts(template, trainNum)
    314314{
    315315    let totalCosts = {};
    316316    for (let r in template.cost)
    317         totalCosts[r] = Math.floor(template.cost[r] * trainNum);
     317        totalCosts[r] = template.cost[r] * trainNum;
    318318
    319319    return totalCosts;
    320320}
    321321
    322322/**
  • binaries/data/mods/public/simulation/ai/common-api/entity.js

    m.Template = m.Class({  
    107107        if (!this.get("Cost"))
    108108            return undefined;
    109109
    110110        let ret = {};
    111111        for (let type in this.get("Cost/Resources"))
    112             ret[type] = +this.get("Cost/Resources/" + type);
     112            ret[type] = Math.round(+this.get("Cost/Resources/" + type));
    113113        return ret;
    114114    },
    115115
    116116    "costSum": function(productionQueue) {
    117117        let cost = this.cost(productionQueue);
  • binaries/data/mods/public/simulation/components/Cost.js

    Cost.prototype.GetResourceCosts = functi  
    5858{
    5959    if (!owner)
    6060    {
    6161        let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    6262        if (!cmpOwnership)
    63             error("GetResourceCost called without valid ownership");
     63            error("GetResourceCosts called without valid ownership");
    6464        else
    6565            owner = cmpOwnership.GetOwner();
    6666    }
    6767
    6868    let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    6969    let entityTemplateName = cmpTemplateManager.GetCurrentTemplateName(this.entity);
    7070    let entityTemplate = cmpTemplateManager.GetTemplate(entityTemplateName);
    7171
    7272    let costs = {};
    7373    for (let r in this.template.Resources)
    74         costs[r] = ApplyValueModificationsToTemplate("Cost/Resources/"+r, +this.template.Resources[r], owner, entityTemplate);
     74        costs[r] = Math.round(ApplyValueModificationsToTemplate("Cost/Resources/"+r, +this.template.Resources[r], owner, entityTemplate));
    7575    return costs;
    7676};
    7777
    7878Cost.prototype.OnOwnershipChanged = function(msg)
    7979{
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

    ProductionQueue.prototype.AddBatch = fun  
    293293            var buildTime = ApplyValueModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, cmpPlayer.GetPlayerID(), template);
    294294            var time = timeMult * buildTime;
    295295
    296296            for (var r in template.Cost.Resources)
    297297            {
    298                 costs[r] = ApplyValueModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], cmpPlayer.GetPlayerID(), template);
    299                 totalCosts[r] = Math.floor(count * costs[r]);
     298                costs[r] = Math.round(ApplyValueModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], cmpPlayer.GetPlayerID(), template));
     299                totalCosts[r] = count * costs[r];
    300300            }
    301 
    302301            var population = ApplyValueModificationsToTemplate("Cost/Population",  +template.Cost.Population, cmpPlayer.GetPlayerID(), template);
    303302
    304303            // TrySubtractResources should report error to player (they ran out of resources)
    305304            if (!cmpPlayer.TrySubtractResources(totalCosts))
    306305                return;