summaryrefslogtreecommitdiff
path: root/src/itemsoundmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-08-06 23:35:58 +0300
committerAndrei Karas <akaras@inbox.ru>2018-08-06 23:35:58 +0300
commit5a6b02b6aba646816a7d27a85dd6724de554a157 (patch)
tree77f5d1c6b94f8a549b7be20c1188091a4b3cd0f2 /src/itemsoundmanager.cpp
parent3b5390eee9c3e031867d3acfce574f1993d46b76 (diff)
downloadplus-5a6b02b6aba646816a7d27a85dd6724de554a157.tar.gz
plus-5a6b02b6aba646816a7d27a85dd6724de554a157.tar.bz2
plus-5a6b02b6aba646816a7d27a85dd6724de554a157.tar.xz
plus-5a6b02b6aba646816a7d27a85dd6724de554a157.zip
Play item usage sound to every player around.
Diffstat (limited to 'src/itemsoundmanager.cpp')
-rw-r--r--src/itemsoundmanager.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/itemsoundmanager.cpp b/src/itemsoundmanager.cpp
index 1ea66d046..b33d2056f 100644
--- a/src/itemsoundmanager.cpp
+++ b/src/itemsoundmanager.cpp
@@ -53,16 +53,38 @@ void ItemSoundManager::playSfx(const FloorItem *const item,
playSfx(ItemDB::get(item->getItemId()), sound);
}
-void ItemSoundManager::playSfx(const ItemInfo &info,
- const ItemSoundEvent::Type sound)
+std::string ItemSoundManager::getSoundEffect(const Being *const being,
+ const ItemInfo &info,
+ const ItemSoundEvent::Type sound)
{
std::string sfx = info.getSound(sound).sound;
if (sfx.empty())
{
+ if (being == nullptr)
+ return std::string();
+
// fallback to player race sound if no item sound.
- const int id = -100 - toInt(localPlayer->getSubType(), int);
+ const int id = -100 - toInt(being->getSubType(), int);
const ItemInfo &info2 = ItemDB::get(id);
sfx = info2.getSound(sound).sound;
}
- soundManager.playGuiSfx(sfx);
+ return sfx;
+}
+
+void ItemSoundManager::playSfx(const ItemInfo &info,
+ const ItemSoundEvent::Type sound)
+{
+ soundManager.playGuiSfx(getSoundEffect(localPlayer, info, sound));
+}
+
+void ItemSoundManager::playSfx(const Being *const being,
+ const int itemId,
+ const ItemSoundEvent::Type sound)
+{
+ if (being == nullptr)
+ return;
+
+ soundManager.playSfx(getSoundEffect(being, ItemDB::get(itemId), sound),
+ being->getTileX(),
+ being->getTileY());
}