diff options
author | Mat <mail@mathias.is> | 2020-03-22 16:50:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 16:50:34 +0100 |
commit | 9ddf433ae747e0a677d02062deea08a95c29f27b (patch) | |
tree | 1e27fcb0fa734b81cc8d538788b519f1eca872cd /src/Mobs/Monster.cpp | |
parent | Increase speed of splash potion and expbottle (#4513) (diff) | |
download | cuberite-9ddf433ae747e0a677d02062deea08a95c29f27b.tar cuberite-9ddf433ae747e0a677d02062deea08a95c29f27b.tar.gz cuberite-9ddf433ae747e0a677d02062deea08a95c29f27b.tar.bz2 cuberite-9ddf433ae747e0a677d02062deea08a95c29f27b.tar.lz cuberite-9ddf433ae747e0a677d02062deea08a95c29f27b.tar.xz cuberite-9ddf433ae747e0a677d02062deea08a95c29f27b.tar.zst cuberite-9ddf433ae747e0a677d02062deea08a95c29f27b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/Monster.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 09f937564..9a826ed21 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -76,7 +76,7 @@ static const struct //////////////////////////////////////////////////////////////////////////////// // cMonster: -cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) +cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, double a_Width, double a_Height) : super(etMonster, a_Width, a_Height) , m_EMState(IDLE) , m_EMPersonality(AGGRESSIVE) @@ -90,6 +90,7 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A , m_CustomNameAlwaysVisible(false) , m_SoundHurt(a_SoundHurt) , m_SoundDeath(a_SoundDeath) + , m_SoundAmbient(a_SoundAmbient) , m_AttackRate(3) , m_AttackDamage(1) , m_AttackRange(1) @@ -117,6 +118,9 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A { GetMonsterConfig(a_ConfigName); } + + // Prevent mobs spawning at the same time from making sounds simultaneously + m_AmbientSoundTimer = GetRandomProvider().RandInt(0, 100); } @@ -384,6 +388,19 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) BroadcastMovementUpdate(); + // Ambient mob sounds + if (!m_SoundAmbient.empty() && (--m_AmbientSoundTimer <= 0)) + { + auto & Random = GetRandomProvider(); + auto ShouldPlaySound = Random.RandBool(); + if (ShouldPlaySound) + { + auto SoundPitchMultiplier = 1.0f + (Random.RandReal(1.0f) - Random.RandReal(1.0f)) * 0.2f; + m_World->BroadcastSoundEffect(m_SoundAmbient, GetPosition(), 1.0f, SoundPitchMultiplier * 1.0f); + } + m_AmbientSoundTimer = 100; + } + if (m_AgingTimer > 0) { m_AgingTimer--; |