summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-16 23:06:58 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-18 21:31:52 +0300
commit67d3b8c193b51bbf892fd965547746511e8ddf87 (patch)
treeb11031d009c6df44263f0be9f01503fae2c09615
parent884c064f762c4d5ca23458ea43d9c34348259840 (diff)
downloadplus-67d3b8c193b51bbf892fd965547746511e8ddf87.tar.gz
plus-67d3b8c193b51bbf892fd965547746511e8ddf87.tar.bz2
plus-67d3b8c193b51bbf892fd965547746511e8ddf87.tar.xz
plus-67d3b8c193b51bbf892fd965547746511e8ddf87.zip
add delay to action sounds.
delay now unused.
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/Makefile.am1
-rw-r--r--src/being.cpp60
-rw-r--r--src/being.h2
-rw-r--r--src/gui/skilldialog.cpp13
-rw-r--r--src/gui/skilldialog.h6
-rw-r--r--src/resources/beinginfo.cpp11
-rw-r--r--src/resources/beinginfo.h10
-rw-r--r--src/resources/itemdb.cpp5
-rw-r--r--src/resources/iteminfo.cpp17
-rw-r--r--src/resources/iteminfo.h20
-rw-r--r--src/resources/monsterdb.cpp18
-rw-r--r--src/resources/sounddb.cpp2
-rw-r--r--src/resources/sounddb.h2
-rw-r--r--src/resources/soundinfo.h43
15 files changed, 127 insertions, 86 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 84388508d..7aaeee334 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -464,8 +464,9 @@ SET(SRCS
resources/sdlmusic.h
resources/sounddb.cpp
resources/sounddb.h
- resources/soundeffect.h
resources/soundeffect.cpp
+ resources/soundeffect.h
+ resources/soundinfo.h
resources/spritedef.h
resources/spritedef.cpp
resources/subimage.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 4c9ccb872..22c7ffb14 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -467,6 +467,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/sounddb.h \
resources/soundeffect.cpp \
resources/soundeffect.h \
+ resources/soundinfo.h \
resources/spritedef.cpp \
resources/spritedef.h \
resources/subimage.cpp \
diff --git a/src/being.cpp b/src/being.cpp
index 564cdec34..ec682ba7d 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -654,8 +654,7 @@ void Being::takeDamage(Being *const attacker, const int amount,
mDamageTaken += amount;
if (mInfo)
{
- soundManager.playSfx(mInfo->getSound(SOUND_EVENT_HURT),
- getTileX(), getTileY());
+ playSfx(mInfo->getSound(SOUND_EVENT_HURT), mX, mY);
if (!mInfo->isStaticMaxHP())
{
@@ -808,34 +807,17 @@ void Being::handleAttack(Being *const victim, const int damage,
if (mSpriteIDs.size() >= 10)
{
// here 10 is weapon slot
- const int weaponId = mSpriteIDs[10];
- std::string soundFile;
- if (weaponId > 0)
- {
- const ItemInfo &info = ItemDB::get(weaponId);
- soundFile = info.getSound((damage > 0) ?
- EQUIP_EVENT_HIT : EQUIP_EVENT_STRIKE);
- }
- else
- {
- soundFile = mInfo->getSound((damage > 0) ?
- SOUND_EVENT_HIT : SOUND_EVENT_MISS);
- }
- if (!soundFile.empty())
- {
- soundManager.playSfx(soundFile, mX, mY);
- }
- else
- {
- soundManager.playSfx(paths.getValue((damage > 0)
- ? "attackSfxFile" : "missSfxFile",
- "fist-swish.ogg"), mX, mY);
- }
+ int weaponId = mSpriteIDs[10];
+ if (!weaponId)
+ weaponId = -100 - mSubType;
+ const ItemInfo &info = ItemDB::get(weaponId);
+ playSfx(info.getSound((damage > 0) ?
+ SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY);
}
}
else
{
- soundManager.playSfx(mInfo->getSound((damage > 0) ?
+ playSfx(mInfo->getSound((damage > 0) ?
SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY);
}
}
@@ -872,17 +854,16 @@ void Being::handleSkill(Being *const victim, const int damage,
}
if (damage && victim->mType == PLAYER && victim->mAction == SIT)
victim->setAction(STAND);
-
if (data)
{
if (damage > 0)
- soundManager.playSfx(data->soundHit, mX, mY);
+ playSfx(data->soundHit, mX, mY);
else
- soundManager.playSfx(data->soundMiss, mX, mY);
+ playSfx(data->soundMiss, mX, mY);
}
else
{
- soundManager.playSfx(mInfo->getSound((damage > 0) ?
+ playSfx(mInfo->getSound((damage > 0) ?
SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY);
}
}
@@ -1118,7 +1099,7 @@ void Being::setAction(const Action &action, const int attackId)
case MOVE:
if (mInfo)
{
- soundManager.playSfx(mInfo->getSound(
+ playSfx(mInfo->getSound(
SOUND_EVENT_MOVE), mX, mY);
}
currentAction = SpriteAction::MOVE;
@@ -1135,7 +1116,7 @@ void Being::setAction(const Action &action, const int attackId)
event = SOUND_EVENT_SITTOP;
else
event = SOUND_EVENT_SIT;
- soundManager.playSfx(mInfo->getSound(event), mX, mY);
+ playSfx(mInfo->getSound(event), mX, mY);
}
break;
case ATTACK:
@@ -1182,15 +1163,14 @@ void Being::setAction(const Action &action, const int attackId)
case HURT:
if (mInfo)
{
- soundManager.playSfx(mInfo->getSound(
- SOUND_EVENT_HURT), mX, mY);
+ playSfx(mInfo->getSound(SOUND_EVENT_HURT), mX, mY);
}
break;
case DEAD:
currentAction = SpriteAction::DEAD;
if (mInfo)
{
- soundManager.playSfx(mInfo->getSound(SOUND_EVENT_DIE), mX, mY);
+ playSfx(mInfo->getSound(SOUND_EVENT_DIE), mX, mY);
if (mType == MONSTER || mType == NPC)
mYDiff = mInfo->getDeadSortOffsetY();
}
@@ -1200,10 +1180,7 @@ void Being::setAction(const Action &action, const int attackId)
break;
case SPAWN:
if (mInfo)
- {
- soundManager.playSfx(mInfo->getSound(
- SOUND_EVENT_SPAWN), mX, mY);
- }
+ playSfx(mInfo->getSound(SOUND_EVENT_SPAWN), mX, mY);
currentAction = SpriteAction::SPAWN;
break;
default:
@@ -2955,6 +2932,11 @@ BeingEquipBackend::BeingEquipBackend(Being *const being):
}
}
+void Being::playSfx(const SoundInfo &sound, const int x, const int y)
+{
+ soundManager.playSfx(sound.sound, x, y);
+}
+
BeingEquipBackend::~BeingEquipBackend()
{
clear();
diff --git a/src/being.h b/src/being.h
index d54c4fad1..c1adbbbcb 100644
--- a/src/being.h
+++ b/src/being.h
@@ -878,6 +878,8 @@ class Being : public ActorSprite, public ConfigListener
void setOwner(Being *const owner)
{ mOwner = owner; }
+ void playSfx(const SoundInfo &sound, const int x, const int y);
+
static uint8_t genderToInt(const Gender sex) A_WARN_UNUSED;
static Gender intToGender(uint8_t sex) A_WARN_UNUSED;
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 2a673a277..cb4d2e481 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -525,10 +525,15 @@ void SkillDialog::loadSkills()
node, "description", "");
data->particle = XML::getProperty(
node, "particle", "");
- data->soundHit = XML::getProperty(
+
+ data->soundHit.sound = XML::getProperty(
node, "soundHit", "");
- data->soundMiss = XML::getProperty(
+ data->soundHit.delay = XML::getProperty(
+ node, "soundHitDelay", 0);
+ data->soundMiss.sound = XML::getProperty(
node, "soundMiss", "");
+ data->soundMiss.delay = XML::getProperty(
+ node, "soundMissDelay", 0);
skill->addData(level, data);
}
@@ -773,7 +778,9 @@ SkillData *SkillInfo::getData1(const int lev)
}
SkillData::SkillData() :
- icon(nullptr)
+ icon(nullptr),
+ soundHit("", 0),
+ soundMiss("", 0)
{
}
diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h
index 968e171d9..2a9f69a77 100644
--- a/src/gui/skilldialog.h
+++ b/src/gui/skilldialog.h
@@ -25,6 +25,8 @@
#include "gui/widgets/window.h"
+#include "resources/soundinfo.h"
+
#include <guichan/actionlistener.hpp>
#include <guichan/mouselistener.hpp>
@@ -50,8 +52,8 @@ struct SkillData final
Image *icon;
std::string particle;
- std::string soundHit;
- std::string soundMiss;
+ SoundInfo soundHit;
+ SoundInfo soundMiss;
SkillData();
A_DELETE_COPY(SkillData)
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index fc6139e83..99ce2ff6f 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -92,18 +92,19 @@ void BeingInfo::setTargetCursorSize(const std::string &size)
}
}
-void BeingInfo::addSound(const SoundEvent event, const std::string &filename)
+void BeingInfo::addSound(const SoundEvent event, const std::string &filename,
+ const int delay)
{
if (mSounds.find(event) == mSounds.end())
- mSounds[event] = new StringVect;
+ mSounds[event] = new SoundInfoVect;
if (mSounds[event])
- mSounds[event]->push_back("sfx/" + filename);
+ mSounds[event]->push_back(SoundInfo("sfx/" + filename, delay));
}
-const std::string &BeingInfo::getSound(const SoundEvent event) const
+const SoundInfo &BeingInfo::getSound(const SoundEvent event) const
{
- static std::string emptySound("");
+ static SoundInfo emptySound("", 0);
const SoundEvents::const_iterator i = mSounds.find(event);
return (i == mSounds.end() || !i->second) ? emptySound :
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index b5ca37bf7..9bf5417fa 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -26,6 +26,7 @@
#include "actorsprite.h"
#include "resources/cursor.h"
+#include "resources/soundinfo.h"
#include <list>
#include <map>
@@ -68,7 +69,7 @@ enum SoundEvent
SOUND_EVENT_SPAWN
};
-typedef std::map<SoundEvent, StringVect*> SoundEvents;
+typedef std::map<SoundEvent, SoundInfoVect*> SoundEvents;
/**
* Holds information about a certain type of monster. This includes the name
@@ -118,10 +119,11 @@ class BeingInfo final
ActorSprite::TargetCursorSize getTargetCursorSize() const A_WARN_UNUSED
{ return mTargetCursorSize; }
- void addSound(const SoundEvent event, const std::string &filename);
+ void addSound(const SoundEvent event, const std::string &filename,
+ const int delay);
- const std::string &getSound(const SoundEvent event)
- const A_WARN_UNUSED;
+ const SoundInfo &getSound(const SoundEvent event)
+ const A_WARN_UNUSED;
void addAttack(const int id, std::string action, const int effectId,
const int hitEffectId, const int criticalHitEffectId,
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 400c42d4f..f5d6e54ce 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -672,14 +672,15 @@ void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node)
const std::string event = XML::getProperty(node, "event", "");
const std::string filename = reinterpret_cast<const char*>(
node->xmlChildrenNode->content);
+ const int delay = XML::getProperty(node, "delay", 0);
if (event == "hit")
{
- itemInfo->addSound(EQUIP_EVENT_HIT, filename);
+ itemInfo->addSound(SOUND_EVENT_HIT, filename, delay);
}
else if (event == "strike" || event == "miss")
{
- itemInfo->addSound(EQUIP_EVENT_STRIKE, filename);
+ itemInfo->addSound(SOUND_EVENT_MISS, filename, delay);
}
else
{
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 4ec5d81f9..a6372ca93 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -23,6 +23,7 @@
#include "resources/iteminfo.h"
#include "resources/itemdb.h"
+
#include "configuration.h"
#include "utils/dtor.h"
@@ -105,22 +106,24 @@ void ItemInfo::setAttackAction(const std::string &attackAction)
mAttackAction = attackAction;
}
-void ItemInfo::addSound(const EquipmentSoundEvent event,
- const std::string &filename)
+void ItemInfo::addSound(const SoundEvent event,
+ const std::string &filename, const int delay)
{
- mSounds[event].push_back(paths.getStringValue("sfx").append(filename));
+ mSounds[event].push_back(SoundInfo(
+ paths.getStringValue("sfx").append(filename), delay));
}
-const std::string &ItemInfo::getSound(const EquipmentSoundEvent event) const
+const SoundInfo &ItemInfo::getSound(const SoundEvent event) const
{
- static const std::string empty;
- std::map<EquipmentSoundEvent, StringVect>::const_iterator i;
+ static const SoundInfo empty("", 0);
+ std::map<SoundEvent, SoundInfoVect>::const_iterator i;
i = mSounds.find(event);
if (i == mSounds.end())
return empty;
- return (!i->second.empty()) ? i->second[rand() % i->second.size()] : empty;
+ return (!i->second.empty()) ? i->second[rand()
+ % i->second.size()] : empty;
}
std::map<int, int> *ItemInfo::addReplaceSprite(const int sprite,
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index e5b6f96b8..12dbb3c03 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -26,18 +26,11 @@
#include "being.h"
#include "resources/colordb.h"
+#include "resources/soundinfo.h"
#include <map>
#include <set>
-enum EquipmentSoundEvent
-{
- // miss
- EQUIP_EVENT_STRIKE = 0,
- // hit
- EQUIP_EVENT_HIT
-};
-
enum EquipmentSlot
{
// Equipment rules:
@@ -215,11 +208,12 @@ class ItemInfo final
void setAttackRange(const int r)
{ mAttackRange = r; }
- void addSound(const EquipmentSoundEvent event,
- const std::string &filename);
+ void addSound(const SoundEvent event,
+ const std::string &filename,
+ const int delay);
- const std::string &getSound(const EquipmentSoundEvent event)
- const A_WARN_UNUSED;
+ const SoundInfo &getSound(const SoundEvent event)
+ const A_WARN_UNUSED;
int getDrawBefore(const int direction) const A_WARN_UNUSED;
@@ -328,7 +322,7 @@ class ItemInfo final
std::map <int, std::string> mAnimationFiles;
/** Stores the names of sounds to be played at certain event. */
- std::map <EquipmentSoundEvent, StringVect> mSounds;
+ std::map <SoundEvent, SoundInfoVect> mSounds;
std::map <int, int> mTags;
const std::map <int, ColorDB::ItemColor> *mColors;
std::string mColorList;
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index 2fe6596b0..269cd59cd 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -147,41 +147,43 @@ void MonsterDB::load()
const std::string event = XML::getProperty(
spriteNode, "event", "");
+ const int delay = XML::getProperty(
+ spriteNode, "delay", 0);
const char *filename;
filename = reinterpret_cast<const char*>(
spriteNode->xmlChildrenNode->content);
if (event == "hit")
{
- currentInfo->addSound(SOUND_EVENT_HIT, filename);
+ currentInfo->addSound(SOUND_EVENT_HIT, filename, delay);
}
else if (event == "miss")
{
- currentInfo->addSound(SOUND_EVENT_MISS, filename);
+ currentInfo->addSound(SOUND_EVENT_MISS, filename, delay);
}
else if (event == "hurt")
{
- currentInfo->addSound(SOUND_EVENT_HURT, filename);
+ currentInfo->addSound(SOUND_EVENT_HURT, filename, delay);
}
else if (event == "die")
{
- currentInfo->addSound(SOUND_EVENT_DIE, filename);
+ currentInfo->addSound(SOUND_EVENT_DIE, filename, delay);
}
else if (event == "move")
{
- currentInfo->addSound(SOUND_EVENT_MOVE, filename);
+ currentInfo->addSound(SOUND_EVENT_MOVE, filename, delay);
}
else if (event == "sit")
{
- currentInfo->addSound(SOUND_EVENT_SIT, filename);
+ currentInfo->addSound(SOUND_EVENT_SIT, filename, delay);
}
else if (event == "sittop")
{
- currentInfo->addSound(SOUND_EVENT_SITTOP, filename);
+ currentInfo->addSound(SOUND_EVENT_SITTOP, filename, delay);
}
else if (event == "spawn")
{
- currentInfo->addSound(SOUND_EVENT_SPAWN, filename);
+ currentInfo->addSound(SOUND_EVENT_SPAWN, filename, delay);
}
else
{
diff --git a/src/resources/sounddb.cpp b/src/resources/sounddb.cpp
index 28ab3509c..9cf303322 100644
--- a/src/resources/sounddb.cpp
+++ b/src/resources/sounddb.cpp
@@ -1,5 +1,5 @@
/*
- * Color database
+ * The ManaPlus Client
* Copyright (C) 2013 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
diff --git a/src/resources/sounddb.h b/src/resources/sounddb.h
index fc1a71229..560cdb4be 100644
--- a/src/resources/sounddb.h
+++ b/src/resources/sounddb.h
@@ -1,5 +1,5 @@
/*
- * Color database
+ * The ManaPlus Client
* Copyright (C) 2013 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
diff --git a/src/resources/soundinfo.h b/src/resources/soundinfo.h
new file mode 100644
index 000000000..f60892e1c
--- /dev/null
+++ b/src/resources/soundinfo.h
@@ -0,0 +1,43 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SOUNDINFO_H
+#define SOUNDINFO_H
+
+#include <string>
+#include <vector>
+
+#include "localconsts.h"
+
+struct SoundInfo final
+{
+ SoundInfo(const std::string &sound0, const int delay0) :
+ sound(sound0),
+ delay(delay0)
+ {
+ }
+
+ std::string sound;
+ int delay;
+};
+
+typedef std::vector<SoundInfo> SoundInfoVect;
+
+#endif