Fix counting of arrows in buildings: don't remove entities twice from the garrisonholder. Fixes #3846

This was SVN commit r17938.
This commit is contained in:
sanderd17 2016-03-23 09:04:02 +00:00
parent e7deb587bb
commit 63d276b73b
2 changed files with 7 additions and 9 deletions

View File

@ -257,15 +257,10 @@ BuildingAI.prototype.GetGarrisonArrowClasses = function()
*/
BuildingAI.prototype.GetArrowCount = function()
{
let count = this.GetDefaultArrowCount();
let count = this.GetDefaultArrowCount() +
Math.round(this.archersGarrisoned * this.GetGarrisonArrowMultiplier());
let cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder);
if (cmpGarrisonHolder)
count += Math.round(this.archersGarrisoned * this.GetGarrisonArrowMultiplier());
if (this.GetMaxArrowCount() < count)
return this.GetMaxArrowCount();
return count;
return Math.min(this.GetMaxArrowCount(), count);
};
BuildingAI.prototype.SetUnitAITarget = function(ent)

View File

@ -698,6 +698,7 @@ GarrisonHolder.prototype.EjectOrKill = function(entities)
}
// And destroy all remaining entities
var killedEntities = [];
for each (var entity in entities)
{
var entityIndex = this.entities.indexOf(entity);
@ -707,9 +708,11 @@ GarrisonHolder.prototype.EjectOrKill = function(entities)
if (cmpHealth)
cmpHealth.Kill();
this.entities.splice(entityIndex, 1);
killedEntities.push(entity);
}
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed" : entities });
if (killedEntities.length > 0)
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed" : killedEntities });
this.UpdateGarrisonFlag();
};