- added support for multiple animation models for each skill and display a them randomly during game play

This commit is contained in:
Mark Vejvoda 2011-06-25 05:23:41 +00:00
parent d0d31e4bfe
commit e0860309c0
4 changed files with 44 additions and 6 deletions

View File

@ -66,10 +66,27 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
string currentPath = dir;
endPathWithSlash(currentPath);
string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(currentPath);
animation= Renderer::getInstance().newModel(rsGame);
animation->load(path, false, &loadedFileList, &parentLoader);
loadedFileList[path].push_back(make_pair(parentLoader,sn->getChild("animation")->getAttribute("path")->getRestrictedValue()));
//string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(currentPath);
vector<XmlNode *> animationList = sn->getChildList("animation");
for(unsigned int i = 0; i < animationList.size(); ++i) {
string path= animationList[i]->getAttribute("path")->getRestrictedValue(currentPath);
if(fileExists(path) == true) {
Model *animation= Renderer::getInstance().newModel(rsGame);
animation->load(path, false, &loadedFileList, &parentLoader);
loadedFileList[path].push_back(make_pair(parentLoader,animationList[i]->getAttribute("path")->getRestrictedValue()));
animations.push_back(animation);
//printf("**FOUND ANIMATION [%s]\n",path.c_str());
}
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());
}
}
if(animations.size() <= 0) {
char szBuf[4096]="";
sprintf(szBuf,"Error no animations found for skill [%s] for parentLoader [%s]",name.c_str(),parentLoader.c_str());
throw runtime_error(szBuf);
}
//particles
if(sn->hasChild("particles")) {
@ -105,6 +122,14 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
}
}
Model *SkillType::getAnimation() const {
//int modelIndex = random.randRange(0,animations.size()-1);
srand(time(NULL));
int modelIndex = rand() % animations.size();
//printf("!!RETURN ANIMATION [%d / %d]\n",modelIndex,animations.size()-1);
return animations[modelIndex];
}
string SkillType::skillClassToStr(SkillClass skillClass) {
switch(skillClass){
case scStop: return "Stop";

View File

@ -82,9 +82,11 @@ protected:
int hpCost;
int speed;
int animSpeed;
Model *animation;
vector<Model *> animations;
SoundContainer sounds;
float soundStartTime;
RandomGen random;
public:
UnitParticleSystemTypes unitParticleSystemTypes;
@ -102,7 +104,7 @@ public:
int getHpCost() const {return hpCost;}
int getSpeed() const {return speed;}
int getAnimSpeed() const {return animSpeed;}
Model *getAnimation() const {return animation;}
Model *getAnimation() const;
StaticSound *getSound() const {return sounds.getRandSound();}
float getSoundStartTime() const {return soundStartTime;}

View File

@ -109,6 +109,7 @@ public:
XmlAttribute *getAttribute(const string &name,bool mustExist=true) const;
XmlNode *getChild(unsigned int i) const;
XmlNode *getChild(const string &childName, unsigned int childIndex=0) const;
vector<XmlNode *> getChildList(const string &childName) const;
bool hasChildAtIndex(const string &childName, int childIndex=0) const;
bool hasChild(const string &childName) const;
XmlNode *getParent() const;

View File

@ -275,6 +275,16 @@ XmlNode *XmlNode::getChild(unsigned int i) const {
return children[i];
}
vector<XmlNode *> XmlNode::getChildList(const string &childName) const {
vector<XmlNode *> list;
for(unsigned int j = 0; j < children.size(); ++j) {
if(children[j]->getName() == childName) {
list.push_back(children[j]);
}
}
return list;
}
XmlNode *XmlNode::getChild(const string &childName, unsigned int i) const{
if(i>=children.size()){