From 53833f3f145dd1d937d9e7754c03ffadb3db15e8 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Fri, 11 Oct 2024 23:11:11 +0200 Subject: Added support for hit/miss sounds on equipment for all players Previously only the local player's weapon "strike" sound would play, regardless of hit or miss. Now the sound is played in response to the SMSG_BEING_ACTION message, so it can be played for all players. Also added alias "miss", which is used by TMW in some places. Finally, when no weapon is equipped, it falls back to the sounds defined on the racesprite item (fixes punch sound on TMW). Closes #68 --- src/being.cpp | 33 +++++++++++++++++++++++++-------- src/localplayer.cpp | 11 ----------- src/net/tmwa/beinghandler.cpp | 6 +----- src/resources/itemdb.cpp | 6 +++--- src/resources/iteminfo.h | 6 +++--- 5 files changed, 32 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 5e869662..7c77f19f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -416,17 +416,34 @@ void Being::handleAttack(Being *victim, int damage, int attackId) setAction(Being::ATTACK, attackId); if (victim) + { lookAt(victim->getPosition()); - if (getType() == PLAYER && victim && mEquippedWeapon) - fireMissile(victim, mEquippedWeapon->missileParticleFile); - else - fireMissile(victim, - mInfo->getAttack(attackId).missileParticleFilename); + if (getType() == PLAYER && mEquippedWeapon) + fireMissile(victim, mEquippedWeapon->missileParticleFile); + else + fireMissile(victim, mInfo->getAttack(attackId).missileParticleFilename); + } + + if (getType() == PLAYER) + { + auto itemInfo = mEquippedWeapon; + + // Fall back to racesprite item + if (!itemInfo) + itemInfo = &itemDb->get(-100 - mSubType); - sound.playSfx(mInfo->getSound((damage > 0) ? - SoundEvent::HIT : SoundEvent::MISS), - getPixelX(), getPixelY()); + const auto event = damage > 0 ? EquipmentSoundEvent::HIT + : EquipmentSoundEvent::STRIKE; + const auto &soundFile = itemInfo->getSound(event); + sound.playSfx(soundFile, getPixelX(), getPixelY()); + } + else + { + const auto event = damage > 0 ? SoundEvent::HIT : SoundEvent::MISS; + const auto &soundFile = mInfo->getSound(event); + sound.playSfx(soundFile, getPixelX(), getPixelY()); + } } void Being::setName(const std::string &name) diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 40849379..43c54731 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -837,17 +837,6 @@ void LocalPlayer::attack(Being *target, bool keep) setAction(ATTACK); - if (mEquippedWeapon) - { - std::string soundFile = mEquippedWeapon->getSound(EQUIP_EVENT_STRIKE); - if (!soundFile.empty()) - sound.playSfx(soundFile); - } - else - { - sound.playSfx(paths.getValue("attackSfxFile", "fist-swish.ogg")); - } - Net::getPlayerHandler()->attack(target->getId()); } diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 33adb93b..159352cc 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -360,23 +360,19 @@ void BeingHandler::handleMessage(MessageIn &msg) case Being::FLEE: // Lucky Dodge if (dstBeing) dstBeing->takeDamage(srcBeing, param1, - (Being::AttackType)type); + static_cast(type)); if (srcBeing) srcBeing->handleAttack(dstBeing, param1); break; case 0x02: // Sit if (srcBeing) - { srcBeing->setAction(Being::SIT); - } break; case 0x03: // Stand up if (srcBeing) - { srcBeing->setAction(Being::STAND); - } break; } break; diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index bb5b5abd..28830e67 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -137,11 +137,11 @@ void ItemDB::loadSoundRef(ItemInfo &itemInfo, xmlNodePtr node) if (event == "hit") { - itemInfo.addSound(EQUIP_EVENT_HIT, filename); + itemInfo.addSound(EquipmentSoundEvent::HIT, filename); } - else if (event == "strike") + else if (event == "strike" || event == "miss") { - itemInfo.addSound(EQUIP_EVENT_STRIKE, filename); + itemInfo.addSound(EquipmentSoundEvent::STRIKE, filename); } else { diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index a5b62fdc..78c808da 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -30,10 +30,10 @@ #include #include -enum EquipmentSoundEvent +enum class EquipmentSoundEvent { - EQUIP_EVENT_STRIKE, - EQUIP_EVENT_HIT + STRIKE, + HIT }; /** -- cgit v1.2.3-70-g09d2