diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index f0a237b9..2006015a 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -3068,7 +3068,7 @@ void Renderer::renderUnits(const int renderFps) { //render Model *model= unit->getCurrentModelPtr(); - model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive() && !unit->isBeingBuiltWithAnimHpBound()); + model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive() && !unit->isAnimProgressBound()); modelRenderer->render(model); triangleCount+= model->getTriangleCount(); @@ -4733,7 +4733,7 @@ void Renderer::renderUnitsFast(bool renderingShadows) { //render Model *model= unit->getCurrentModelPtr(); - model->updateInterpolationVertices(unit->getAnimProgress(), unit->isAlive() && !unit->isBeingBuiltWithAnimHpBound()); + model->updateInterpolationVertices(unit->getAnimProgress(), unit->isAlive() && !unit->isAnimProgressBound()); modelRenderer->render(model); glPopMatrix(); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index de87c363..ba098c62 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -487,6 +487,17 @@ int Unit::getProductionPercent() const{ return -1; } +float Unit::getProgressRatio() const{ + if(anyCommand()){ + const ProducibleType *produced= commands.front()->getCommandType()->getProduced(); + if(produced!=NULL){ + float help=progress2; + return clamp(help/produced->getProductionTime(), 0.f, 1.f); + } + } + return -1; +} + float Unit::getHpRatio() const { if(type == NULL) { char szBuf[4096]=""; @@ -550,7 +561,7 @@ bool Unit::isOperative() const{ return isAlive() && isBuilt(); } -bool Unit::isBeingBuiltWithAnimHpBound() const{ +bool Unit::isAnimProgressBound() const{ if(currSkill == NULL) { char szBuf[4096]=""; sprintf(szBuf,"In [%s::%s Line: %d] ERROR: currSkill == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str()); @@ -559,9 +570,27 @@ bool Unit::isBeingBuiltWithAnimHpBound() const{ bool result = false; if(currSkill->getClass() == scBeBuilt) { - const BeBuiltSkillType *bbst = dynamic_cast(currSkill); - if(bbst != NULL) { - result = bbst->getAnimHpBound(); + const BeBuiltSkillType *skill = dynamic_cast(currSkill); + if(skill != NULL) { + result = skill->getAnimProgressBound(); + } + } + else if(currSkill->getClass() == scProduce) { + const ProduceSkillType *skill = dynamic_cast(currSkill); + if(skill != NULL) { + result = skill->getAnimProgressBound(); + } + } + else if(currSkill->getClass() == scUpgrade) { + const UpgradeSkillType *skill = dynamic_cast(currSkill); + if(skill != NULL) { + result = skill->getAnimProgressBound(); + } + } + else if(currSkill->getClass() == scMorph) { + const MorphSkillType *skill = dynamic_cast(currSkill); + if(skill != NULL) { + result = skill->getAnimProgressBound(); } } return result; @@ -1336,8 +1365,11 @@ bool Unit::update() { float speedDenominator = (speedDivider * game->getWorld()->getUpdateFps(this->getFactionIndex())); progress += (speed * diagonalFactor * heightFactor) / speedDenominator; - if(isBeingBuiltWithAnimHpBound() == true) { - animProgress=this->getHpRatio(); + if(isAnimProgressBound() == true) { + if(currSkill->getClass() == scBeBuilt) animProgress = this->getHpRatio(); + if(currSkill->getClass() == scProduce) animProgress = this->getProgressRatio(); + if(currSkill->getClass() == scUpgrade) animProgress = this->getProgressRatio(); + if(currSkill->getClass() == scMorph) animProgress = this->getProgressRatio(); } else{ animProgress += (currSkill->getAnimSpeed() * heightFactor) / speedDenominator; diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 64774de8..4dde7372 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -404,6 +404,7 @@ public: int getHp() const {return hp;} int getEp() const {return ep;} int getProductionPercent() const; + float getProgressRatio() const; float getHpRatio() const; float getEpRatio() const; bool getToBeUndertaken() const {return toBeUndertaken;} @@ -443,7 +444,7 @@ public: bool isOperative() const; bool isBeingBuilt() const; bool isBuilt() const; - bool isBeingBuiltWithAnimHpBound() const; + bool isAnimProgressBound() const; bool isPutrefacting() const; bool isAlly(const Unit *unit) const; bool isDamaged() const; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 49e34beb..b539bda1 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -588,6 +588,20 @@ ProduceSkillType::ProduceSkillType(){ skillClass= scProduce; } +void ProduceSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map > > &loadedFileList, + string parentLoader) { + SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + + if(sn->hasChild("anim-progress-bound")){ + animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); + } + else { + animProgressBound=false; + } +} + + string ProduceSkillType::toString() const{ return Lang::getInstance().get("Produce"); } @@ -606,6 +620,19 @@ UpgradeSkillType::UpgradeSkillType(){ skillClass= scUpgrade; } +void UpgradeSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map > > &loadedFileList, + string parentLoader) { + SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + + if(sn->hasChild("anim-progress-bound")){ + animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); + } + else { + animProgressBound=false; + } +} + string UpgradeSkillType::toString() const{ return Lang::getInstance().get("Upgrade"); } @@ -629,11 +656,14 @@ void BeBuiltSkillType::load(const XmlNode *sn, const string &dir, const TechTree string parentLoader) { SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); - if(sn->hasChild("anim-hp-bound")){ - animHpBound= sn->getChild("anim-hp-bound")->getAttribute("value")->getBoolValue(); + if(sn->hasChild("anim-progress-bound")){ + animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); + } + else if(sn->hasChild("anim-hp-bound")){ // deprecated!!!! remove it when you see it after 15th July 2011 + animProgressBound= sn->getChild("anim-hp-bound")->getAttribute("value")->getBoolValue(); } else { - animHpBound=false; + animProgressBound=false; } } @@ -650,6 +680,19 @@ MorphSkillType::MorphSkillType(){ skillClass= scMorph; } +void MorphSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map > > &loadedFileList, + string parentLoader) { + SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + + if(sn->hasChild("anim-progress-bound")){ + animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); + } + else { + animProgressBound=false; + } +} + string MorphSkillType::toString() const{ return "Morph"; } diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index 971fa609..daf5764a 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -278,8 +278,15 @@ public: // =============================== class ProduceSkillType: public SkillType{ +private: + bool animProgressBound; public: ProduceSkillType(); + bool getAnimProgressBound() const {return animProgressBound;} + virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map > > &loadedFileList, + string parentLoader); + virtual string toString() const; virtual int getTotalSpeed(const TotalUpgrade *totalUpgrade) const; @@ -290,8 +297,15 @@ public: // =============================== class UpgradeSkillType: public SkillType{ +private: + bool animProgressBound; public: UpgradeSkillType(); + bool getAnimProgressBound() const {return animProgressBound;} + virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map > > &loadedFileList, + string parentLoader); + virtual string toString() const; virtual int getTotalSpeed(const TotalUpgrade *totalUpgrade) const; @@ -304,11 +318,11 @@ public: class BeBuiltSkillType: public SkillType{ private: - bool animHpBound; + bool animProgressBound; public: BeBuiltSkillType(); - bool getAnimHpBound() const {return animHpBound;} + bool getAnimProgressBound() const {return animProgressBound;} virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, @@ -321,10 +335,18 @@ public: // =============================== class MorphSkillType: public SkillType{ +private: + bool animProgressBound; + public: MorphSkillType(); - virtual string toString() const; + bool getAnimProgressBound() const {return animProgressBound;} + virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map > > &loadedFileList, + string parentLoader); + + virtual string toString() const; virtual int getTotalSpeed(const TotalUpgrade *totalUpgrade) const; };