mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 19:52:25 +01:00
- for multiple animations added a new xml node to tell the engine to pick a random animation ONLY x number of times (so death animation is random but not changing when completed animating):
<animation-random-cycle-maxcount value="1" />
This commit is contained in:
parent
1700cbba2d
commit
4013af9447
@ -310,6 +310,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
||||
|
||||
//starting skill
|
||||
this->lastModelIndexForCurrSkillType = -1;
|
||||
this->animationRandomCycleCount = 0;
|
||||
this->currSkill = getType()->getFirstStOfClass(scStop);
|
||||
this->currentAttackBoostOriginatorEffect.skillType = this->currSkill;
|
||||
|
||||
@ -634,6 +635,7 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
|
||||
progress2= 0;
|
||||
if(this->currSkill != currSkill) {
|
||||
this->lastModelIndexForCurrSkillType = -1;
|
||||
this->animationRandomCycleCount = 0;
|
||||
}
|
||||
this->currSkill= currSkill;
|
||||
|
||||
@ -742,7 +744,12 @@ Model *Unit::getCurrentModelPtr() {
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
return currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType);
|
||||
int currentModelIndexForCurrSkillType = lastModelIndexForCurrSkillType;
|
||||
Model *result = currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType, &animationRandomCycleCount);
|
||||
if(currentModelIndexForCurrSkillType != lastModelIndexForCurrSkillType) {
|
||||
animationRandomCycleCount++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const Model *Unit::getCurrentModel() {
|
||||
@ -752,7 +759,12 @@ const Model *Unit::getCurrentModel() {
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
return currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType);
|
||||
int currentModelIndexForCurrSkillType = lastModelIndexForCurrSkillType;
|
||||
const Model *result = currSkill->getAnimation(animProgress,this,&lastModelIndexForCurrSkillType, &animationRandomCycleCount);
|
||||
if(currentModelIndexForCurrSkillType != lastModelIndexForCurrSkillType) {
|
||||
animationRandomCycleCount++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec3f Unit::getCurrVector() const{
|
||||
@ -1290,8 +1302,11 @@ bool Unit::update() {
|
||||
|
||||
//checks
|
||||
if(animProgress > 1.f) {
|
||||
bool canCycle = currSkill->CanCycleNextRandomAnimation(&animationRandomCycleCount);
|
||||
animProgress = currSkill->getClass() == scDie? 1.f: 0.f;
|
||||
this->lastModelIndexForCurrSkillType = -1;
|
||||
if(canCycle == true) {
|
||||
this->lastModelIndexForCurrSkillType = -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool return_value = false;
|
||||
|
@ -310,6 +310,7 @@ private:
|
||||
const ResourceType *loadType;
|
||||
const SkillType *currSkill;
|
||||
int lastModelIndexForCurrSkillType;
|
||||
int animationRandomCycleCount;
|
||||
|
||||
bool toBeUndertaken;
|
||||
bool alive;
|
||||
|
@ -138,6 +138,12 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
||||
string currentPath = dir;
|
||||
endPathWithSlash(currentPath);
|
||||
|
||||
animationRandomCycleMaxcount = -1;
|
||||
if(sn->hasChild("animation-random-cycle-maxcount") == true) {
|
||||
const XmlNode *randomCycleCountNode = sn->getChild("animation-random-cycle-maxcount");
|
||||
animationRandomCycleMaxcount = randomCycleCountNode->getAttribute("value")->getIntValue();
|
||||
}
|
||||
|
||||
//string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(currentPath);
|
||||
vector<XmlNode *> animationList = sn->getChildList("animation");
|
||||
for(unsigned int i = 0; i < animationList.size(); ++i) {
|
||||
@ -267,7 +273,20 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
||||
}
|
||||
}
|
||||
|
||||
Model *SkillType::getAnimation(float animProgress, const Unit *unit, int *lastAnimationIndex) const {
|
||||
bool SkillType::CanCycleNextRandomAnimation(const int *animationRandomCycleCount) const {
|
||||
bool result = true;
|
||||
if(animations.size() > 1) {
|
||||
if( animationRandomCycleMaxcount >= 0 &&
|
||||
animationRandomCycleCount != NULL &&
|
||||
*animationRandomCycleCount >= animationRandomCycleMaxcount) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Model *SkillType::getAnimation(float animProgress, const Unit *unit,
|
||||
int *lastAnimationIndex, int *animationRandomCycleCount) const {
|
||||
int modelIndex = 0;
|
||||
if(animations.size() > 1) {
|
||||
//printf("animProgress = [%f] for skill [%s]\n",animProgress,name.c_str());
|
||||
@ -276,24 +295,27 @@ Model *SkillType::getAnimation(float animProgress, const Unit *unit, int *lastAn
|
||||
modelIndex = *lastAnimationIndex;
|
||||
}
|
||||
if(modelIndex < 0 || animProgress > 1.0f) {
|
||||
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;
|
||||
bool canCycle = CanCycleNextRandomAnimation(animationRandomCycleCount);
|
||||
if(canCycle == true) {
|
||||
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(foundSpecificAnimation == false) {
|
||||
//int modelIndex = random.randRange(0,animations.size()-1);
|
||||
srand(time(NULL));
|
||||
modelIndex = rand() % animations.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,6 +119,8 @@ protected:
|
||||
int hpCost;
|
||||
int speed;
|
||||
int animSpeed;
|
||||
|
||||
int animationRandomCycleMaxcount;
|
||||
vector<Model *> animations;
|
||||
vector<AnimationAttributes> animationAttributes;
|
||||
|
||||
@ -137,6 +139,8 @@ public:
|
||||
const FactionType *ft, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
||||
string parentLoader);
|
||||
|
||||
bool CanCycleNextRandomAnimation(const int *animationRandomCycleCount) const;
|
||||
|
||||
//get
|
||||
const string &getName() const {return name;}
|
||||
SkillClass getClass() const {return skillClass;}
|
||||
@ -144,7 +148,7 @@ public:
|
||||
int getHpCost() const {return hpCost;}
|
||||
int getSpeed() const {return speed;}
|
||||
int getAnimSpeed() const {return animSpeed;}
|
||||
Model *getAnimation(float animProgress=0, const Unit *unit=NULL, int *lastAnimationIndex=NULL) const;
|
||||
Model *getAnimation(float animProgress=0, const Unit *unit=NULL, int *lastAnimationIndex=NULL, int *animationRandomCycleCount=NULL) const;
|
||||
StaticSound *getSound() const {return sounds.getRandSound();}
|
||||
float getSoundStartTime() const {return soundStartTime;}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user