From 5dda269151b191b4cce45e9c1e6c8a5218cdb733 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 25 Jun 2011 07:31:01 +0000 Subject: [PATCH] - bugfix for multiple models per skilltype (let existing model finish animating before allow next random model to be selected) - started work on a new feature called 'attack-boost' that should prove VERY INTERESTING once fully implemented (shhh its a secret) --- source/glest_game/type_instances/unit.cpp | 14 +++++--- source/glest_game/type_instances/unit.h | 5 +-- source/glest_game/types/skill_type.cpp | 42 ++++++++++++++++++++--- source/glest_game/types/skill_type.h | 19 ++++++++-- source/glest_game/types/upgrade_type.cpp | 29 +++++++++++----- source/glest_game/types/upgrade_type.h | 6 +++- 6 files changed, 94 insertions(+), 21 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 28b5de8a..9f45266b 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -276,6 +276,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType computeTotalUpgrade(); //starting skill + this->lastModelIndexForCurrSkillType = -1; this->currSkill = getType()->getFirstStOfClass(scStop); livingUnits.insert(id); livingUnitsp.insert(this); @@ -588,7 +589,11 @@ void Unit::setCurrSkill(const SkillType *currSkill) { } } progress2= 0; + if(this->currSkill != currSkill) { + this->lastModelIndexForCurrSkillType = -1; + } this->currSkill= currSkill; + } void Unit::setCurrSkill(SkillClass sc) { @@ -675,24 +680,24 @@ void Unit::setVisible(const bool visible) { // =============================== Render related ================================== -Model *Unit::getCurrentModelPtr() const { +Model *Unit::getCurrentModelPtr() { 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()); throw runtime_error(szBuf); } - return currSkill->getAnimation(); + return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType); } -const Model *Unit::getCurrentModel() const{ +const Model *Unit::getCurrentModel() { 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()); throw runtime_error(szBuf); } - return currSkill->getAnimation(); + return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType); } Vec3f Unit::getCurrVector() const{ @@ -1205,6 +1210,7 @@ bool Unit::update() { //checks if(animProgress > 1.f) { animProgress = currSkill->getClass() == scDie? 1.f: 0.f; + this->lastModelIndexForCurrSkillType = -1; } bool return_value = false; diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 633d5f54..7799aac7 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -283,6 +283,7 @@ private: const UnitType *type; const ResourceType *loadType; const SkillType *currSkill; + int lastModelIndexForCurrSkillType; bool toBeUndertaken; bool alive; @@ -423,8 +424,8 @@ public: bool getVisible() const { return visible; } //render related - const Model *getCurrentModel() const; - Model *getCurrentModelPtr() const; + const Model *getCurrentModel(); + Model *getCurrentModelPtr(); Vec3f getCurrVector() const; Vec3f getCurrVectorFlat() const; Vec3f getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) const; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 0b5b7825..48b7e1b4 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -120,12 +120,46 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, sounds[i]= sound; } } + + + // attack-boost + if(sn->hasChild("attack-boost") == true) { + //printf("$$FOUND ATTACK BOOST FOR [%s]\n",parentLoader.c_str()); + + attackBoost.enabled = true; + + const XmlNode *attackBoostNode = sn->getChild("attack-boost"); + attackBoost.radius = attackBoostNode->getChild("radius")->getAttribute("value")->getIntValue(); + attackBoost.boostAllUnits = attackBoostNode->getChild("boost-all-units")->getAttribute("value")->getBoolValue(); + if(attackBoost.boostAllUnits == false) { + for(int i = 0; i < attackBoostNode->getChild("boost-all-units")->getChildCount(); ++i) { + const XmlNode *boostUnitNode= attackBoostNode->getChild("boost-all-units")->getChild("unit-type", i); + attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); + } + } + attackBoost.boostUpgrade.load(attackBoostNode); + } + } -Model *SkillType::getAnimation() const { - //int modelIndex = random.randRange(0,animations.size()-1); - srand(time(NULL)); - int modelIndex = rand() % animations.size(); +Model *SkillType::getAnimation(float animProgress, int *lastAnimationIndex) const { + int modelIndex = 0; + if(animations.size() > 1) { + //printf("animProgress = [%f] for skill [%s]\n",animProgress,name.c_str()); + + if(lastAnimationIndex) { + modelIndex = *lastAnimationIndex; + } + if(modelIndex < 0 || animProgress > 1.0f) { + //int modelIndex = random.randRange(0,animations.size()-1); + srand(time(NULL)); + modelIndex = rand() % animations.size(); + } + } + if(lastAnimationIndex) { + *lastAnimationIndex = modelIndex; + } + //printf("!!RETURN ANIMATION [%d / %d]\n",modelIndex,animations.size()-1); return animations[modelIndex]; } diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index 76c5ee73..70e5c99f 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -22,6 +22,7 @@ #include "factory.h" #include "sound_container.h" #include "particle.h" +#include "upgrade_type.h" #include "leak_dumper.h" using Shared::Sound::StaticSound; @@ -72,8 +73,21 @@ typedef list UnitParticleSystemTypes; /// A basic action that an unit can perform // ===================================================== -class SkillType { +class AttackBoost { +public: + AttackBoost() { + enabled = false; + radius = 0; + boostAllUnits = false; + } + bool enabled; + int radius; + bool boostAllUnits; + vector boostUnitList; + UpgradeTypeBase boostUpgrade; +}; +class SkillType { protected: SkillClass skillClass; @@ -86,6 +100,7 @@ protected: SoundContainer sounds; float soundStartTime; RandomGen random; + AttackBoost attackBoost; public: UnitParticleSystemTypes unitParticleSystemTypes; @@ -104,7 +119,7 @@ public: int getHpCost() const {return hpCost;} int getSpeed() const {return speed;} int getAnimSpeed() const {return animSpeed;} - Model *getAnimation() const; + Model *getAnimation(float animProgress=0, int *lastAnimationIndex=NULL) const; StaticSound *getSound() const {return sounds.getRandSound();} float getSoundStartTime() const {return soundStartTime;} diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 1ead348c..69357313 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -37,6 +37,18 @@ namespace Glest{ namespace Game{ // ==================== get ==================== +void UpgradeTypeBase::load(const XmlNode *upgradeNode) { + //values + maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue(); + maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue(); + sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue(); + attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue(); + attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue(); + armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue(); + moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue(); + prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue(); +} + bool UpgradeType::isAffected(const UnitType *unitType) const{ return find(effects.begin(), effects.end(), unitType)!=effects.end(); } @@ -154,14 +166,15 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, sortedItems.clear(); //values - maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue(); - maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue(); - sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue(); - attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue(); - attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue(); - armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue(); - moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue(); - prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue(); +// maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue(); +// maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue(); +// sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue(); +// attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue(); +// attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue(); +// armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue(); +// moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue(); +// prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue(); + UpgradeTypeBase::load(upgradeNode); } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); diff --git a/source/glest_game/types/upgrade_type.h b/source/glest_game/types/upgrade_type.h index c42c9abb..696976d6 100644 --- a/source/glest_game/types/upgrade_type.h +++ b/source/glest_game/types/upgrade_type.h @@ -15,10 +15,12 @@ #include "element_type.h" #include "checksum.h" #include "conversion.h" +#include "xml_parser.h" #include "leak_dumper.h" using Shared::Util::Checksum; using namespace Shared::Util; +using namespace Shared::Xml; namespace Glest{ namespace Game{ @@ -30,7 +32,7 @@ class UnitType; // class UpgradeTypeBase // =============================== -class UpgradeTypeBase{ +class UpgradeTypeBase { protected: int maxHp; int sight; @@ -51,6 +53,8 @@ public: int getMoveSpeed() const {return moveSpeed;} int getProdSpeed() const {return prodSpeed;} + void load(const XmlNode *upgradeNode); + std::string toString() const { std::string result = "";