Ticket #3544: 0001-Fix-promotion-of-dead-units.patch

File 0001-Fix-promotion-of-dead-units.patch, 1.7 KB (added by Karamel, 9 years ago)

Simple patch with HP check before promoting

  • binaries/data/mods/public/simulation/components/Promotion.js

    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()  
    3030
    3131Promotion.prototype.Promote = function(promotedTemplateName)
    3232{
     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;
    3337    // Create promoted unit entity
    3438    var promotedUnitEntity = Engine.AddEntity(promotedTemplateName);
    3539
    Promotion.prototype.Promote = function(promotedTemplateName)  
    5256    cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner());
    5357
    5458    // change promoted unit health to the same percent of hitpoints as unit had before promotion
    55     var cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health);
    5659    var cmpPromotedUnitHealth = Engine.QueryInterface(promotedUnitEntity, IID_Health);
    5760    var healthFraction = Math.max(0, Math.min(1, cmpCurrentUnitHealth.GetHitpoints() / cmpCurrentUnitHealth.GetMaxHitpoints()));
    5861    var promotedUnitHitpoints = Math.round(cmpPromotedUnitHealth.GetMaxHitpoints() * healthFraction);