1
0
forked from 0ad/0ad

rounding needed for houses with popBonus%5 != 0, fixes #3328

This was SVN commit r16848.
This commit is contained in:
mimo 2015-07-12 15:23:34 +00:00
parent 0f10e21ab1
commit f74215e96c
2 changed files with 6 additions and 4 deletions

View File

@ -229,7 +229,8 @@ AIInterface.prototype.OnTemplateModification = function(msg)
let oldValue = +item;
let newValue = ApplyValueModificationsToTemplate(valName, oldValue, msg.player, template);
// Apply the same roundings as in the components
if (valName === "Health/Max" || valName === "Player/MaxPopulation")
if (valName === "Health/Max" || valName === "Player/MaxPopulation"
|| valName === "Cost/Population" || valName === "Cost/PopulationBonus")
newValue = Math.round(newValue);
// TODO in some cases, we can have two opposite changes which bring us to the old value,
@ -275,7 +276,8 @@ AIInterface.prototype.OnGlobalValueModification = function(msg)
let oldValue = +item;
let newValue = ApplyValueModificationsToEntity(valName, oldValue, ent);
// Apply the same roundings as in the components
if (valName === "Health/Max" || valName === "Player/MaxPopulation")
if (valName === "Health/Max" || valName === "Player/MaxPopulation"
|| valName === "Cost/Population" || valName === "Cost/PopulationBonus")
newValue = Math.round(newValue);
// TODO in some cases, we can have two opposite changes which bring us to the old value,
// and we should keep it. But how to distinguish it ?

View File

@ -94,12 +94,12 @@ Cost.prototype.OnValueModification = function(msg)
return;
// update the population costs
var newPopCost = ApplyValueModificationsToEntity("Cost/Population", +this.template.Population, this.entity);
var newPopCost = Math.round(ApplyValueModificationsToEntity("Cost/Population", +this.template.Population, this.entity));
var popCostDifference = newPopCost - this.populationCost;
this.populationCost = newPopCost;
// update the population bonuses
var newPopBonus = ApplyValueModificationsToEntity("Cost/PopulationBonus", +this.template.PopulationBonus, this.entity);
var newPopBonus = Math.round(ApplyValueModificationsToEntity("Cost/PopulationBonus", +this.template.PopulationBonus, this.entity));
var popDifference = newPopBonus - this.populationBonus;
this.populationBonus = newPopBonus;