Skip to content

Commit

Permalink
Use random sound array.
Browse files Browse the repository at this point in the history
  • Loading branch information
malortie committed Dec 2, 2021
1 parent c633af8 commit 548a8ba
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions dlls/zombie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,30 @@ void CZombie::PainSound()
int pitch = 95 + RANDOM_LONG(0, 9);

if (RANDOM_LONG(0, 5) < 2)
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, pPainSounds[RANDOM_LONG(0, ARRAYSIZE(pPainSounds) - 1)], 1.0, ATTN_NORM, 0, pitch);
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pPainSounds), 1.0, ATTN_NORM, 0, pitch);
}

void CZombie::AlertSound()
{
int pitch = 95 + RANDOM_LONG(0, 9);

EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, pAlertSounds[RANDOM_LONG(0, ARRAYSIZE(pAlertSounds) - 1)], 1.0, ATTN_NORM, 0, pitch);
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pAlertSounds), 1.0, ATTN_NORM, 0, pitch);
}

void CZombie::IdleSound()
{
int pitch = 100 + RANDOM_LONG(-5, 5);

// Play a random idle sound
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, pIdleSounds[RANDOM_LONG(0, ARRAYSIZE(pIdleSounds) - 1)], 1.0, ATTN_NORM, 0, pitch);
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pIdleSounds), 1.0, ATTN_NORM, 0, pitch);
}

void CZombie::AttackSound()
{
int pitch = 100 + RANDOM_LONG(-5, 5);

// Play a random attack sound
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, pAttackSounds[RANDOM_LONG(0, ARRAYSIZE(pAttackSounds) - 1)], 1.0, ATTN_NORM, 0, pitch);
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, RANDOM_SOUND_ARRAY(pAttackSounds), 1.0, ATTN_NORM, 0, pitch);
}


Expand All @@ -206,10 +206,10 @@ void CZombie::HandleAnimEvent(MonsterEvent_t* pEvent)
pHurt->pev->velocity = pHurt->pev->velocity - gpGlobals->v_right * 100;
}
// Play a random attack hit sound
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG(0, ARRAYSIZE(pAttackHitSounds) - 1)], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY(pAttackHitSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
}
else // Play a random attack miss sound
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG(0, ARRAYSIZE(pAttackMissSounds) - 1)], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY(pAttackMissSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));

if (RANDOM_LONG(0, 1))
AttackSound();
Expand All @@ -229,10 +229,10 @@ void CZombie::HandleAnimEvent(MonsterEvent_t* pEvent)
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_right * 100;
}
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG(0, ARRAYSIZE(pAttackHitSounds) - 1)], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY(pAttackHitSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
}
else
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG(0, ARRAYSIZE(pAttackMissSounds) - 1)], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY(pAttackMissSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));

if (RANDOM_LONG(0, 1))
AttackSound();
Expand All @@ -250,10 +250,10 @@ void CZombie::HandleAnimEvent(MonsterEvent_t* pEvent)
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity + gpGlobals->v_forward * -100;
}
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, pAttackHitSounds[RANDOM_LONG(0, ARRAYSIZE(pAttackHitSounds) - 1)], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY(pAttackHitSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
}
else
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, pAttackMissSounds[RANDOM_LONG(0, ARRAYSIZE(pAttackMissSounds) - 1)], 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, RANDOM_SOUND_ARRAY(pAttackMissSounds), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG(-5, 5));

if (RANDOM_LONG(0, 1))
AttackSound();
Expand Down Expand Up @@ -293,27 +293,14 @@ void CZombie::Spawn()
//=========================================================
void CZombie::Precache()
{
int i;

PRECACHE_MODEL("models/zombie.mdl");

for (i = 0; i < ARRAYSIZE(pAttackHitSounds); i++)
PRECACHE_SOUND((char*)pAttackHitSounds[i]);

for (i = 0; i < ARRAYSIZE(pAttackMissSounds); i++)
PRECACHE_SOUND((char*)pAttackMissSounds[i]);

for (i = 0; i < ARRAYSIZE(pAttackSounds); i++)
PRECACHE_SOUND((char*)pAttackSounds[i]);

for (i = 0; i < ARRAYSIZE(pIdleSounds); i++)
PRECACHE_SOUND((char*)pIdleSounds[i]);

for (i = 0; i < ARRAYSIZE(pAlertSounds); i++)
PRECACHE_SOUND((char*)pAlertSounds[i]);

for (i = 0; i < ARRAYSIZE(pPainSounds); i++)
PRECACHE_SOUND((char*)pPainSounds[i]);
PRECACHE_SOUND_ARRAY(pAttackHitSounds);
PRECACHE_SOUND_ARRAY(pAttackMissSounds);
PRECACHE_SOUND_ARRAY(pAttackSounds);
PRECACHE_SOUND_ARRAY(pIdleSounds);
PRECACHE_SOUND_ARRAY(pAlertSounds);
PRECACHE_SOUND_ARRAY(pPainSounds);
}

//=========================================================
Expand Down

0 comments on commit 548a8ba

Please sign in to comment.