Ticket #2405: Cost_js_fix_population_cost_and_bonus_v2.patch
File Cost_js_fix_population_cost_and_bonus_v2.patch, 5.0 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Cost.js
33 33 34 34 Cost.prototype.Init = function() 35 35 { 36 this.populationCost = +this.template.Population; 36 37 this.populationBonus = +this.template.PopulationBonus; 37 38 }; 38 39 39 40 Cost.prototype.GetPopCost = function() 40 41 { 41 return +this.template.Population;42 return this.populationCost; 42 43 }; 43 44 44 45 Cost.prototype.GetPopBonus = function() … … 87 88 if (msg.component != "Cost") 88 89 return; 89 90 90 // foundations shouldn't give a pop bonus 91 // foundations shouldn't give a pop bonus and a pop cost 91 92 var cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation) 92 93 if (cmpFoundation) 93 94 return; 94 95 96 // update the population costs 97 var newPopCost = ApplyValueModificationsToEntity("Cost/Population", +this.template.Population, this.entity); 98 var popCostDifference = newPopCost - this.populationCost; 99 if (popCostDifference) 100 this.populationCost = newPopCost; 101 95 102 // update the population bonuses 96 103 var newPopBonus = ApplyValueModificationsToEntity("Cost/PopulationBonus", +this.template.PopulationBonus, this.entity); 97 104 var popDifference = newPopBonus - this.populationBonus; 98 if ( !popDifference)99 return;105 if (popDifference) 106 this.populationBonus = newPopBonus; 100 107 101 108 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 102 109 if (cmpPlayer) 103 cmpPlayer.AddPopulationBonuses(popDifference); 110 { 111 if (popCostDifference) 112 cmpPlayer.AddPopulation(popCostDifference); 113 if (popDifference) 114 cmpPlayer.AddPopulationBonuses(popDifference); 115 } 104 116 }; 105 117 106 118 Engine.RegisterComponentType(IID_Cost, "Cost", Cost); -
binaries/data/mods/public/simulation/components/Player.js
112 112 return this.popUsed; 113 113 }; 114 114 115 Player.prototype.AddPopulation = function(num) 116 { 117 this.popUsed += num; 118 }; 119 115 120 Player.prototype.SetPopulationBonuses = function(num) 116 121 { 117 122 this.popBonuses = num; -
binaries/data/mods/public/simulation/components/ProductionQueue.js
244 244 if (type == "unit") 245 245 { 246 246 // Find the template data so we can determine the build costs 247 var cmpTemp Man= Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);248 var template = cmpTemp Man.GetTemplate(templateName);247 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 248 var template = cmpTemplateManager.GetTemplate(templateName); 249 249 if (!template) 250 250 return; 251 251 if (template.Promotion) … … 275 275 totalCosts[r] = Math.floor(count * costs[r]); 276 276 } 277 277 278 var population = +template.Cost.Population;278 var population = ApplyValueModificationsToTemplate("Cost/Population", +template.Cost.Population, cmpPlayer.GetPlayerID(), template); 279 279 280 280 // TrySubtractResources should report error to player (they ran out of resources) 281 281 if (!cmpPlayer.TrySubtractResources(totalCosts)) … … 309 309 else if (type == "technology") 310 310 { 311 311 // Load the technology template 312 var cmpTech TempMan= Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);313 var template = cmpTech TempMan.GetTemplate(templateName);312 var cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager); 313 var template = cmpTechnologyTemplateManager.GetTemplate(templateName); 314 314 if (!template) 315 315 return; 316 316 var cmpPlayer = QueryOwnerInterface(this.entity); … … 395 395 // Update entity count in the EntityLimits component 396 396 if (item.unitTemplate) 397 397 { 398 var cmpTemp Man= Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);399 var template = cmpTemp Man.GetTemplate(item.unitTemplate);398 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 399 var template = cmpTemplateManager.GetTemplate(item.unitTemplate); 400 400 if (template.TrainingRestrictions) 401 401 { 402 402 var unitCategory = template.TrainingRestrictions.Category; … … 665 665 // If the item is a unit then do population checks 666 666 if (item.unitTemplate) 667 667 { 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 668 672 // Batch's training hasn't started yet. 669 673 // Try to reserve the necessary population slots 670 674 item.neededSlots = cmpPlayer.TryReservePopulationSlots(item.population * item.count);