mirror of
https://github.com/glest/glest-source.git
synced 2025-09-01 04:01:47 +02:00
- 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:
@@ -689,7 +689,7 @@ Model *Unit::getCurrentModelPtr() {
|
|||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType);
|
return currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Model *Unit::getCurrentModel() {
|
const Model *Unit::getCurrentModel() {
|
||||||
@@ -699,7 +699,7 @@ const Model *Unit::getCurrentModel() {
|
|||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType);
|
return currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3f Unit::getCurrVector() const{
|
Vec3f Unit::getCurrVector() const{
|
||||||
|
@@ -126,6 +126,13 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
|||||||
|
|
||||||
animations.push_back(animation);
|
animations.push_back(animation);
|
||||||
//printf("**FOUND ANIMATION [%s]\n",path.c_str());
|
//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 {
|
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());
|
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;
|
int modelIndex = 0;
|
||||||
if(animations.size() > 1) {
|
if(animations.size() > 1) {
|
||||||
//printf("animProgress = [%f] for skill [%s]\n",animProgress,name.c_str());
|
//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;
|
modelIndex = *lastAnimationIndex;
|
||||||
}
|
}
|
||||||
if(modelIndex < 0 || animProgress > 1.0f) {
|
if(modelIndex < 0 || animProgress > 1.0f) {
|
||||||
//int modelIndex = random.randRange(0,animations.size()-1);
|
bool foundSpecificAnimation = false;
|
||||||
srand(time(NULL));
|
if(unit != NULL) {
|
||||||
modelIndex = rand() % animations.size();
|
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) {
|
if(lastAnimationIndex) {
|
||||||
|
@@ -86,6 +86,17 @@ public:
|
|||||||
bool isAffected(const Unit *source, const Unit *dest) const;
|
bool isAffected(const Unit *source, const Unit *dest) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AnimationAttributes {
|
||||||
|
public:
|
||||||
|
AnimationAttributes() {
|
||||||
|
fromHp = 0;
|
||||||
|
toHp = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fromHp;
|
||||||
|
int toHp;
|
||||||
|
};
|
||||||
|
|
||||||
class SkillType {
|
class SkillType {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -96,6 +107,8 @@ protected:
|
|||||||
int speed;
|
int speed;
|
||||||
int animSpeed;
|
int animSpeed;
|
||||||
vector<Model *> animations;
|
vector<Model *> animations;
|
||||||
|
vector<AnimationAttributes> animationAttributes;
|
||||||
|
|
||||||
SoundContainer sounds;
|
SoundContainer sounds;
|
||||||
float soundStartTime;
|
float soundStartTime;
|
||||||
RandomGen random;
|
RandomGen random;
|
||||||
@@ -118,7 +131,7 @@ public:
|
|||||||
int getHpCost() const {return hpCost;}
|
int getHpCost() const {return hpCost;}
|
||||||
int getSpeed() const {return speed;}
|
int getSpeed() const {return speed;}
|
||||||
int getAnimSpeed() const {return animSpeed;}
|
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();}
|
StaticSound *getSound() const {return sounds.getRandSound();}
|
||||||
float getSoundStartTime() const {return soundStartTime;}
|
float getSoundStartTime() const {return soundStartTime;}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user