From 7bc9394e8538bde54f90a5fcd0f1a548f0c58def Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 22 Jul 2011 20:06:48 +0000 Subject: [PATCH] - fixed some bugs around hp regeneration and attack-boost --- source/glest_game/type_instances/unit.cpp | 34 +++++++++++++++-------- source/glest_game/types/upgrade_type.cpp | 8 +++--- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 0ea06f0c..a83bf8ee 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1731,11 +1731,16 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { //regenerate hp upgrade / or boost if(totalUpgrade.getMaxHpRegeneration() != 0) { checkItemInVault(&this->hp,this->hp); + + //printf("BEFORE Apply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp); + hp += (totalUpgrade.getMaxHpRegeneration() - prevMaxHpRegen); - if(hp > totalUpgrade.getMaxHp()) { - hp = totalUpgrade.getMaxHp(); - } + //if(hp > type->getTotalMaxHp(&totalUpgrade)) { + // hp = type->getTotalMaxHp(&totalUpgrade); + //} addItemToVault(&this->hp,this->hp); + + //printf("AFTER Apply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp); } //printf("#2 wasAlive = %d hp = %d boosthp = %d\n",wasAlive,hp,boost->boostUpgrade.getMaxHp()); @@ -1810,11 +1815,16 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) { //regenerate hp upgrade / or boost if(totalUpgrade.getMaxHpRegeneration() != 0) { checkItemInVault(&this->hp,this->hp); + + //printf("BEFORE DeApply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp); + hp -= (totalUpgrade.getMaxHpRegeneration() - prevMaxHpRegen); - if(hp > totalUpgrade.getMaxHp()) { - hp = totalUpgrade.getMaxHp(); - } + //if(hp > totalUpgrade.getMaxHp()) { + // hp = totalUpgrade.getMaxHp(); + //} addItemToVault(&this->hp,this->hp); + + //printf("AFTER DeApply Hp Regen max = %d, prev = %d, hp = %d\n",totalUpgrade.getMaxHpRegeneration(),prevMaxHpRegen,hp); } if(wasAlive == true) { @@ -2101,10 +2111,10 @@ string Unit::getDesc() const { //str += "\n"+lang.get("Hp")+ ": " + intToStr(hp) + "/" + intToStr(type->getTotalMaxHp(&totalUpgrade)) + " [" + floatToStr(getHpRatio()) + "] [" + floatToStr(animProgress) + "]"; str += "\n"+lang.get("Hp")+ ": " + intToStr(hp) + "/" + intToStr(type->getTotalMaxHp(&totalUpgrade)); - if(type->getHpRegeneration() != 0) { + if(type->getHpRegeneration() != 0 || totalUpgrade.getMaxHpRegeneration() != 0) { str+= " (" + lang.get("Regeneration") + ": " + intToStr(type->getHpRegeneration()); - if(type->getTotalMaxHpRegeneration(&totalUpgrade) != 0) { - str+= "/" + intToStr(type->getTotalMaxHpRegeneration(&totalUpgrade)); + if(totalUpgrade.getMaxHpRegeneration() != 0) { + str+= "+" + intToStr(totalUpgrade.getMaxHpRegeneration()); } str+= ")"; } @@ -2113,10 +2123,10 @@ string Unit::getDesc() const { if(getType()->getMaxEp()!=0){ str+= "\n" + lang.get("Ep")+ ": " + intToStr(ep) + "/" + intToStr(type->getTotalMaxEp(&totalUpgrade)); } - if(type->getEpRegeneration() != 0) { + if(type->getEpRegeneration() != 0 || totalUpgrade.getMaxEpRegeneration() != 0) { str+= " (" + lang.get("Regeneration") + ": " + intToStr(type->getEpRegeneration()); - if(type->getTotalMaxEpRegeneration(&totalUpgrade) != 0) { - str += "/" + intToStr(type->getTotalMaxEpRegeneration(&totalUpgrade)); + if(totalUpgrade.getMaxEpRegeneration() != 0) { + str += "+" + intToStr(totalUpgrade.getMaxEpRegeneration()); } str+= ")"; } diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index aba7c3be..b839ad16 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -460,7 +460,7 @@ void TotalUpgrade::sum(const UpgradeTypeBase *ut, const Unit *unit) { //printf("#1 Maxhp maxHp = %d, unit->getHp() = %d ut->getMaxHp() = %d\n",maxHp,unit->getHp(),ut->getMaxHp()); maxHp += ((double)unit->getHp() * ((double)ut->getMaxHp() / (double)100)); if(ut->getMaxHpRegeneration() != 0) { - maxHpRegeneration += ((double)unit->getType()->getHpRegeneration() * ((double)ut->getMaxHpRegeneration() / (double)100)); + maxHpRegeneration += ((double)unit->getType()->getHpRegeneration() + ((double)max(maxHp,unit->getHp()) * ((double)ut->getMaxHpRegeneration() / (double)100))); } //printf("#1.1 Maxhp maxHp = %d, unit->getHp() = %d ut->getMaxHp() = %d\n",maxHp,unit->getHp(),ut->getMaxHp()); } @@ -475,7 +475,7 @@ void TotalUpgrade::sum(const UpgradeTypeBase *ut, const Unit *unit) { if(ut->getMaxEpIsMultiplier() == true) { maxEp += ((double)unit->getEp() * ((double)ut->getMaxEp() / (double)100)); if(ut->getMaxHpRegeneration() != 0) { - maxEpRegeneration += ((double)unit->getType()->getEpRegeneration() * ((double)ut->getMaxEpRegeneration() / (double)100)); + maxEpRegeneration += ((double)unit->getType()->getEpRegeneration() + ((double)max(maxEp,unit->getEp()) * ((double)ut->getMaxEpRegeneration() / (double)100))); } } else { @@ -583,7 +583,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { if(ut->getMaxHpIsMultiplier() == true) { maxHp -= ((double)unit->getHp() * ((double)ut->getMaxHp() / (double)100)); if(ut->getMaxHpRegeneration() != 0) { - maxHpRegeneration -= ((double)unit->getType()->getHpRegeneration() * ((double)ut->getMaxHpRegeneration() / (double)100)); + maxHpRegeneration -= ((double)unit->getType()->getHpRegeneration() + ((double)max(maxHp,unit->getHp()) * ((double)ut->getMaxHpRegeneration() / (double)100))); } } else { @@ -596,7 +596,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { if(ut->getMaxEpIsMultiplier() == true) { maxEp -= ((double)unit->getEp() * ((double)ut->getMaxEp() / (double)100)); if(ut->getMaxEpRegeneration() != 0) { - maxEpRegeneration += ((double)unit->getType()->getEpRegeneration() * ((double)ut->getMaxEpRegeneration() / (double)100)); + maxEpRegeneration += ((double)unit->getType()->getEpRegeneration() + ((double)max(maxEp,unit->getEp()) * ((double)ut->getMaxEpRegeneration() / (double)100))); } } else {