diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 63db47ad..aad40ae4 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -1209,7 +1209,7 @@ void Faction::applyCostsOnInterval(const ResourceType *rtApply) { world->getStats()->die(unit->getFactionIndex(),unit->getType()->getCountUnitDeathInStats()); scriptManager->onUnitDied(unit); } - StaticSound *sound= unit->getType()->getFirstStOfClass(scDie)->getSound(); + StaticSound *sound= static_cast(unit->getType()->getFirstStOfClass(scDie))->getSound(); if(sound != NULL && (thisFaction == true || world->showWorldForPlayer(world->getThisTeamIndex()) == true)) { SoundRenderer::getInstance().playFx(sound); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 7042c4ee..cbe3c050 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -2937,7 +2937,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); - StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); + StaticSound *sound= static_cast(this->getType()->getFirstStOfClass(scDie))->getSound(); if(sound != NULL && (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { @@ -3035,7 +3035,7 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) { Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); - StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); + StaticSound *sound= static_cast(this->getType()->getFirstStOfClass(scDie))->getSound(); if(sound != NULL && (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { @@ -3107,7 +3107,7 @@ void Unit::tick() { Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); } - StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); + StaticSound *sound= static_cast(this->getType()->getFirstStOfClass(scDie))->getSound(); if(sound != NULL && (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { @@ -3146,7 +3146,7 @@ void Unit::tick() { Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); game->getScriptManager()->onUnitDied(this); } - StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); + StaticSound *sound= static_cast(this->getType()->getFirstStOfClass(scDie))->getSound(); if(sound != NULL && (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 8ccff7e7..a9832c3a 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -274,12 +274,27 @@ void AttackBoost::saveGame(XmlNode *rootNode) const { attackBoostNode->addAttribute("name",name, mapTagReplacements); } +// ===================================================== +// class SkillSound +// ===================================================== +SkillSound::SkillSound(){ + startTime=0.0f; +} +SkillSound::~SkillSound() +{ + deleteValues(soundContainer.getSounds().begin(), soundContainer.getSounds().end()); + startTime=0.0f; + //soundContainer +} // ===================================================== // class SkillType // ===================================================== SkillType::~SkillType() { - deleteValues(sounds.getSounds().begin(), sounds.getSounds().end()); + while(!skillSoundList.empty()) { + delete skillSoundList.back(); + skillSoundList.pop_back(); + } //remove unitParticleSystemTypes while(!unitParticleSystemTypes.empty()) { delete unitParticleSystemTypes.back(); @@ -505,11 +520,16 @@ void SkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, } //sound - if(sn->hasChild("sound")) { - const XmlNode *soundNode= sn->getChild("sound"); + vector soundNodeList = sn->getChildList("sound"); + for(unsigned int i = 0; i < soundNodeList.size(); ++i) { + const XmlNode *soundNode= soundNodeList[i]; if(soundNode->getAttribute("enabled")->getBoolValue()) { - soundStartTime= soundNode->getAttribute("start-time")->getFloatValue(); - sounds.resize((int)soundNode->getChildCount()); + float soundStartTime= soundNode->getAttribute("start-time")->getFloatValue(); + SkillSound *skillSound = new SkillSound(); + skillSound->setStartTime(soundStartTime); + + skillSound->getSoundContainer()->resize((int)soundNode->getChildCount()); + skillSoundList.push_back(skillSound); for(int i = 0; i < (int)soundNode->getChildCount(); ++i) { const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true); @@ -517,7 +537,7 @@ void SkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, StaticSound *sound= new StaticSound(); sound->load(path); loadedFileList[path].push_back(make_pair(parentLoader,soundFileNode->getAttribute("path")->getRestrictedValue())); - sounds[i]= sound; + (*skillSound->getSoundContainer())[i]= sound; } } } @@ -744,7 +764,7 @@ void SkillType::saveGame(XmlNode *rootNode) { // // SoundContainer sounds; // float soundStartTime; - skillTypeNode->addAttribute("soundStartTime",floatToStr(soundStartTime,6), mapTagReplacements); +// skillTypeNode->addAttribute("soundStartTime",floatToStr(soundStartTime,6), mapTagReplacements); // RandomGen random; skillTypeNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements); // AttackBoost attackBoost; @@ -1299,6 +1319,15 @@ void DieSkillType::saveGame(XmlNode *rootNode) { dieSkillTypeNode->addAttribute("fade",intToStr(fade), mapTagReplacements); } +StaticSound *DieSkillType::getSound() const{ + if(skillSoundList.size()==0){ + return NULL; + } + else { + return skillSoundList.front()->getSoundContainer()->getRandSound(); + } +} + // ===================================================== // class FogOfWarSkillType diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index f65989b3..290c1903 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -125,8 +125,29 @@ public: int toHp; }; +// ===================================================== +// class SkillSound +// holds the start time and a SoundContainer +// ===================================================== + +class SkillSound{ +private: + SoundContainer soundContainer; + float startTime; + +public: + SkillSound(); + ~SkillSound(); + + SoundContainer *getSoundContainer() {return &soundContainer;} + float getStartTime() const {return startTime;} + void setStartTime(float value) {startTime=value;} +}; + +typedef list SkillSoundList; + class SkillType { - + protected: SkillClass skillClass; string name; @@ -157,8 +178,7 @@ protected: vector animations; vector animationAttributes; - SoundContainer sounds; - float soundStartTime; + SkillSoundList skillSoundList; RandomGen random; AttackBoost attackBoost; @@ -197,14 +217,14 @@ public: int getSpeed() const {return speed;} int getAnimSpeed() const {return animSpeed;} 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;} float getShakeStartTime() const {return shakeStartTime;} bool getShake() const {return shake;} int getShakeIntensity() const {return shakeIntensity;} int getShakeDuration() const {return shakeDuration;} + const SkillSoundList * getSkillSoundList() const {return &skillSoundList;} + bool getShakeSelfEnabled() const {return shakeSelfEnabled;} bool getShakeSelfVisible() const {return shakeSelfVisible;} bool getShakeSelfInCameraView() const {return shakeSelfInCameraView;} @@ -450,6 +470,7 @@ public: virtual string toString(bool translatedValue) const; virtual void saveGame(XmlNode *rootNode); + StaticSound *getSound() const; }; // =============================== diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index dbfda944..90835e11 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -128,16 +128,18 @@ bool UnitUpdater::updateUnit(Unit *unit) { //play skill sound const SkillType *currSkill= unit->getCurrSkill(); - if(currSkill->getSound() != NULL) { - float soundStartTime= currSkill->getSoundStartTime(); + + for(SkillSoundList::const_iterator it= currSkill->getSkillSoundList()->begin(); it != currSkill->getSkillSoundList()->end(); ++it) { + float soundStartTime= (*it)->getStartTime(); if(soundStartTime >= unit->getLastAnimProgressAsFloat() && soundStartTime < unit->getAnimProgressAsFloat()) { if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex()) || (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true)) { - soundRenderer.playFx(currSkill->getSound(), unit->getCurrVector(), gameCamera->getPos()); + soundRenderer.playFx((*it)->getSoundContainer()->getRandSound(), unit->getCurrVector(), gameCamera->getPos()); } } } + if (currSkill->getShake()) { float shakeStartTime = currSkill->getShakeStartTime(); if (shakeStartTime >= unit->getLastAnimProgressAsFloat()