- 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:
Mark Vejvoda 2010-12-28 02:17:44 +00:00
parent 8d8afe78b5
commit 335749a15e
3 changed files with 34 additions and 17 deletions

View File

@ -25,6 +25,7 @@
#include "renderer.h"
#include "game.h"
#include "socket.h"
#include "sound_renderer.h"
#include "leak_dumper.h"
@ -1112,23 +1113,39 @@ void Unit::tick() {
}
//regenerate hp
hp+= type->getHpRegeneration();
if(hp>type->getTotalMaxHp(&totalUpgrade)){
hp= type->getTotalMaxHp(&totalUpgrade);
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 ){
if(hp > type->getTotalMaxHp(&totalUpgrade) / 2) {
stopDamageParticles();
}
//regenerate ep
ep+= type->getEpRegeneration();
ep += type->getEpRegeneration();
if(ep>type->getTotalMaxEp(&totalUpgrade)){
ep= type->getTotalMaxEp(&totalUpgrade);
}
}
}
int Unit::update2(){
int Unit::update2() {
progress2++;
return progress2;
}
@ -1185,12 +1202,12 @@ bool Unit::repair(){
}
//decrements HP and returns if dead
bool Unit::decHp(int i){
if(hp==0){
bool Unit::decHp(int i) {
if(hp == 0) {
return false;
}
hp-=i;
hp -= i;
if(type == NULL) {
char szBuf[4096]="";
@ -1199,12 +1216,12 @@ bool Unit::decHp(int i){
}
//startDamageParticles
if(hp<type->getMaxHp()/2 ){
if(hp < type->getMaxHp() / 2 ) {
startDamageParticles();
}
//stop DamageParticles on death
if(hp<=0){
if(hp <= 0) {
alive= false;
hp=0;
stopDamageParticles();
@ -1213,7 +1230,7 @@ bool Unit::decHp(int i){
return false;
}
string Unit::getDesc() const{
string Unit::getDesc() const {
Lang &lang= Lang::getInstance();

View File

@ -151,7 +151,7 @@ public:
// =====================================================
// class UnitPath
// =====================================================
/** Holds the next cells of a Unit movement
/** Holds the next cells of a Unit movement
* @extends std::list<Shared::Math::Vec2i>
*/
class UnitPath : public list<Vec2i>, public UnitPathInterface {
@ -175,14 +175,14 @@ public:
bool empty() const {return list<Vec2i>::empty();} /**< is path empty */
virtual void add(const Vec2i &pos) { push_front(pos);} /**< push onto front of path */
#if 0
// old style, to work with original PathFinder
Vec2i peek() {return back();} /**< peek at the next position */
Vec2i peek() {return back();} /**< peek at the next position */
void pop() {this->pop_back();} /**< pop the next position off the path */
#else
// new style, for the new RoutePlanner
Vec2i peek() {return front();} /**< peek at the next position */
Vec2i peek() {return front();} /**< peek at the next position */
//virtual Vec2i pop() { Vec2i p= front(); erase(begin()); return p; } /**< pop the next position off the path */
void pop() { erase(begin()); } /**< pop the next position off the path */
#endif

View File

@ -747,7 +747,7 @@ Vec2i Map::findBestBuildApproach(const Unit *unit, Vec2i originalBuildPos,const
Vec2i end = pos + Vec2i(ut->getSize());
for(int i = start.x; i <= end.x; ++i) {
for(int j = start.y; j <= end.y; ++j){
for(int j = start.y; j <= end.y; ++j) {
Vec2i testPos(i,j);
if(isInUnitTypeCells(ut, originalBuildPos,testPos) == false) {
float distance = unitBuilderPos.dist(testPos);