Ticket #3236: Cost_js_fix_population_cost_and bonus.patch

File Cost_js_fix_population_cost_and bonus.patch, 3.3 KB (added by Vladislav Belov, 9 years ago)

Fix both issues (cost and bonus)

  • binaries/data/mods/public/simulation/components/Cost.js

     
    9797    var popDifference = newPopBonus - this.populationBonus;
    9898    if (!popDifference)
    9999        return;
     100    this.populationBonus = newPopBonus;
    100101
    101102    var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
    102103    if (cmpPlayer)
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

     
    244244        if (type == "unit")
    245245        {
    246246            // Find the template data so we can determine the build costs
    247             var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    248             var template = cmpTempMan.GetTemplate(templateName);
     247            var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
     248            var template = cmpTemplateManager.GetTemplate(templateName);
    249249            if (!template)
    250250                return;
    251251            if (template.Promotion)
     
    275275                totalCosts[r] = Math.floor(count * costs[r]);
    276276            }
    277277
    278             var population = +template.Cost.Population;
     278            var population = ApplyValueModificationsToTemplate("Cost/Population",  +template.Cost.Population, cmpPlayer.GetPlayerID(), template);
    279279
    280280            // TrySubtractResources should report error to player (they ran out of resources)
    281281            if (!cmpPlayer.TrySubtractResources(totalCosts))
     
    309309        else if (type == "technology")
    310310        {
    311311            // Load the technology template
    312             var cmpTechTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
    313             var template = cmpTechTempMan.GetTemplate(templateName);
     312            var cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
     313            var template = cmpTechnologyTemplateManager.GetTemplate(templateName);
    314314            if (!template)
    315315                return;
    316316            var cmpPlayer = QueryOwnerInterface(this.entity);
     
    395395        // Update entity count in the EntityLimits component
    396396        if (item.unitTemplate)
    397397        {
    398             var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    399             var template = cmpTempMan.GetTemplate(item.unitTemplate);
     398            var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
     399            var template = cmpTemplateManager.GetTemplate(item.unitTemplate);
    400400            if (template.TrainingRestrictions)
    401401            {
    402402                var unitCategory = template.TrainingRestrictions.Category;
     
    665665            // If the item is a unit then do population checks
    666666            if (item.unitTemplate)
    667667            {
     668                // If something change population cost
     669                var template = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).GetTemplate(item.unitTemplate);
     670                item.population = ApplyValueModificationsToTemplate("Cost/Population",  +template.Cost.Population, item.player, template);
     671               
    668672                // Batch's training hasn't started yet.
    669673                // Try to reserve the necessary population slots
    670674                item.neededSlots = cmpPlayer.TryReservePopulationSlots(item.population * item.count);