Add Vox_Sentence_Broadcast() and Vox_Sentence_Single

This commit is contained in:
Marco Cawthorne 2021-05-25 10:25:20 +02:00
parent 4964ba3859
commit 03b16ff905
7 changed files with 113 additions and 3 deletions

View File

@ -687,4 +687,43 @@ Vox_Init(void)
precache_sound("vox/zero.wav");
precache_sound("vox/zone.wav");
precache_sound("vox/zulu.wav");
}
}
class CVoxSpeaker:CBaseEntity
{
void CVoxSpeaker;
virtual void(string) SentenceSample;
virtual float(void) predraw;
};
void
CVoxSpeaker::SentenceSample(string sample)
{
sound(this, CHAN_VOICE, sample, 1.0, ATTN_NONE);
}
float
CVoxSpeaker::predraw(void)
{
ProcessWordQue();
return (PREDRAW_NEXT);
}
void
CVoxSpeaker::CVoxSpeaker(void)
{
// blaaa
drawmask = MASK_ENGINE;
}
CVoxSpeaker g_voxSpeaker;
void
Vox_PlaySentence(string sentence)
{
if (!g_voxSpeaker) {
g_voxSpeaker = spawn(CVoxSpeaker);
}
g_voxSpeaker.Sentence(sentence);
}

View File

@ -104,12 +104,41 @@ void env_message::env_message(void)
void
env_message_single(entity target, string msg)
{
if (!msg)
return;
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_MESSAGE);
WriteString(MSG_MULTICAST, msg);
if (substring(msg, 0, 1) != "#")
WriteString(MSG_MULTICAST, msg);
else
WriteString(MSG_MULTICAST, substring(msg, 1, -1));
WriteString(MSG_MULTICAST, "misc/talk.wav");
WriteFloat(MSG_MULTICAST, 1.0);
WriteByte(MSG_MULTICAST, ATTN_NORM);
msg_entity = target;
multicast([0,0,0], MULTICAST_ONE_R);
}
void
env_message_broadcast(string msg)
{
if (!msg)
return;
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_MESSAGE);
if (substring(msg, 0, 1) != "#")
WriteString(MSG_MULTICAST, msg);
else
WriteString(MSG_MULTICAST, substring(msg, 1, -1));
WriteString(MSG_MULTICAST, "misc/talk.wav");
WriteFloat(MSG_MULTICAST, 1.0);
WriteByte(MSG_MULTICAST, ATTN_NORM);
msg_entity = world;
multicast([0,0,0], MULTICAST_ALL_R);
}

View File

@ -30,6 +30,7 @@ class CBaseEntity
void(void) CBaseEntity;
virtual void(void) Init;
virtual void(void) Initialized;
virtual void(string) SentenceSample;
virtual void(string) Sentence;
virtual void(void) ProcessWordQue;
virtual void(float flChanged) ReceiveEntity;

View File

@ -198,6 +198,12 @@ CBaseEntity::predraw(void)
return (PREDRAW_NEXT);
}
void
CBaseEntity::SentenceSample(string sample)
{
sound(this, CHAN_VOICE, sample, 1.0, ATTN_NORM, 100, SOUNDFLAG_FOLLOW);
}
void
CBaseEntity::ProcessWordQue(void)
{
@ -209,7 +215,8 @@ CBaseEntity::ProcessWordQue(void)
return;
}
sound(this, CHAN_VOICE, m_pSentenceQue[m_iSentencePos].m_strSnd, 1.0, ATTN_NORM, 100, SOUNDFLAG_FOLLOW);
SentenceSample(m_pSentenceQue[m_iSentencePos].m_strSnd);
dprint(sprintf("^2CBaseEntity::^3ProcessWordQue^7: Speaking %s\n", m_pSentenceQue[m_iSentencePos].m_strSnd));
m_iSentencePos++;

View File

@ -17,3 +17,5 @@
string Vox_TimeToString(float);
void Vox_Broadcast(string);
void Vox_Singlecast(entity, string);
void Vox_Sentence_Single(entity, string);
void Vox_Sentence_Broadcast(string);

View File

@ -78,3 +78,34 @@ Vox_Singlecast(entity eClient, string sMessage)
msg_entity = eClient;
multicast([0,0,0], MULTICAST_ONE_R);
}
void
Vox_Sentence_Single(entity eClient, string strSentence)
{
if (!strSentence)
return;
localcmd(sprintf("echo [VOX] Sentence to %s: %s\n", eClient.netname, strSentence));
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_SENTENCE_VOX);
WriteString(MSG_MULTICAST, strSentence);
msg_entity = eClient;
multicast([0,0,0], MULTICAST_ONE_R);
}
void
Vox_Sentence_Broadcast(string strSentence)
{
if (!strSentence)
return;
localcmd(sprintf("echo [VOX] Broadcast: %s\n", strSentence));
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_SENTENCE_VOX);
WriteString(MSG_MULTICAST, strSentence);
msg_entity = world;
multicast([0,0,0], MULTICAST_ALL_R);
}

View File

@ -43,6 +43,7 @@ enum
EV_OBITUARY, // new one
EV_SPEAK,
EV_SENTENCE,
EV_SENTENCE_VOX,
EV_CHAT,
EV_CHAT_TEAM,
EV_CHAT_VOX,