- bugfix for hp regeneration (Thanks for pointing this out Ishmaru)

This commit is contained in:
Mark Vejvoda 2011-11-28 06:25:20 +00:00
parent 1658306b59
commit 21d06fd386
1 changed files with 56 additions and 46 deletions

View File

@ -2093,14 +2093,49 @@ void Unit::tick() {
throw runtime_error(szBuf); throw runtime_error(szBuf);
} }
//if(this->getType()->getName() == "spearman") printf("Unit [%d - %s] start tick hp = %d\n",this->getId(),this->getType()->getName().c_str(),hp);
//regenerate hp upgrade / or boost
if(type->getTotalMaxHpRegeneration(&totalUpgrade) != 0) {
if(type->getTotalMaxHpRegeneration(&totalUpgrade) >= 0) {
checkItemInVault(&this->hp,this->hp);
hp += type->getTotalMaxHpRegeneration(&totalUpgrade);
if(hp > type->getTotalMaxHp(&totalUpgrade)) {
hp = type->getTotalMaxHp(&totalUpgrade);
}
addItemToVault(&this->hp,this->hp);
//if(this->getType()->getName() == "spearman") printf("tick hp#2 [type->getTotalMaxHpRegeneration(&totalUpgrade)] = %d type->getTotalMaxHp(&totalUpgrade) [%d] newhp = %d\n",type->getTotalMaxHpRegeneration(&totalUpgrade),type->getTotalMaxHp(&totalUpgrade),hp);
}
// If we have negative regeneration then check if the unit should die
else {
bool decHpResult = decHp(-type->getTotalMaxHpRegeneration(&totalUpgrade));
if(decHpResult) {
this->setCauseOfDeath(ucodStarvedRegeneration);
Unit::game->getWorld()->getStats()->die(getFactionIndex());
game->getScriptManager()->onUnitDied(this);
}
StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound();
if(sound != NULL &&
(this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) {
SoundRenderer::getInstance().playFx(sound);
}
}
}
//regenerate hp //regenerate hp
else {
if(type->getHpRegeneration() >= 0) { if(type->getHpRegeneration() >= 0) {
checkItemInVault(&this->hp,this->hp); checkItemInVault(&this->hp,this->hp);
hp += type->getHpRegeneration(); hp += type->getHpRegeneration();
if(hp > type->getTotalMaxHp(&totalUpgrade)) { if(hp > type->getTotalMaxHp(&totalUpgrade)) {
hp = type->getTotalMaxHp(&totalUpgrade); hp = type->getTotalMaxHp(&totalUpgrade);
} }
addItemToVault(&this->hp,this->hp); addItemToVault(&this->hp,this->hp);
//if(this->getType()->getName() == "spearman") printf("tick hp#1 [type->getHpRegeneration()] = %d type->getTotalMaxHp(&totalUpgrade) [%d] newhp = %d\n",type->getHpRegeneration(),type->getTotalMaxHp(&totalUpgrade),hp);
} }
// If we have negative regeneration then check if the unit should die // If we have negative regeneration then check if the unit should die
else { else {
@ -2117,31 +2152,6 @@ void Unit::tick() {
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) {
SoundRenderer::getInstance().playFx(sound); SoundRenderer::getInstance().playFx(sound);
} }
}
//regenerate hp upgrade / or boost
if(type->getTotalMaxHpRegeneration(&totalUpgrade) >= 0) {
checkItemInVault(&this->hp,this->hp);
hp += type->getTotalMaxHpRegeneration(&totalUpgrade);
if(hp > type->getTotalMaxHp(&totalUpgrade)) {
hp = type->getTotalMaxHp(&totalUpgrade);
}
addItemToVault(&this->hp,this->hp);
}
// If we have negative regeneration then check if the unit should die
else {
bool decHpResult = decHp(-type->getTotalMaxHpRegeneration(&totalUpgrade));
if(decHpResult) {
this->setCauseOfDeath(ucodStarvedRegeneration);
Unit::game->getWorld()->getStats()->die(getFactionIndex());
game->getScriptManager()->onUnitDied(this);
}
StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound();
if(sound != NULL &&
(this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) {
SoundRenderer::getInstance().playFx(sound);
} }
} }