- updated hp regeneration method to look for negative hp regen values and if health ticks below 0 the unit dies
This commit is contained in:
parent
8d8afe78b5
commit
335749a15e
|
@ -25,6 +25,7 @@
|
|||
#include "renderer.h"
|
||||
#include "game.h"
|
||||
#include "socket.h"
|
||||
#include "sound_renderer.h"
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
|
@ -1112,14 +1113,30 @@ void Unit::tick() {
|
|||
}
|
||||
|
||||
//regenerate hp
|
||||
if(type->getHpRegeneration() >= 0) {
|
||||
hp+= type->getHpRegeneration();
|
||||
if(hp>type->getTotalMaxHp(&totalUpgrade)){
|
||||
hp= type->getTotalMaxHp(&totalUpgrade);
|
||||
}
|
||||
}
|
||||
// If we have negative regeneration then check if the unit should die
|
||||
else {
|
||||
bool decHpResult = decHp(-type->getHpRegeneration());
|
||||
if(decHpResult) {
|
||||
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()) {
|
||||
SoundRenderer::getInstance().playFx(sound);
|
||||
}
|
||||
}
|
||||
|
||||
//stop DamageParticles
|
||||
if(hp > type->getTotalMaxHp(&totalUpgrade) / 2) {
|
||||
stopDamageParticles();
|
||||
}
|
||||
|
||||
//regenerate ep
|
||||
ep += type->getEpRegeneration();
|
||||
if(ep>type->getTotalMaxEp(&totalUpgrade)){
|
||||
|
|
Loading…
Reference in New Issue