From d8f17ac61ff09eabb102604683a5c659ce768bec Mon Sep 17 00:00:00 2001
From: Karamel <karamel@creativekara.fr>
Date: Thu, 22 Oct 2015 21:21:53 +0200
Subject: [PATCH] Fix promotion of dead units
---
binaries/data/mods/public/simulation/components/Promotion.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/binaries/data/mods/public/simulation/components/Promotion.js b/binaries/data/mods/public/simulation/components/Promotion.js
index 58fab25..a7c57cc 100644
a
|
b
|
Promotion.prototype.GetPromotedTemplateName = function()
|
30 | 30 | |
31 | 31 | Promotion.prototype.Promote = function(promotedTemplateName) |
32 | 32 | { |
| 33 | // If the unit is dead, don't promote it |
| 34 | var cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health); |
| 35 | if(cmpCurrentUnitHealth.GetHitpoints() == 0) |
| 36 | return; |
33 | 37 | // Create promoted unit entity |
34 | 38 | var promotedUnitEntity = Engine.AddEntity(promotedTemplateName); |
35 | 39 | |
… |
… |
Promotion.prototype.Promote = function(promotedTemplateName)
|
52 | 56 | cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner()); |
53 | 57 | |
54 | 58 | // change promoted unit health to the same percent of hitpoints as unit had before promotion |
55 | | var cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health); |
56 | 59 | var cmpPromotedUnitHealth = Engine.QueryInterface(promotedUnitEntity, IID_Health); |
57 | 60 | var healthFraction = Math.max(0, Math.min(1, cmpCurrentUnitHealth.GetHitpoints() / cmpCurrentUnitHealth.GetMaxHitpoints())); |
58 | 61 | var promotedUnitHitpoints = Math.round(cmpPromotedUnitHealth.GetMaxHitpoints() * healthFraction); |