diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 1f40495a..80148e8b 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -2508,7 +2508,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { } if(shouldApplyAttackBoost == true) { - //printf("APPLYING ATTACK BOOST START to unit [%s - %d] from unit [%s - %d]\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("=== APPLYING ATTACK BOOST START to unit [%s - %d] from unit [%s - %d] hp: %d\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId(),hp); UnitAttackBoostEffect *effect = new UnitAttackBoostEffect(); effect->boost = boost; @@ -2616,6 +2616,9 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { //printf("APPLYING ATTACK BOOST END to unit [%s - %d] from unit [%s - %d]\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId()); } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("APPLIED ATTACK BOOST START to unit [%s - %d] from unit [%s - %d] hp: %d\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId(),hp); + return shouldApplyAttackBoost; } @@ -2626,7 +2629,7 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) { throw megaglest_runtime_error(szBuf); } - //printf("DE-APPLYING ATTACK BOOST START to unit [%s - %d] from unit [%s - %d]\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("=== DE-APPLYING ATTACK BOOST START to unit [%s - %d] from unit [%s - %d] hp: %d\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId(),hp); bool wasAlive = alive; int originalHp = hp; @@ -2722,6 +2725,8 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) { } } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("DE-APPLIED ATTACK BOOST START to unit [%s - %d] from unit [%s - %d] hp: %d\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId(),hp); + //printf("DE-APPLYING ATTACK BOOST END to unit [%s - %d] from unit [%s - %d]\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId()); } diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 1b3a1272..7aceea57 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -928,10 +928,13 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { prodSpeedIsMultiplier = ut->getProdSpeedIsMultiplier(); if(ut->getMaxHpIsMultiplier() == true) { + //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)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()); } else { maxHp -= ut->getMaxHp(); @@ -939,11 +942,13 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { maxHpRegeneration -= ut->getMaxHpRegeneration(); } } + enforceMinimumValue(0,maxHp); + enforceMinimumValue(0,maxHpRegeneration); if(ut->getMaxEpIsMultiplier() == true) { maxEp -= ((double)unit->getEp() * ((double)ut->getMaxEp() / (double)100)); if(ut->getMaxEpRegeneration() != 0) { - maxEpRegeneration += ((double)unit->getType()->getEpRegeneration() + ((double)max(maxEp,unit->getEp()) * ((double)ut->getMaxEpRegeneration() / (double)100))); + maxEpRegeneration -= ((double)unit->getType()->getEpRegeneration() + ((double)max(maxEp,unit->getEp()) * ((double)ut->getMaxEpRegeneration() / (double)100))); } } else { @@ -952,6 +957,8 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { maxEpRegeneration -= ut->getMaxEpRegeneration(); } } + enforceMinimumValue(0,maxEp); + enforceMinimumValue(0,maxEpRegeneration); if(ut->getSightIsMultiplier() == true) { sight -= ((double)unit->getType()->getSight() * ((double)ut->getSight() / (double)100)); @@ -959,6 +966,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { else { sight -= ut->getSight(); } + enforceMinimumValue(0,sight); if(ut->getArmorIsMultiplier() == true) { armor -= ((double)unit->getType()->getArmor() * ((double)ut->getArmor() / (double)100)); @@ -966,6 +974,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { else { armor -= ut->getArmor(); } + enforceMinimumValue(0,armor); if(ut->getAttackStrengthIsMultiplier() == true) { for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { @@ -973,24 +982,29 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { const AttackSkillType *ast = dynamic_cast(skillType); if(ast != NULL) { attackStrengthMultiplierValueList[ast->getName()] -= ((double)ast->getAttackStrength() * ((double)ut->getAttackStrength(NULL) / (double)100)); + enforceMinimumValue(0,attackStrengthMultiplierValueList[ast->getName()]); } } } else { attackStrength -= ut->getAttackStrength(NULL); + enforceMinimumValue(0,attackStrength); } + if(ut->getAttackRangeIsMultiplier() == true) { for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { const SkillType *skillType = unit->getType()->getSkillType(i); const AttackSkillType *ast = dynamic_cast(skillType); if(ast != NULL) { attackRangeMultiplierValueList[ast->getName()] -= ((double)ast->getAttackRange() * ((double)ut->getAttackRange(NULL) / (double)100)); + enforceMinimumValue(0,attackRangeMultiplierValueList[ast->getName()]); } } } else { attackRange -= ut->getAttackRange(NULL); + enforceMinimumValue(0,attackRange); } if(ut->getMoveSpeedIsMultiplier() == true) { @@ -1001,6 +1015,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { const MoveSkillType *mst = dynamic_cast(skillType); if(mst != NULL) { moveSpeedIsMultiplierValueList[mst->getName()] -= ((double)mst->getSpeed() * ((double)ut->getMoveSpeed(NULL) / (double)100)); + enforceMinimumValue(0,moveSpeedIsMultiplierValueList[mst->getName()]); } } @@ -1008,6 +1023,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { } else { moveSpeed -= ut->getMoveSpeed(NULL); + enforceMinimumValue(0,moveSpeed); } if(ut->getProdSpeedIsMultiplier() == true) { @@ -1016,19 +1032,23 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { const ProduceSkillType *pst = dynamic_cast(skillType); if(pst != NULL) { prodSpeedProduceIsMultiplierValueList[pst->getName()] -= ((double)pst->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100)); + enforceMinimumValue(0,prodSpeedProduceIsMultiplierValueList[pst->getName()]); } const UpgradeSkillType *ust = dynamic_cast(skillType); if(ust != NULL) { prodSpeedUpgradeIsMultiplierValueList[ust->getName()] -= ((double)ust->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100)); + enforceMinimumValue(0,prodSpeedUpgradeIsMultiplierValueList[ust->getName()]); } const MorphSkillType *mst = dynamic_cast(skillType); if(mst != NULL) { prodSpeedMorphIsMultiplierValueList[mst->getName()] -= ((double)mst->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100)); + enforceMinimumValue(0,prodSpeedMorphIsMultiplierValueList[mst->getName()]); } } } else { prodSpeed -= ut->getProdSpeed(NULL); + enforceMinimumValue(0,prodSpeed); } } diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index 167282fc..e707e04e 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -239,6 +239,13 @@ int round(float f); //misc bool checkVersionComptability(string clientVersionString, string serverVersionString); +template +void enforceMinimumValue(T minValue, T &value) { + if(value < minValue) { + value = minValue; + } +} + template void deleteValues(T beginIt, T endIt){ for(T it= beginIt; it!=endIt; ++it){