⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voicemgr.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
;
;	 MODULE:		VOICEMGR (.CPP)
;
;	PURPOSE:		Voice Manager for character voice sounds
;
;	HISTORY:		10/11/98 [blg] This file was created
;
;	COMMENT:		Copyright (c) 1998, Monolith Productions Inc.
;
****************************************************************************/

// Includes...

#include "VoiceMgr.h"
#include "StdIo.h"
#include "ClientUtilities.h"
#include "BloodClientShell.h"
#include "SoundTypes.h"


// Externs...

extern CBloodClientShell* g_pBloodClientShell;


// Functions...

// *********************************************************************** //
// CVoiceGroup

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroup::Init
//
//	PURPOSE:	Initialization
//
// ----------------------------------------------------------------------- //

DBOOL CVoiceGroup::Init(CClientDE* pClientDE, char* sDir, char* sCustomDir)
{
	// Sanity checks...

	if (!pClientDE) return(DFALSE);
	if (!sDir) return(DFALSE);


	// Set simple members...

	m_pClientDE = pClientDE;


	// Add all the sounds in the given dir...

	int cSounds = AddSoundStrings(sCustomDir);

	if (cSounds <= 0)
	{
		AddSoundStrings(sDir);
	}


	// All done...

	return(DTRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroup::Term
//
//	PURPOSE:	Terminate
//
// ----------------------------------------------------------------------- //

void CVoiceGroup::Term()
{
	// Clear everything...

	Clear();
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroup::AddSoundStrings
//
//	PURPOSE:	Add all of the sound strings in the given rez directory
//
//	RETURNS:	int = number of sound strings added
//
// ----------------------------------------------------------------------- //

int CVoiceGroup::AddSoundStrings(char* sDir)
{
	// Sanity checks...

	if (!sDir) return(0);
	if (sDir[0] == '\0') return(0);


	// Add all of the sound strings in the given rez directory...

	int cSounds = 0;

	FileEntry* pFiles = m_pClientDE->GetFileList(sDir);
	if (!pFiles) return(0);

	FileEntry* pCurFile = pFiles;

	while (pCurFile)
	{
		if (pCurFile->m_Type == TYPE_FILE)
		{
			int nLen = _mbstrlen(pCurFile->m_pBaseFilename);

			if (nLen > 4 && strnicmp(&pCurFile->m_pBaseFilename[nLen - 4], ".wav", 4) == 0)
			{
				if (AddSoundString(pCurFile->m_pFullFilename))
				{
					cSounds++;
				}
			}
		}

		pCurFile= pCurFile->m_pNext;
	}


	// All done...
	m_pClientDE->FreeFileList(pFiles);
	return(cSounds);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroup::AddSoundString
//
//	PURPOSE:	Adds the given sound string
//
// ----------------------------------------------------------------------- //

DBOOL CVoiceGroup::AddSoundString(char* sSound)
{
	// Sanity checks...

	if (!sSound) return(DFALSE);
	if (GetNumSounds() >= VM_MAX_SOUNDS) return(DFALSE);
	if (_mbstrlen(sSound) >= VM_MAX_STRING) return(DFALSE);


	// Add the string...

	_mbscpy((unsigned char*)m_sSounds[m_cSounds], (const unsigned char*)sSound);

	m_cSounds++;


	// All done...

	return(DTRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroup::GetRandomSoundString
//
//	PURPOSE:	Gets a random sound string
//
// ----------------------------------------------------------------------- //

char* CVoiceGroup::GetRandomSoundString()
{
	// Sanity checks...

	if (GetNumSounds() <= 0) return(DNULL);


	// Check if we only have one sound to play...

	if (GetNumSounds() == 1)
	{
		return(GetSoundString(0));
	}


	// Pick a random sound to play...

	int nMax    = GetNumSounds() - 1;
	int iRandom = GetRandom(0, nMax);
	int cSafety = 200;

	while (iRandom == m_iLast && cSafety > 0)
	{
		iRandom = GetRandom(0, nMax);
		cSafety--;
	}

	m_iLast = iRandom;


	// Return with the random sound...

	return(GetSoundString(iRandom));
}


// *********************************************************************** //
// CVoiceGroupMgr

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroupMgr::Init
//
//	PURPOSE:	Initialization
//
// ----------------------------------------------------------------------- //

DBOOL CVoiceGroupMgr::Init(CClientDE* pClientDE, char* sDirPrefix, char* sCustomDirPrefix)
{
	// Sanity checks...

	if (!pClientDE) return(DFALSE);
	if (!sDirPrefix) return(DFALSE);


	// Set simple members...

	m_pClientDE = pClientDE;


	// Add all the groups...

	AddGroup(VME_IDLE,     sDirPrefix, sCustomDirPrefix, "Idle");
	AddGroup(VME_BIGGIB,   sDirPrefix, sCustomDirPrefix, "BigGib");
	AddGroup(VME_PAIN,     sDirPrefix, sCustomDirPrefix, "Pain");
	AddGroup(VME_KILL,     sDirPrefix, sCustomDirPrefix, "Kill");
	AddGroup(VME_DEATH,    sDirPrefix, sCustomDirPrefix, "Death");
	AddGroup(VME_BURNING,  sDirPrefix, sCustomDirPrefix, "Burning");
	AddGroup(VME_POWERUP,  sDirPrefix, sCustomDirPrefix, "Powerup");
	AddGroup(VME_SPAWN,    sDirPrefix, sCustomDirPrefix, "Spawn");
	AddGroup(VME_SUICIDE,  sDirPrefix, sCustomDirPrefix, "Suicide");
	AddGroup(VME_WEAPON,   sDirPrefix, sCustomDirPrefix, "Weapon");
	AddGroup(VME_TAUNT,    sDirPrefix, sCustomDirPrefix, "Taunt");
	AddGroup(VME_JUMP,     sDirPrefix, sCustomDirPrefix, "Jump");


	// All done...

	return(DTRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroupMgr::Term
//
//	PURPOSE:	Termination
//
// ----------------------------------------------------------------------- //

void CVoiceGroupMgr::Term()
{
	// Terminate all of the groups...

	for (int i = 0; i < VME_MAX; i++)
	{
		m_aGroups[i].Term();
	}


	// Clear everything...

	Clear();
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceGroupMgr::AddGroup
//
//	PURPOSE:	Adds the sounds for the given voice group
//
//	RETURNS:	int = number of sound strings added
//
// ----------------------------------------------------------------------- //

int CVoiceGroupMgr::AddGroup(int iGroup, char* sDirPrefix, char* sCustomDirPrefix, char* sDir)
{
	// Sanity checks...

	if (iGroup < 0 || iGroup >= VME_MAX) return(0);
	if (!sDirPrefix) return(0);
	if (!sDir) return(0);


	// Create the full directory names...

	char sFullDir[256];
	sprintf(sFullDir, "%s\\%s", sDirPrefix, sDir);

	char sFullCustomDir[256];
	sprintf(sFullCustomDir, "%s\\%s", sCustomDirPrefix, sDir);


	// Init the specified group...

	CVoiceGroup* pGroup = GetGroup(iGroup);
	if (!pGroup) return(0);

	if (!pGroup->Init(m_pClientDE, sFullDir, sFullCustomDir))
	{
		pGroup->Term();
		return(0);
	}


	// All done...

	return(pGroup->GetNumSounds());
}


// *********************************************************************** //
// CVoiceMgr

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceMgr::Init
//
//	PURPOSE:	Initialization
//
// ----------------------------------------------------------------------- //

DBOOL CVoiceMgr::Init(CClientDE* pClientDE)
{
	// Sanity checks...

	if (!pClientDE) return(DFALSE);


	// Set simple members...

	m_pClientDE = pClientDE;


	// Randomize...

	srand((int)m_pClientDE->GetTime());


	// Init the group manager for Caleb...

	CVoiceGroupMgr* pGroupMgr = GetGroupMgr(VMC_CALEB);
	if (!pGroupMgr) return(DFALSE);

	pGroupMgr->Init(m_pClientDE, "sounds\\chosen\\caleb", "\\caleb");


	// Init the group manager for Ophelia...

	pGroupMgr = GetGroupMgr(VMC_OPHELIA);
	if (!pGroupMgr) return(DFALSE);

	pGroupMgr->Init(m_pClientDE, "sounds\\chosen\\ophelia", "\\ophelia");


	// Init the group manager for Ishmael...

	pGroupMgr = GetGroupMgr(VMC_ISHMAEL);
	if (!pGroupMgr) return(DFALSE);

	pGroupMgr->Init(m_pClientDE, "sounds\\chosen\\ishmael", "\\ishmael");


	// Init the group manager for Gabriella...

	pGroupMgr = GetGroupMgr(VMC_GABRIELLA);
	if (!pGroupMgr) return(DFALSE);

	pGroupMgr->Init(m_pClientDE, "sounds\\chosen\\gabriella", "\\gabriella");


	// Init add-on characters if necessary...

#ifdef _ADDON
	pGroupMgr = GetGroupMgr(VMC_MALECULTIST);
	if (!pGroupMgr) return(DFALSE);
	pGroupMgr->Init(m_pClientDE, "sounds_ao\\enemies\\m_cultist", "\\malecultist");

	pGroupMgr = GetGroupMgr(VMC_FEMALECULTIST);
	if (!pGroupMgr) return(DFALSE);
	pGroupMgr->Init(m_pClientDE, "sounds_ao\\enemies\\f_cultist", "\\femalecultist");

	pGroupMgr = GetGroupMgr(VMC_SOULDRUDGE);
	if (!pGroupMgr) return(DFALSE);
	pGroupMgr->Init(m_pClientDE, "sounds_ao\\enemies\\souldrudge", "\\souldrudge");

	pGroupMgr = GetGroupMgr(VMC_PROPHET);
	if (!pGroupMgr) return(DFALSE);
	pGroupMgr->Init(m_pClientDE, "sounds_ao\\enemies\\prophet", "\\prophet");
#endif


	// All done...

	return(DTRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CVoiceMgr::Term
//
//	PURPOSE:	Termination
//
// ----------------------------------------------------------------------- //

void CVoiceMgr::Term()
{
	// Stop all sounds...

	StopAll();


	// Terminate all the group managers...

	for (int i = 0; i < VM_MAX_CHARACTERS; i++)
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -