multi sounds

multiple sounds timed sounds for all skills. 
By this you can now play a sound for shooting every single shot too.
This commit is contained in:
titiger 2014-07-20 03:28:03 +02:00
parent 26bab8548c
commit da23e4c048
5 changed files with 72 additions and 20 deletions

View File

@ -1209,7 +1209,7 @@ void Faction::applyCostsOnInterval(const ResourceType *rtApply) {
world->getStats()->die(unit->getFactionIndex(),unit->getType()->getCountUnitDeathInStats()); world->getStats()->die(unit->getFactionIndex(),unit->getType()->getCountUnitDeathInStats());
scriptManager->onUnitDied(unit); scriptManager->onUnitDied(unit);
} }
StaticSound *sound= unit->getType()->getFirstStOfClass(scDie)->getSound(); StaticSound *sound= static_cast<const DieSkillType *>(unit->getType()->getFirstStOfClass(scDie))->getSound();
if(sound != NULL && if(sound != NULL &&
(thisFaction == true || world->showWorldForPlayer(world->getThisTeamIndex()) == true)) { (thisFaction == true || world->showWorldForPlayer(world->getThisTeamIndex()) == true)) {
SoundRenderer::getInstance().playFx(sound); SoundRenderer::getInstance().playFx(sound);

View File

@ -2937,7 +2937,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats());
game->getScriptManager()->onUnitDied(this); game->getScriptManager()->onUnitDied(this);
StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); StaticSound *sound= static_cast<const DieSkillType *>(this->getType()->getFirstStOfClass(scDie))->getSound();
if(sound != NULL && if(sound != NULL &&
(this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { (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()); Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats());
game->getScriptManager()->onUnitDied(this); game->getScriptManager()->onUnitDied(this);
StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); StaticSound *sound= static_cast<const DieSkillType *>(this->getType()->getFirstStOfClass(scDie))->getSound();
if(sound != NULL && if(sound != NULL &&
(this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) {
@ -3107,7 +3107,7 @@ void Unit::tick() {
Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats());
game->getScriptManager()->onUnitDied(this); game->getScriptManager()->onUnitDied(this);
} }
StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); StaticSound *sound= static_cast<const DieSkillType *>(this->getType()->getFirstStOfClass(scDie))->getSound();
if(sound != NULL && if(sound != NULL &&
(this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) {
@ -3146,7 +3146,7 @@ void Unit::tick() {
Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats()); Unit::game->getWorld()->getStats()->die(getFactionIndex(),getType()->getCountUnitDeathInStats());
game->getScriptManager()->onUnitDied(this); game->getScriptManager()->onUnitDied(this);
} }
StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound(); StaticSound *sound= static_cast<const DieSkillType *>(this->getType()->getFirstStOfClass(scDie))->getSound();
if(sound != NULL && if(sound != NULL &&
(this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() || (this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) { (game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true))) {

View File

@ -274,12 +274,27 @@ void AttackBoost::saveGame(XmlNode *rootNode) const {
attackBoostNode->addAttribute("name",name, mapTagReplacements); 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 // class SkillType
// ===================================================== // =====================================================
SkillType::~SkillType() { SkillType::~SkillType() {
deleteValues(sounds.getSounds().begin(), sounds.getSounds().end()); while(!skillSoundList.empty()) {
delete skillSoundList.back();
skillSoundList.pop_back();
}
//remove unitParticleSystemTypes //remove unitParticleSystemTypes
while(!unitParticleSystemTypes.empty()) { while(!unitParticleSystemTypes.empty()) {
delete unitParticleSystemTypes.back(); delete unitParticleSystemTypes.back();
@ -505,11 +520,16 @@ void SkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
} }
//sound //sound
if(sn->hasChild("sound")) { vector<XmlNode *> soundNodeList = sn->getChildList("sound");
const XmlNode *soundNode= sn->getChild("sound"); for(unsigned int i = 0; i < soundNodeList.size(); ++i) {
const XmlNode *soundNode= soundNodeList[i];
if(soundNode->getAttribute("enabled")->getBoolValue()) { if(soundNode->getAttribute("enabled")->getBoolValue()) {
soundStartTime= soundNode->getAttribute("start-time")->getFloatValue(); float soundStartTime= soundNode->getAttribute("start-time")->getFloatValue();
sounds.resize((int)soundNode->getChildCount()); 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) { for(int i = 0; i < (int)soundNode->getChildCount(); ++i) {
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true); 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(); StaticSound *sound= new StaticSound();
sound->load(path); sound->load(path);
loadedFileList[path].push_back(make_pair(parentLoader,soundFileNode->getAttribute("path")->getRestrictedValue())); 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; // SoundContainer sounds;
// float soundStartTime; // float soundStartTime;
skillTypeNode->addAttribute("soundStartTime",floatToStr(soundStartTime,6), mapTagReplacements); // skillTypeNode->addAttribute("soundStartTime",floatToStr(soundStartTime,6), mapTagReplacements);
// RandomGen random; // RandomGen random;
skillTypeNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements); skillTypeNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
// AttackBoost attackBoost; // AttackBoost attackBoost;
@ -1299,6 +1319,15 @@ void DieSkillType::saveGame(XmlNode *rootNode) {
dieSkillTypeNode->addAttribute("fade",intToStr(fade), mapTagReplacements); dieSkillTypeNode->addAttribute("fade",intToStr(fade), mapTagReplacements);
} }
StaticSound *DieSkillType::getSound() const{
if(skillSoundList.size()==0){
return NULL;
}
else {
return skillSoundList.front()->getSoundContainer()->getRandSound();
}
}
// ===================================================== // =====================================================
// class FogOfWarSkillType // class FogOfWarSkillType

View File

@ -125,8 +125,29 @@ public:
int toHp; 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<SkillSound*> SkillSoundList;
class SkillType { class SkillType {
protected: protected:
SkillClass skillClass; SkillClass skillClass;
string name; string name;
@ -157,8 +178,7 @@ protected:
vector<Model *> animations; vector<Model *> animations;
vector<AnimationAttributes> animationAttributes; vector<AnimationAttributes> animationAttributes;
SoundContainer sounds; SkillSoundList skillSoundList;
float soundStartTime;
RandomGen random; RandomGen random;
AttackBoost attackBoost; AttackBoost attackBoost;
@ -197,14 +217,14 @@ public:
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, const Unit *unit=NULL, int *lastAnimationIndex=NULL, int *animationRandomCycleCount=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;}
float getShakeStartTime() const {return shakeStartTime;} float getShakeStartTime() const {return shakeStartTime;}
bool getShake() const {return shake;} bool getShake() const {return shake;}
int getShakeIntensity() const {return shakeIntensity;} int getShakeIntensity() const {return shakeIntensity;}
int getShakeDuration() const {return shakeDuration;} int getShakeDuration() const {return shakeDuration;}
const SkillSoundList * getSkillSoundList() const {return &skillSoundList;}
bool getShakeSelfEnabled() const {return shakeSelfEnabled;} bool getShakeSelfEnabled() const {return shakeSelfEnabled;}
bool getShakeSelfVisible() const {return shakeSelfVisible;} bool getShakeSelfVisible() const {return shakeSelfVisible;}
bool getShakeSelfInCameraView() const {return shakeSelfInCameraView;} bool getShakeSelfInCameraView() const {return shakeSelfInCameraView;}
@ -450,6 +470,7 @@ public:
virtual string toString(bool translatedValue) const; virtual string toString(bool translatedValue) const;
virtual void saveGame(XmlNode *rootNode); virtual void saveGame(XmlNode *rootNode);
StaticSound *getSound() const;
}; };
// =============================== // ===============================

View File

@ -128,16 +128,18 @@ bool UnitUpdater::updateUnit(Unit *unit) {
//play skill sound //play skill sound
const SkillType *currSkill= unit->getCurrSkill(); 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(soundStartTime >= unit->getLastAnimProgressAsFloat() && soundStartTime < unit->getAnimProgressAsFloat()) {
if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex()) || if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex()) ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true)) { (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()) { if (currSkill->getShake()) {
float shakeStartTime = currSkill->getShakeStartTime(); float shakeStartTime = currSkill->getShakeStartTime();
if (shakeStartTime >= unit->getLastAnimProgressAsFloat() if (shakeStartTime >= unit->getLastAnimProgressAsFloat()