diff --git a/src/xrGame/Explosive.cpp b/src/xrGame/Explosive.cpp index c37e5bb6f23..695e9cf741a 100644 --- a/src/xrGame/Explosive.cpp +++ b/src/xrGame/Explosive.cpp @@ -75,9 +75,23 @@ void CExplosive::LightCreate() m_pLight->set_shadow(true); } -void CExplosive::LightDestroy() { m_pLight.destroy(); } -CExplosive::~CExplosive(void) { sndExplode.destroy(); } -void CExplosive::Load(LPCSTR section) { Load(pSettings, section); } +void CExplosive::LightDestroy() +{ + m_pLight.destroy(); +} + +CExplosive::~CExplosive(void) +{ +#ifndef LAYERED_SND_SHOOT + sndExplode.destroy(); +#endif +} + +void CExplosive::Load(LPCSTR section) +{ + Load(pSettings, section); +} + void CExplosive::Load(CInifile const* ini, LPCSTR section) { m_fBlastHit = ini->r_float(section, "blast"); @@ -106,8 +120,13 @@ void CExplosive::Load(CInifile const* ini, LPCSTR section) //трассы для разлета осколков m_fFragmentSpeed = ini->r_float(section, "fragment_speed"); + //Alundaio: LAYERED_SND_SHOOT +#ifdef LAYERED_SND_SHOOT + m_layered_sounds.LoadSound(ini, section, "snd_explode", "sndExplode", false, m_eSoundExplode); +#else LPCSTR snd_name = ini->r_string(section, "snd_explode"); sndExplode.create(snd_name, st_Effect, m_eSoundExplode); +#endif m_fExplodeDurationMax = ini->r_float(section, "explode_duration"); @@ -333,7 +352,11 @@ void CExplosive::Explode() // Msg("---------CExplosive Explode [%d] frame[%d]",cast_game_object()->ID(), Device.dwFrame); OnBeforeExplosion(); //играем звук взрыва +#ifdef LAYERED_SND_SHOOT + m_layered_sounds.PlaySound("sndExplode", pos, smart_cast(this), false, false, (u8)-1); +#else GEnv.Sound->play_at_pos(sndExplode, 0, pos, false); +#endif //показываем эффекты diff --git a/src/xrGame/Explosive.h b/src/xrGame/Explosive.h index eb46c6bb083..fe3ec90c7b7 100644 --- a/src/xrGame/Explosive.h +++ b/src/xrGame/Explosive.h @@ -77,6 +77,13 @@ class CExplosive : public IDamageSource void LightDestroy(); protected: + + //Alundaio: LAYERED_SND_SHOOT +#ifdef LAYERED_SND_SHOOT + HUD_SOUND_COLLECTION_LAYERED m_layered_sounds; +#endif + //-Alundaio + CWalmarkManager m_wallmark_manager; // ID персонажа который иницировал действие u16 m_iCurrentParentID; diff --git a/src/xrGame/HudSound.cpp b/src/xrGame/HudSound.cpp index 280fab789d6..84a352bce96 100644 --- a/src/xrGame/HudSound.cpp +++ b/src/xrGame/HudSound.cpp @@ -169,11 +169,12 @@ void HUD_SOUND_COLLECTION::LoadSound(LPCSTR section, LPCSTR line, LPCSTR alias, snd_item.m_alias = alias; snd_item.m_b_exclusive = exclusive; } + //Alundaio: /* - It's usage is to play a group of sounds HUD_SOUND_ITEMs as if they were a single layered entity. This is a achieved by - wrapping the class around HUD_SOUND_COLLECTION and tagging them with the same alias. This way, when one for example - sndShot is played, it will play all the sound items with the same alias. + It's usage is to play a group of sounds HUD_SOUND_ITEMs as if they were a single layered entity. This is a achieved by + wrapping the class around HUD_SOUND_COLLECTION and tagging them with the same alias. This way, when one for example + sndShot is played, it will play all the sound items with the same alias. */ //---------------------------------------------------------- #ifdef LAYERED_SND_SHOOT @@ -205,8 +206,7 @@ void HUD_SOUND_COLLECTION_LAYERED::SetPosition(pcstr alias, const Fvector& pos) sound_item.SetPosition(alias, pos); } -void HUD_SOUND_COLLECTION_LAYERED::PlaySound(pcstr alias, const Fvector& position, const IGameObject* parent, - bool hud_mode, bool looped, u8 index) +void HUD_SOUND_COLLECTION_LAYERED::PlaySound(pcstr alias, const Fvector& position, const IGameObject* parent, bool hud_mode, bool looped, u8 index) { for (auto& sound_item : m_sound_items) if (sound_item.m_alias == alias) @@ -236,9 +236,42 @@ void HUD_SOUND_COLLECTION_LAYERED::LoadSound(pcstr section, pcstr line, pcstr al if (pSettings->section_exist(buf_str)) { string256 sound_line; - xr_strcpy(sound_line, "snd_1_layer"); + xr_strcpy(sound_line,"snd_1_layer"); int k = 1; while (pSettings->line_exist(buf_str, sound_line)) + { + m_sound_items.resize(m_sound_items.size() + 1); + HUD_SOUND_COLLECTION& snd_item = m_sound_items.back(); + snd_item.LoadSound(buf_str, sound_line, alias, exclusive, type); + snd_item.m_alias = alias; + xr_sprintf(sound_line,"snd_%d_layer", ++k); + } + } + else // For compatibility with normal HUD_SOUND_COLLECTION sounds + { + m_sound_items.resize(m_sound_items.size() + 1); + HUD_SOUND_COLLECTION& snd_item = m_sound_items.back(); + snd_item.LoadSound(section, line, alias, exclusive, type); + snd_item.m_alias = alias; + } +} + +void HUD_SOUND_COLLECTION_LAYERED::LoadSound(CInifile const *ini, pcstr section, pcstr line, pcstr alias, bool exclusive, int type) +{ + pcstr str = ini->r_string(section, line); + string256 buf_str; + + int count = _GetItemCount(str); + R_ASSERT(count); + + _GetItem(str, 0, buf_str); + + if (ini->section_exist(buf_str)) + { + string256 sound_line; + xr_strcpy(sound_line, "snd_1_layer"); + int k = 1; + while (ini->line_exist(buf_str, sound_line)) { m_sound_items.resize(m_sound_items.size() + 1); HUD_SOUND_COLLECTION& snd_item = m_sound_items.back(); @@ -256,4 +289,4 @@ void HUD_SOUND_COLLECTION_LAYERED::LoadSound(pcstr section, pcstr line, pcstr al } } #endif -//-Alundaio +//-Alundaio diff --git a/src/xrGame/HudSound.h b/src/xrGame/HudSound.h index 36dc5eedc37..3ce9e0ae527 100644 --- a/src/xrGame/HudSound.h +++ b/src/xrGame/HudSound.h @@ -57,6 +57,7 @@ class HUD_SOUND_COLLECTION ~HUD_SOUND_COLLECTION(); #ifdef LAYERED_SND_SHOOT + HUD_SOUND_COLLECTION() : m_alias(nullptr) {}; shared_str m_alias; //Alundaio: For use when it's part of a layered Collection #endif @@ -83,13 +84,20 @@ class HUD_SOUND_COLLECTION_LAYERED public: ~HUD_SOUND_COLLECTION_LAYERED(); + HUD_SOUND_ITEM* FindSoundItem(pcstr alias, bool b_assert); - void PlaySound(pcstr alias, const Fvector& position, const IGameObject* parent, bool hud_mode, bool looped = false, - u8 index = u8(-1)); + + void PlaySound(pcstr alias, const Fvector& position, const IGameObject* parent, + bool hud_mode, bool looped = false, u8 index = u8(-1)); + void StopSound(pcstr alias); void StopAllSounds(); + void LoadSound(pcstr section, pcstr line, pcstr alias, bool exclusive = false, int type = sg_SourceType); + void LoadSound(CInifile const* ini, pcstr section, pcstr line, pcstr alias, + bool exclusive = false, int type = sg_SourceType); + void SetPosition(pcstr alias, const Fvector& pos); }; #endif -//-Alundaio +//-Alundaio diff --git a/src/xrGame/WeaponMagazined.cpp b/src/xrGame/WeaponMagazined.cpp index 8d9d7277215..5429c3f8803 100644 --- a/src/xrGame/WeaponMagazined.cpp +++ b/src/xrGame/WeaponMagazined.cpp @@ -88,9 +88,9 @@ void CWeaponMagazined::Load(LPCSTR section) //Alundaio: LAYERED_SND_SHOOT #ifdef LAYERED_SND_SHOOT - m_layered_sounds.LoadSound(section, "snd_shoot", "sndShot", true, m_eSoundShot); + m_layered_sounds.LoadSound(section, "snd_shoot", "sndShot", false, m_eSoundShot); #else - m_sounds.LoadSound(section, "snd_shoot", "sndShot", true, m_eSoundShot); //Alundaio: Set exclusive to true + m_sounds.LoadSound(section, "snd_shoot", "sndShot", false, m_eSoundShot); #endif //-Alundaio @@ -114,7 +114,17 @@ void CWeaponMagazined::Load(LPCSTR section) if (pSettings->line_exist(section, "silencer_smoke_particles")) m_sSilencerSmokeParticles = pSettings->r_string(section, "silencer_smoke_particles"); + //Alundaio: LAYERED_SND_SHOOT Silencer +#ifdef LAYERED_SND_SHOOT + m_layered_sounds.LoadSound(section, "snd_silncer_shot", "sndSilencerShot", false, m_eSoundShot); + if (WeaponSoundExist(section, "snd_silncer_shot_actor")) + m_layered_sounds.LoadSound(section, "snd_silncer_shot_actor", "sndSilencerShotActor", false, m_eSoundShot); +#else m_sounds.LoadSound(section, "snd_silncer_shot", "sndSilencerShot", false, m_eSoundShot); + if (WeaponSoundExist(section, "snd_silncer_shot_actor")) + m_sounds.LoadSound(section, "snd_silncer_shot_actor", "sndSilencerShotActor", false, m_eSoundShot); +#endif + //-Alundaio } m_iBaseDispersionedBulletsCount = READ_IF_EXISTS(pSettings, r_u8, section, "base_dispersioned_bullets_count", 0); @@ -183,7 +193,7 @@ void CWeaponMagazined::FireStart() { // misfire //Alundaio #ifdef EXTENDED_WEAPON_CALLBACKS - CGameObject *object = smart_cast(H_Parent()); + CGameObject *object = smart_cast(H_Parent()); if (object) object->callback(GameObject::eOnWeaponJammed)(object->lua_game_object(), this->lua_game_object()); #endif @@ -629,7 +639,7 @@ void CWeaponMagazined::OnShot() #ifdef LAYERED_SND_SHOOT m_layered_sounds.PlaySound(m_sSndShotCurrent.c_str(), get_LastFP(), H_Root(), !!GetHUDmode(), false, (u8)-1); #else - PlaySound(m_sSndShotCurrent.c_str(), get_LastFP(), (u8)(m_iShotNum - 1)); //Alundaio: Play sound at index (ie. snd_shoot, snd_shoot1, snd_shoot2, snd_shoot3) + PlaySound(m_sSndShotCurrent.c_str(), get_LastFP(), (u8)-1); //Alundaio: Play sound at index (ie. snd_shoot, snd_shoot1, snd_shoot2, snd_shoot3) #endif //-Alundaio @@ -1194,7 +1204,7 @@ void CWeaponMagazined::OnZoomIn() //Alundaio: callback not sure why vs2013 gives error, it's fine #ifdef EXTENDED_WEAPON_CALLBACKS - CGameObject *object = smart_cast(H_Parent()); + CGameObject *object = smart_cast(H_Parent()); if (object) object->callback(GameObject::eOnWeaponZoomIn)(object->lua_game_object(),this->lua_game_object()); #endif @@ -1223,13 +1233,13 @@ void CWeaponMagazined::OnZoomOut() if (GetState() == eIdle) PlayAnimIdle(); - //Alundaio + //Alundaio #ifdef EXTENDED_WEAPON_CALLBACKS - CGameObject *object = smart_cast(H_Parent()); - if (object) - object->callback(GameObject::eOnWeaponZoomOut)(object->lua_game_object(), this->lua_game_object()); + CGameObject *object = smart_cast(H_Parent()); + if (object) + object->callback(GameObject::eOnWeaponZoomOut)(object->lua_game_object(), this->lua_game_object()); #endif - //-Alundaio + //-Alundaio CActor* pActor = smart_cast(H_Parent()); @@ -1453,7 +1463,11 @@ bool CWeaponMagazined::install_upgrade_impl(LPCSTR section, bool test) result2 = process_if_exists_set(section, "snd_shoot", &CInifile::r_string, str, test); if (result2 && !test) { +#ifdef LAYERED_SND_SHOOT + m_layered_sounds.LoadSound(section, "snd_shoot", "sndShot", false, m_eSoundShot); +#else m_sounds.LoadSound(section, "snd_shoot", "sndShot", false, m_eSoundShot); +#endif } result |= result2; @@ -1494,7 +1508,11 @@ bool CWeaponMagazined::install_upgrade_impl(LPCSTR section, bool test) result2 = process_if_exists_set(section, "snd_silncer_shot", &CInifile::r_string, str, test); if (result2 && !test) { +#ifdef LAYERED_SND_SHOOT + m_layered_sounds.LoadSound(section, "snd_silncer_shot", "sndSilencerShot", false, m_eSoundShot); +#else m_sounds.LoadSound(section, "snd_silncer_shot", "sndSilencerShot", false, m_eSoundShot); +#endif } result |= result2; }