1
0
forked from 0ad/0ad

Change promoted unit health to the same percent of hitpoints as unit had before promotion. Closes #922.

This was SVN commit r9984.
This commit is contained in:
fcxSanya 2011-08-09 18:42:21 +00:00
parent c513b5e35e
commit 0adcad8662

View File

@ -51,6 +51,13 @@ Promotion.prototype.Promote = function(promotedTemplateName)
var cmpPromotedUnitOwnership = Engine.QueryInterface(promotedUnitEntity, IID_Ownership);
cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner());
// change promoted unit health to the same percent of hitpoints as unit had before promotion
var cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health);
var cmpPromotedUnitHealth = Engine.QueryInterface(promotedUnitEntity, IID_Health);
var healthFraction = Math.max(0, Math.min(1, cmpCurrentUnitHealth.GetHitpoints() / cmpCurrentUnitHealth.GetMaxHitpoints()));
var promotedUnitHitpoints = Math.round(cmpPromotedUnitHealth.GetMaxHitpoints() * healthFraction);
cmpPromotedUnitHealth.SetHitpoints(promotedUnitHitpoints);
var cmpPromotedUnitPromotion = Engine.QueryInterface(promotedUnitEntity, IID_Promotion);
if (cmpPromotedUnitPromotion)
cmpPromotedUnitPromotion.IncreaseXp(this.currentXp);