bugfixes for attack boost did not properly rollback boost value sometimes for multiplier style boosts
This commit is contained in:
parent
4da10fc7fa
commit
4533da71bd
|
@ -2508,7 +2508,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shouldApplyAttackBoost == true) {
|
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();
|
UnitAttackBoostEffect *effect = new UnitAttackBoostEffect();
|
||||||
effect->boost = boost;
|
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());
|
//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;
|
return shouldApplyAttackBoost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2626,7 +2629,7 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||||
throw megaglest_runtime_error(szBuf);
|
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;
|
bool wasAlive = alive;
|
||||||
int originalHp = hp;
|
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());
|
//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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -928,10 +928,13 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) {
|
||||||
prodSpeedIsMultiplier = ut->getProdSpeedIsMultiplier();
|
prodSpeedIsMultiplier = ut->getProdSpeedIsMultiplier();
|
||||||
|
|
||||||
if(ut->getMaxHpIsMultiplier() == true) {
|
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));
|
maxHp -= ((double)unit->getHp() * ((double)ut->getMaxHp() / (double)100));
|
||||||
|
|
||||||
if(ut->getMaxHpRegeneration() != 0) {
|
if(ut->getMaxHpRegeneration() != 0) {
|
||||||
maxHpRegeneration -= ((double)unit->getType()->getHpRegeneration() + ((double)max(maxHp,unit->getHp()) * ((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());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
maxHp -= ut->getMaxHp();
|
maxHp -= ut->getMaxHp();
|
||||||
|
@ -939,11 +942,13 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) {
|
||||||
maxHpRegeneration -= ut->getMaxHpRegeneration();
|
maxHpRegeneration -= ut->getMaxHpRegeneration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
enforceMinimumValue(0,maxHp);
|
||||||
|
enforceMinimumValue(0,maxHpRegeneration);
|
||||||
|
|
||||||
if(ut->getMaxEpIsMultiplier() == true) {
|
if(ut->getMaxEpIsMultiplier() == true) {
|
||||||
maxEp -= ((double)unit->getEp() * ((double)ut->getMaxEp() / (double)100));
|
maxEp -= ((double)unit->getEp() * ((double)ut->getMaxEp() / (double)100));
|
||||||
if(ut->getMaxEpRegeneration() != 0) {
|
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 {
|
else {
|
||||||
|
@ -952,6 +957,8 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) {
|
||||||
maxEpRegeneration -= ut->getMaxEpRegeneration();
|
maxEpRegeneration -= ut->getMaxEpRegeneration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
enforceMinimumValue(0,maxEp);
|
||||||
|
enforceMinimumValue(0,maxEpRegeneration);
|
||||||
|
|
||||||
if(ut->getSightIsMultiplier() == true) {
|
if(ut->getSightIsMultiplier() == true) {
|
||||||
sight -= ((double)unit->getType()->getSight() * ((double)ut->getSight() / (double)100));
|
sight -= ((double)unit->getType()->getSight() * ((double)ut->getSight() / (double)100));
|
||||||
|
@ -959,6 +966,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) {
|
||||||
else {
|
else {
|
||||||
sight -= ut->getSight();
|
sight -= ut->getSight();
|
||||||
}
|
}
|
||||||
|
enforceMinimumValue(0,sight);
|
||||||
|
|
||||||
if(ut->getArmorIsMultiplier() == true) {
|
if(ut->getArmorIsMultiplier() == true) {
|
||||||
armor -= ((double)unit->getType()->getArmor() * ((double)ut->getArmor() / (double)100));
|
armor -= ((double)unit->getType()->getArmor() * ((double)ut->getArmor() / (double)100));
|
||||||
|
@ -966,6 +974,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) {
|
||||||
else {
|
else {
|
||||||
armor -= ut->getArmor();
|
armor -= ut->getArmor();
|
||||||
}
|
}
|
||||||
|
enforceMinimumValue(0,armor);
|
||||||
|
|
||||||
if(ut->getAttackStrengthIsMultiplier() == true) {
|
if(ut->getAttackStrengthIsMultiplier() == true) {
|
||||||
for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) {
|
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<const AttackSkillType *>(skillType);
|
const AttackSkillType *ast = dynamic_cast<const AttackSkillType *>(skillType);
|
||||||
if(ast != NULL) {
|
if(ast != NULL) {
|
||||||
attackStrengthMultiplierValueList[ast->getName()] -= ((double)ast->getAttackStrength() * ((double)ut->getAttackStrength(NULL) / (double)100));
|
attackStrengthMultiplierValueList[ast->getName()] -= ((double)ast->getAttackStrength() * ((double)ut->getAttackStrength(NULL) / (double)100));
|
||||||
|
enforceMinimumValue(0,attackStrengthMultiplierValueList[ast->getName()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
attackStrength -= ut->getAttackStrength(NULL);
|
attackStrength -= ut->getAttackStrength(NULL);
|
||||||
|
enforceMinimumValue(0,attackStrength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(ut->getAttackRangeIsMultiplier() == true) {
|
if(ut->getAttackRangeIsMultiplier() == true) {
|
||||||
for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) {
|
for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) {
|
||||||
const SkillType *skillType = unit->getType()->getSkillType(i);
|
const SkillType *skillType = unit->getType()->getSkillType(i);
|
||||||
const AttackSkillType *ast = dynamic_cast<const AttackSkillType *>(skillType);
|
const AttackSkillType *ast = dynamic_cast<const AttackSkillType *>(skillType);
|
||||||
if(ast != NULL) {
|
if(ast != NULL) {
|
||||||
attackRangeMultiplierValueList[ast->getName()] -= ((double)ast->getAttackRange() * ((double)ut->getAttackRange(NULL) / (double)100));
|
attackRangeMultiplierValueList[ast->getName()] -= ((double)ast->getAttackRange() * ((double)ut->getAttackRange(NULL) / (double)100));
|
||||||
|
enforceMinimumValue(0,attackRangeMultiplierValueList[ast->getName()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
attackRange -= ut->getAttackRange(NULL);
|
attackRange -= ut->getAttackRange(NULL);
|
||||||
|
enforceMinimumValue(0,attackRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ut->getMoveSpeedIsMultiplier() == true) {
|
if(ut->getMoveSpeedIsMultiplier() == true) {
|
||||||
|
@ -1001,6 +1015,7 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) {
|
||||||
const MoveSkillType *mst = dynamic_cast<const MoveSkillType *>(skillType);
|
const MoveSkillType *mst = dynamic_cast<const MoveSkillType *>(skillType);
|
||||||
if(mst != NULL) {
|
if(mst != NULL) {
|
||||||
moveSpeedIsMultiplierValueList[mst->getName()] -= ((double)mst->getSpeed() * ((double)ut->getMoveSpeed(NULL) / (double)100));
|
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 {
|
else {
|
||||||
moveSpeed -= ut->getMoveSpeed(NULL);
|
moveSpeed -= ut->getMoveSpeed(NULL);
|
||||||
|
enforceMinimumValue(0,moveSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ut->getProdSpeedIsMultiplier() == true) {
|
if(ut->getProdSpeedIsMultiplier() == true) {
|
||||||
|
@ -1016,19 +1032,23 @@ void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) {
|
||||||
const ProduceSkillType *pst = dynamic_cast<const ProduceSkillType *>(skillType);
|
const ProduceSkillType *pst = dynamic_cast<const ProduceSkillType *>(skillType);
|
||||||
if(pst != NULL) {
|
if(pst != NULL) {
|
||||||
prodSpeedProduceIsMultiplierValueList[pst->getName()] -= ((double)pst->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100));
|
prodSpeedProduceIsMultiplierValueList[pst->getName()] -= ((double)pst->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100));
|
||||||
|
enforceMinimumValue(0,prodSpeedProduceIsMultiplierValueList[pst->getName()]);
|
||||||
}
|
}
|
||||||
const UpgradeSkillType *ust = dynamic_cast<const UpgradeSkillType *>(skillType);
|
const UpgradeSkillType *ust = dynamic_cast<const UpgradeSkillType *>(skillType);
|
||||||
if(ust != NULL) {
|
if(ust != NULL) {
|
||||||
prodSpeedUpgradeIsMultiplierValueList[ust->getName()] -= ((double)ust->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100));
|
prodSpeedUpgradeIsMultiplierValueList[ust->getName()] -= ((double)ust->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100));
|
||||||
|
enforceMinimumValue(0,prodSpeedUpgradeIsMultiplierValueList[ust->getName()]);
|
||||||
}
|
}
|
||||||
const MorphSkillType *mst = dynamic_cast<const MorphSkillType *>(skillType);
|
const MorphSkillType *mst = dynamic_cast<const MorphSkillType *>(skillType);
|
||||||
if(mst != NULL) {
|
if(mst != NULL) {
|
||||||
prodSpeedMorphIsMultiplierValueList[mst->getName()] -= ((double)mst->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100));
|
prodSpeedMorphIsMultiplierValueList[mst->getName()] -= ((double)mst->getSpeed() * ((double)ut->getProdSpeed(NULL) / (double)100));
|
||||||
|
enforceMinimumValue(0,prodSpeedMorphIsMultiplierValueList[mst->getName()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
prodSpeed -= ut->getProdSpeed(NULL);
|
prodSpeed -= ut->getProdSpeed(NULL);
|
||||||
|
enforceMinimumValue(0,prodSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,13 @@ int round(float f);
|
||||||
//misc
|
//misc
|
||||||
bool checkVersionComptability(string clientVersionString, string serverVersionString);
|
bool checkVersionComptability(string clientVersionString, string serverVersionString);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void enforceMinimumValue(T minValue, T &value) {
|
||||||
|
if(value < minValue) {
|
||||||
|
value = minValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void deleteValues(T beginIt, T endIt){
|
void deleteValues(T beginIt, T endIt){
|
||||||
for(T it= beginIt; it!=endIt; ++it){
|
for(T it= beginIt; it!=endIt; ++it){
|
||||||
|
|
Loading…
Reference in New Issue