Fix cc1ea7cca0 error in Promotion when promoting an entity that died on the same turn.

Add a regression test for this case.

Reported By: elexis
Differential Revision: https://code.wildfiregames.com/D2227
This was SVN commit r22808.
This commit is contained in:
wraitii
2019-08-31 12:38:38 +00:00
parent 395fae107b
commit 381bdcbade
2 changed files with 14 additions and 0 deletions
@@ -33,7 +33,10 @@ Promotion.prototype.Promote = function(promotedTemplateName)
// If the unit is dead, don't promote it
let cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
if (cmpHealth && cmpHealth.GetHitpoints() == 0)
{
this.promotedUnitEntity = INVALID_ENTITY;
return;
}
// Save the entity id.
this.promotedUnitEntity = ChangeEntityTemplate(this.entity, promotedTemplateName);
@@ -63,4 +63,15 @@ cmpPromotion.IncreaseXp(4200);
TS_ASSERT_EQUALS(cmpPromotion.entity, 62);
TS_ASSERT_EQUALS(cmpPromotion.template.Entity, "end");
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 200);
cmpPromotion = ConstructComponent(ENT_ID, "Promotion", {
"Entity": "template_b",
"RequiredXp": 1000
});
let cmpHealth = AddMock(ENT_ID, IID_Health, {
"GetHitpoints": () => 0,
});
cmpPromotion.IncreaseXp(1000);
})();