📄 voicemgr.cpp
字号:
m_aGroupMgrs[i].Term();
}
// Clear everything else...
Clear();
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::Clear
//
// PURPOSE: Clear
//
// ----------------------------------------------------------------------- //
void CVoiceMgr::Clear()
{
// Clear simple members...
m_pClientDE = DNULL;
m_fNextPlayTime = 0;
if( m_hCurSound )
{
g_pClientDE->KillSound( m_hCurSound );
m_hCurSound = DNULL;
}
m_bOn = DTRUE;
// Clear the play flags for each character...
for (int i = 0; i < VMC_MAX; i++)
{
for (int j = 0; j < VMU_MAX; j++)
{
m_aUniquePlayFlags[i][j] = DFALSE;
}
}
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::PlayEventSound
//
// PURPOSE: Plays a random sound for the given event for the given
// character.
//
// ----------------------------------------------------------------------- //
DBOOL CVoiceMgr::PlayEventSound(int iCharacter, int iEvent)
{
// Make sure it's ok to play...
if (!IsOkToPlaySound())
{
return(DFALSE);
}
// Get a random sound string to play...
char* sSound = GetRandomGroupSoundString(iCharacter, iEvent);
if (!sSound) return(DFALSE);
// Play the sound...
if (iEvent == VME_JUMP) // special case for non streaming for brad
{
if (!PlaySoundNoStream(sSound))
{
return(DFALSE);
}
}
else
{
if (!PlaySound(sSound))
{
return(DFALSE);
}
}
// All done...
return(DTRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::PlayUniqueSound
//
// PURPOSE: Plays the specific sound for the given unique event for
// the given character.
//
// ----------------------------------------------------------------------- //
DBOOL CVoiceMgr::PlayUniqueSound(int iCharacter, int iUnique)
{
// Sanity check, unique sounds are only for caleb...
if (iCharacter != VMC_CALEB) return(DFALSE);
// Check if we have already played this sound...
if (IsUniqueSoundPlayed(iCharacter, iUnique))
{
return(DFALSE);
}
// Make sure it's ok to play...
if (!IsOkToPlaySound())
{
return(DFALSE);
}
// Get the sound string for this unique event...
char sSound[256] = { "" };
DBOOL bRet = GetUniqueEventSoundString(iCharacter, iUnique, sSound);
if (!bRet) return(DFALSE);
if (sSound[0] == '\0') return(DFALSE);
// Play the sound...
if (!PlaySound(sSound))
{
return(DFALSE);
}
// Flag that we have now played this unique sound for this character...
FlagUniqueSoundPlayed(iCharacter, iUnique);
// All done...
return(DTRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::GetUniqueEventSoundString
//
// PURPOSE: Gets the sound string for the given unique event for the
// given character.
//
// ----------------------------------------------------------------------- //
DBOOL CVoiceMgr::GetUniqueEventSoundString(int iCharacter, int iUnique, char* sPath)
{
// Sanity checks...
if (iCharacter != VMC_CALEB) return(DFALSE);
if (!sPath) return(DFALSE);
sPath[0] = '\0';
// Get the unique sound string for Caleb...
char sSound[32] = { "" };
switch (iUnique)
{
case VMU_HOWITZER: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc1_cal.wav"); break;
case VMU_TESLACANNON: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc2_cal.wav"); break;
case VMU_SNIPERRIFLE: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc3_cal.wav"); break;
case VMU_AKIMBO: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc4_cal.wav"); break;
case VMU_VOODOODOLL: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc5_cal.wav"); break;
case VMU_ASSAULTRIFLE: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc6_cal.wav"); break;
case VMU_NAPALMLAUNCHER: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc7_cal.wav"); break;
case VMU_SINGULARITY: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc8_cal.wav"); break;
case VMU_SHOTGUN: _mbscpy((unsigned char*)sSound, (const unsigned char*)"msc9_cal.wav"); break;
default: return(DFALSE);
}
// Build the full path...
sprintf(sPath, "sounds\\chosen\\caleb\\unique\\%s", sSound);
// All done...
return(DTRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::IsUniqueSoundPlayed
//
// PURPOSE: Determines if the given unique sound for the given
// character has already been played.
//
// ----------------------------------------------------------------------- //
DBOOL CVoiceMgr::IsUniqueSoundPlayed(int iCharacter, int iUnique)
{
// Sanity checks...
if (iCharacter < 0) return(DFALSE);
if (iCharacter >= VMC_MAX) return(DFALSE);
if (iUnique < 0) return(DFALSE);
if (iUnique >= VMU_MAX) return(DFALSE);
// Determine if this sound has already been played...
return(m_aUniquePlayFlags[iCharacter][iUnique]);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::FlagUniqueSoundPlayed
//
// PURPOSE: Flag that the given unique sound for the given
// character has been played.
//
// ----------------------------------------------------------------------- //
void CVoiceMgr::FlagUniqueSoundPlayed(int iCharacter, int iUnique)
{
// Sanity checks...
if (iCharacter < 0) return;
if (iCharacter >= VMC_MAX) return;
if (iUnique < 0) return;
if (iUnique >= VMU_MAX) return;
// Flag that this sound has been played...
m_aUniquePlayFlags[iCharacter][iUnique] = DTRUE;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::IsOkToPlaySound
//
// PURPOSE: Determines if it's ok to play a new voice sound
//
// ----------------------------------------------------------------------- //
DBOOL CVoiceMgr::IsOkToPlaySound()
{
if (!IsOn()) return(DFALSE);
if (m_hCurSound && !m_pClientDE->IsDone(m_hCurSound)) return(DFALSE);
if (g_pBloodClientShell && g_pBloodClientShell->IsExternalCamera()) return(DFALSE);
return(m_pClientDE->GetTime() > m_fNextPlayTime);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::PlaySound
//
// PURPOSE: Plays the given sound
//
// ----------------------------------------------------------------------- //
DBOOL CVoiceMgr::PlaySound(char* sSound, DFLOAT fTimeAdd)
{
// Sanity checks...
if (!sSound) return(DFALSE);
// Stop any current sounds...
StopAll();
// Play the sound...
m_hCurSound = PlaySoundLocal(sSound, SOUNDPRIORITY_PLAYER_MEDIUM, DFALSE, DTRUE, DFALSE, DTRUE);
if (!m_hCurSound) return(DFALSE);
// Set the next sound play time...
DFLOAT fSoundTime = 1;
DRESULT dr = m_pClientDE->GetSoundDuration(m_hCurSound, &fSoundTime);
if (dr == DE_OK)
{
fSoundTime += fTimeAdd;
}
else
{
fSoundTime = 1;
}
SetNextPlayTime(fSoundTime);
// All done...
return(DTRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::PlaySoundNoStream
//
// PURPOSE: Plays the given sound without streaming
//
// ----------------------------------------------------------------------- //
DBOOL CVoiceMgr::PlaySoundNoStream(char* sSound, DFLOAT fTimeAdd)
{
// Sanity checks...
if (!sSound) return(DFALSE);
// Stop any current sounds...
StopAll();
// Play the sound...
m_hCurSound = PlaySoundLocal(sSound, SOUNDPRIORITY_PLAYER_MEDIUM, DFALSE, DTRUE, DFALSE, DFALSE);
if (!m_hCurSound) return(DFALSE);
// Set the next sound play time...
DFLOAT fSoundTime = 1;
DRESULT dr = m_pClientDE->GetSoundDuration(m_hCurSound, &fSoundTime);
if (dr == DE_OK)
{
fSoundTime += fTimeAdd;
}
else
{
fSoundTime = 1;
}
SetNextPlayTime(fSoundTime);
// All done...
return(DTRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::StopAll
//
// PURPOSE: Stops any currently playing sound
//
// ----------------------------------------------------------------------- //
void CVoiceMgr::StopAll()
{
// Reset the next play time...
m_fNextPlayTime = 0;
// Sanity checks...
if (!m_hCurSound) return;
if (!m_pClientDE) return;
// Kill the sound...
m_pClientDE->KillSound(m_hCurSound);
m_hCurSound = DNULL;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CVoiceMgr::Reset
//
// PURPOSE: Resets stuff
//
// ----------------------------------------------------------------------- //
void CVoiceMgr::Reset()
{
// Stop all sounds...
StopAll();
m_fNextPlayTime = 0;
// Clear the play flags for each character...
for (int i = 0; i < VMC_MAX; i++)
{
for (int j = 0; j < VMU_MAX; j++)
{
m_aUniquePlayFlags[i][j] = DFALSE;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -