multishot with multi sounds and possible camerashake on projectile impact.

Still work in progress!
This commit is contained in:
titiger 2014-07-19 18:50:47 +02:00
parent b72f4857d7
commit 762f09ab43
4 changed files with 85 additions and 31 deletions

View File

@ -24,9 +24,9 @@ ProjectileType::ProjectileType() {
projectileParticleSystemType=NULL; projectileParticleSystemType=NULL;
attackStartTime=0.0f; attackStartTime=0.0f;
splash=false; splash=false;
splashRadius=0; splashRadius=0;
splashDamageAll=true; splashDamageAll=true;
splashParticleSystemType=NULL; splashParticleSystemType=NULL;
shake=false; shake=false;
@ -35,7 +35,7 @@ ProjectileType::ProjectileType() {
shakeVisible=true; shakeVisible=true;
shakeInCameraView=true; shakeInCameraView=true;
shakeCameraAffected=false; shakeCameraDistanceAffected=false;
} }
@ -67,19 +67,34 @@ void ProjectileType::load(const XmlNode *projectileNode, const string &dir, cons
} }
} }
const XmlNode *soundNode= projectileNode->getChild("sound"); if(projectileNode->hasChild("hitshake")){
if(soundNode->getAttribute("enabled")->getBoolValue()){ const XmlNode *hitShakeNode= projectileNode->getChild("hitshake");
shake=hitShakeNode->getAttribute("enabled")->getBoolValue();
if(shake){
shakeIntensity=hitShakeNode->getAttribute("intensity")->getIntValue();
shakeDuration=hitShakeNode->getAttribute("duration")->getIntValue();
hitSounds.resize((int)soundNode->getChildCount()); shakeVisible=hitShakeNode->getAttribute("visible")->getBoolValue();
for(int i=0; i < (int)soundNode->getChildCount(); ++i){ shakeInCameraView=hitShakeNode->getAttribute("in-camera-view")->getBoolValue();
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); shakeCameraDistanceAffected=hitShakeNode->getAttribute("camera-distance-affected")->getBoolValue();
string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true); }
//printf("\n\n\n\n!@#$ ---> parentLoader [%s] path [%s] nodeValue [%s] i = %d",parentLoader.c_str(),path.c_str(),soundFileNode->getAttribute("path")->getRestrictedValue().c_str(),i); }
StaticSound *sound= new StaticSound(); if(projectileNode->hasChild("hitsound")){
sound->load(path); const XmlNode *soundNode= projectileNode->getChild("hitsound");
loadedFileList[path].push_back(make_pair(parentLoader,soundFileNode->getAttribute("path")->getRestrictedValue())); if(soundNode->getAttribute("enabled")->getBoolValue()){
hitSounds[i]= sound;
hitSounds.resize((int)soundNode->getChildCount());
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);
//printf("\n\n\n\n!@#$ ---> parentLoader [%s] path [%s] nodeValue [%s] i = %d",parentLoader.c_str(),path.c_str(),soundFileNode->getAttribute("path")->getRestrictedValue().c_str(),i);
StaticSound *sound= new StaticSound();
sound->load(path);
loadedFileList[path].push_back(make_pair(parentLoader,soundFileNode->getAttribute("path")->getRestrictedValue()));
hitSounds[i]= sound;
}
} }
} }
} }

View File

@ -52,7 +52,7 @@ protected:
bool shakeVisible; bool shakeVisible;
bool shakeInCameraView; bool shakeInCameraView;
bool shakeCameraAffected; bool shakeCameraDistanceAffected;
public: public:
ProjectileType(); ProjectileType();
@ -73,7 +73,7 @@ public:
int getSplashRadius() const { return splashRadius;} int getSplashRadius() const { return splashRadius;}
bool isShake() const{return shake;} bool isShake() const{return shake;}
bool isShakeCameraAffected() const{return shakeCameraAffected;} bool isShakeCameraDistanceAffected() const{return shakeCameraDistanceAffected;}
int getShakeDuration() const{return shakeDuration;} int getShakeDuration() const{return shakeDuration;}
bool isShakeInCameraView() const{return shakeInCameraView;} bool isShakeInCameraView() const{return shakeInCameraView;}
int getShakeIntensity() const{return shakeIntensity;} int getShakeIntensity() const{return shakeIntensity;}

View File

