1
0
forked from 0ad/0ad

Fix double resource subtraction on training stop.

Reported by @KarloManco at
https://wildfiregames.com/forum/topic/102402-resourcesused-counter-bug/.
Introduced in 0c4f59d0a7.

Fixes #6670

This was SVN commit r27321.
This commit is contained in:
Freagarach 2022-12-30 07:16:58 +00:00
parent 3b4ffea4a6
commit 89c78ee1f3

View File

@ -145,19 +145,15 @@ Trainer.prototype.Item.prototype.Stop = function()
cmpPlayerEntityLimits.ChangeMatchCount(this.templateName, -this.count);
}
const cmpStatisticsTracker = QueryPlayerIDInterface(this.player, IID_StatisticsTracker);
const totalCosts = {};
for (const resource in this.resources)
{
totalCosts[resource] = Math.floor(this.count * this.resources[resource]);
if (cmpStatisticsTracker)
cmpStatisticsTracker.IncreaseResourceUsedCounter(resource, -totalCosts[resource]);
}
if (cmpPlayer)
{
if (this.started)
cmpPlayer.UnReservePopulationSlots(this.population * this.count);
const totalCosts = {};
for (const resource in this.resources)
totalCosts[resource] = Math.floor(this.count * this.resources[resource]);
cmpPlayer.RefundResources(totalCosts);
cmpPlayer.UnBlockTraining();
}