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;
attackStartTime=0.0f;
splash=false;
splashRadius=0;
splashDamageAll=true;
splash=false;
splashRadius=0;
splashDamageAll=true;
splashParticleSystemType=NULL;
shake=false;
@ -35,7 +35,7 @@ ProjectileType::ProjectileType() {
shakeVisible=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(soundNode->getAttribute("enabled")->getBoolValue()){
if(projectileNode->hasChild("hitshake")){
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());
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);
shakeVisible=hitShakeNode->getAttribute("visible")->getBoolValue();
shakeInCameraView=hitShakeNode->getAttribute("in-camera-view")->getBoolValue();
shakeCameraDistanceAffected=hitShakeNode->getAttribute("camera-distance-affected")->getBoolValue();
}
}
StaticSound *sound= new StaticSound();
sound->load(path);
loadedFileList[path].push_back(make_pair(parentLoader,soundFileNode->getAttribute("path")->getRestrictedValue()));
hitSounds[i]= sound;
if(projectileNode->hasChild("hitsound")){
const XmlNode *soundNode= projectileNode->getChild("hitsound");
if(soundNode->getAttribute("enabled")->getBoolValue()){
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 shakeInCameraView;
bool shakeCameraAffected;
bool shakeCameraDistanceAffected;
public:
ProjectileType();
@ -73,7 +73,7 @@ public:
int getSplashRadius() const { return splashRadius;}
bool isShake() const{return shake;}
bool isShakeCameraAffected() const{return shakeCameraAffected;}
bool isShakeCameraDistanceAffected() const{return shakeCameraDistanceAffected;}
int getShakeDuration() const{return shakeDuration;}
bool isShakeInCameraView() const{return shakeInCameraView;}
int getShakeIntensity() const{return shakeIntensity;}

View File

@ -881,19 +881,7 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
}
}
if(sn->hasChild("projectiles")){
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 {
if(sn->hasChild("projectile")){
//projectile -- backward compatible old behaviour with only one projectile
const XmlNode *projectileNode= sn->getChild("projectile");
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
const XmlNode *splashNode= sn->getChild("splash");

View File

@ -3254,10 +3254,33 @@ void ParticleDamager::update(ParticleSystem *particleSystem) {
//attacker->setNetworkCRCParticleObserverLogInfo(szBuf);
//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) {
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);
delete this;