@ -881,19 +881,7 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
} }
} }
if(sn->hasChild("projectiles")){ if(sn->hasChild("projectile")){
const XmlNode *projectilesNode= sn->getChild("projectiles");
vector<XmlNode *> projectilesNodeList = projectilesNode->getChildList("projectile");
for(unsigned int i = 0; i < projectilesNodeList.size(); ++i) {
const XmlNode *projectileNode= projectilesNodeList[i];
ProjectileType *projectileType=new ProjectileType();
projectileType->load(projectileNode,dir, tt->getPath(), loadedFileList, parentLoader);
projectileTypes.push_back(projectileType);
projectile=true;
}
}
else {
//projectile -- backward compatible old behaviour with only one projectile //projectile -- backward compatible old behaviour with only one projectile
const XmlNode *projectileNode= sn->getChild("projectile"); const XmlNode *projectileNode= sn->getChild("projectile");
projectile= projectileNode->getAttribute("value")->getBoolValue(); projectile= projectileNode->getAttribute("value")->getBoolValue();
@ -934,6 +922,34 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
} }
} }
} }
else {
const XmlNode *projectilesNode= sn->getChild("projectiles");
vector<XmlNode *> projectilesNodeList = projectilesNode->getChildList("projectile");
for(unsigned int i = 0; i < projectilesNodeList.size(); ++i) {
const XmlNode *projectileNode= projectilesNodeList[i];
ProjectileType *projectileType=new ProjectileType();
projectileType->load(projectileNode,dir, tt->getPath(), loadedFileList, parentLoader);
projectileTypes.push_back(projectileType);
projectile=true;
}
//general hit sounds, individual ones can be set in projectiles
const XmlNode *soundNode= sn->getChild("hitsound");
if(soundNode->getAttribute("enabled")->getBoolValue()){
projSounds.resize((int)soundNode->getChildCount());
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);
//printf("\n\n\n\n!@#$ ---> parentLoader [%s] path [%s] nodeValue [%s] i = %d",parentLoader.c_str(),path.c_str(),soundFileNode->getAttribute("path")->getRestrictedValue().c_str(),i);
StaticSound *sound= new StaticSound();
sound->load(path);
loadedFileList[path].push_back(make_pair(parentLoader,soundFileNode->getAttribute("path")->getRestrictedValue()));
projSounds[i]= sound;
}
}
}
//splash //splash
const XmlNode *splashNode= sn->getChild("splash"); const XmlNode *splashNode= sn->getChild("splash");

View File

@ -3254,10 +3254,33 @@ void ParticleDamager::update(ParticleSystem *particleSystem) {
//attacker->setNetworkCRCParticleObserverLogInfo(szBuf); //attacker->setNetworkCRCParticleObserverLogInfo(szBuf);
//play sound //play sound
StaticSound *projSound= ast->getProjSound(); // Try to use the sound form the projetileType
StaticSound *projSound=projectileType->getHitSound();
if(projSound == NULL){
// use the sound from the skill
projSound= ast->getProjSound();
}
if(particleSystem->getVisible() && projSound != NULL) { if(particleSystem->getVisible() && projSound != NULL) {
SoundRenderer::getInstance().playFx(projSound, attacker->getCurrVector(), gameCamera->getPos()); SoundRenderer::getInstance().playFx(projSound, attacker->getCurrVector(), gameCamera->getPos());
} }
// check for shake and shake
if(projectileType->isShake()==true){
World *world=attacker->getFaction()->getWorld();
Map* map=world->getMap();
Game *game=world->getGame();
//Unit *attacked= map->getCell(targetPos)->getUnit(targetField);
Vec2i surfaceTargetPos=Map::toSurfCoords(targetPos);
bool visibility=(!projectileType->isShakeVisible())||(map->getSurfaceCell(surfaceTargetPos)->isVisible(world->getThisTeamIndex()) ||
(game->getWorld()->showWorldForPlayer(game->getWorld()->getThisTeamIndex()) == true));
bool isInCameraView=(!projectileType->isShakeInCameraView()) || Renderer::getInstance().posInCellQuadCache(surfaceTargetPos).first;
if(visibility && isInCameraView) {
game->getGameCameraPtr()->shake( projectileType->getShakeDuration(), projectileType->getShakeIntensity(),projectileType->isShakeCameraDistanceAffected(),map->getSurfaceCell(surfaceTargetPos)->getVertex());
}
}
} }
particleSystem->setObserver(NULL); particleSystem->setObserver(NULL);
delete this; delete this;