From e0860309c0ba5abf90c7a654d655f5ae8079bb93 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 25 Jun 2011 05:23:41 +0000 Subject: [PATCH] - added support for multiple animation models for each skill and display a them randomly during game play --- source/glest_game/types/skill_type.cpp | 33 +++++++++++++++++--- source/glest_game/types/skill_type.h | 6 ++-- source/shared_lib/include/xml/xml_parser.h | 1 + source/shared_lib/sources/xml/xml_parser.cpp | 10 ++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 635104ce7..0b5b78258 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -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 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"; diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index 524d71718..76c5ee730 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -82,9 +82,11 @@ protected: int hpCost; int speed; int animSpeed; - Model *animation; + vector 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;} diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index 3ac4e517b..edd29ba60 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -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 getChildList(const string &childName) const; bool hasChildAtIndex(const string &childName, int childIndex=0) const; bool hasChild(const string &childName) const; XmlNode *getParent() const; diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index 19511ef03..c6cfe6bf4 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -275,6 +275,16 @@ XmlNode *XmlNode::getChild(unsigned int i) const { return children[i]; } +vector XmlNode::getChildList(const string &childName) const { + vector 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()){