From 381bdcbade7128c293ac4ca876be4fc44867bf9a Mon Sep 17 00:00:00 2001 From: wraitii Date: Sat, 31 Aug 2019 12:38:38 +0000 Subject: [PATCH] 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. --- .../mods/public/simulation/components/Promotion.js | 3 +++ .../simulation/components/tests/test_Promotion.js | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/binaries/data/mods/public/simulation/components/Promotion.js b/binaries/data/mods/public/simulation/components/Promotion.js index e764434ea7..a11cde36b7 100644 --- a/binaries/data/mods/public/simulation/components/Promotion.js +++ b/binaries/data/mods/public/simulation/components/Promotion.js @@ -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); diff --git a/binaries/data/mods/public/simulation/components/tests/test_Promotion.js b/binaries/data/mods/public/simulation/components/tests/test_Promotion.js index 1875f306c3..76facdebbe 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Promotion.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Promotion.js @@ -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); })();