- for multiple animations, now can specify a 'preferred' animation based on the units hp using:
<animation path="models/archer_standing.g3d" fromHp="0" toHp="10" />
This commit is contained in:
parent
86743e2718
commit
14b6f195e6
|
@ -689,7 +689,7 @@ Model *Unit::getCurrentModelPtr() {
|
|||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType);
|
||||
return currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType);
|
||||
}
|
||||
|
||||
const Model *Unit::getCurrentModel() {
|
||||
|
@ -699,7 +699,7 @@ const Model *Unit::getCurrentModel() {
|
|||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType);
|
||||
return currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType);
|
||||
}
|
||||
|
||||
Vec3f Unit::getCurrVector() const{
|
||||
|
|
|
@ -126,6 +126,13 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
|||
|
||||
animations.push_back(animation);
|
||||
//printf("**FOUND ANIMATION [%s]\n",path.c_str());
|
||||
|
||||
AnimationAttributes animationAttributeList;
|
||||
if(animationList[i]->getAttribute("fromHp",false) != NULL && animationList[i]->getAttribute("toHp",false) != NULL) {
|
||||
animationAttributeList.fromHp = animationList[i]->getAttribute("fromHp")->getIntValue();
|
||||
animationAttributeList.toHp = animationList[i]->getAttribute("toHp")->getIntValue();
|
||||
}
|
||||
animationAttributes.push_back(animationAttributeList);
|
||||
}
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] WARNING CANNOT LOAD MODEL [%s] for parentLoader [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),parentLoader.c_str());
|
||||
|
@ -191,7 +198,7 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
|||
|
||||
}
|
||||
|
||||
Model *SkillType::getAnimation(float animProgress, int *lastAnimationIndex) const {
|
||||
Model *SkillType::getAnimation(float animProgress, const Unit *unit, int *lastAnimationIndex) const {
|
||||
int modelIndex = 0;
|
||||
if(animations.size() > 1) {
|
||||
//printf("animProgress = [%f] for skill [%s]\n",animProgress,name.c_str());
|
||||
|
@ -200,9 +207,25 @@ Model *SkillType::getAnimation(float animProgress, int *lastAnimationIndex) cons
|
|||
modelIndex = *lastAnimationIndex;
|
||||
}
|
||||
if(modelIndex < 0 || animProgress > 1.0f) {
|
||||
//int modelIndex = random.randRange(0,animations.size()-1);
|
||||
srand(time(NULL));
|
||||
modelIndex = rand() % animations.size();
|
||||
bool foundSpecificAnimation = false;
|
||||
if(unit != NULL) {
|
||||
for(unsigned int i = 0; i < animationAttributes.size(); ++i) {
|
||||
const AnimationAttributes &attributes = animationAttributes[i];
|
||||
if(attributes.fromHp != 0 || attributes.toHp != 0) {
|
||||
if(unit->getHp() >= attributes.fromHp && unit->getHp() <= attributes.toHp) {
|
||||
modelIndex = i;
|
||||
foundSpecificAnimation = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(foundSpecificAnimation == false) {
|
||||
//int modelIndex = random.randRange(0,animations.size()-1);
|
||||
srand(time(NULL));
|
||||
modelIndex = rand() % animations.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(lastAnimationIndex) {
|
||||
|
|
|
@ -86,6 +86,17 @@ public:
|
|||
bool isAffected(const Unit *source, const Unit *dest) const;
|
||||
};
|
||||
|
||||
class AnimationAttributes {
|
||||
public:
|
||||
AnimationAttributes() {
|
||||
fromHp = 0;
|
||||
toHp = 0;
|
||||
}
|
||||
|
||||
int fromHp;
|
||||
int toHp;
|
||||
};
|
||||
|
||||
class SkillType {
|
||||
|
||||
protected:
|
||||
|
@ -96,6 +107,8 @@ protected:
|
|||
int speed;
|
||||
int animSpeed;
|
||||
vector<Model *> animations;
|
||||
vector<AnimationAttributes> animationAttributes;
|
||||
|
||||
SoundContainer sounds;
|
||||
float soundStartTime;
|
||||
RandomGen random;
|
||||
|
@ -118,7 +131,7 @@ public:
|
|||
int getHpCost() const {return hpCost;}
|
||||
int getSpeed() const {return speed;}
|
||||
int getAnimSpeed() const {return animSpeed;}
|
||||
Model *getAnimation(float animProgress=0, int *lastAnimationIndex=NULL) const;
|
||||
Model *getAnimation(float animProgress=0, const Unit *unit=NULL, int *lastAnimationIndex=NULL) const;
|
||||
StaticSound *getSound() const {return sounds.getRandSound();}
|
||||
float getSoundStartTime() const {return soundStartTime;}
|
||||
|
||||
|
|
Loading…
Reference in New Issue