From 03b16ff905680b3e07af35578dcb1ecbe08bf809 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Tue, 25 May 2021 10:25:20 +0200 Subject: [PATCH] Add Vox_Sentence_Broadcast() and Vox_Sentence_Single --- src/client/vox.qc | 41 +++++++++++++++++++++++++++- src/gs-entbase/server/env_message.qc | 31 ++++++++++++++++++++- src/gs-entbase/shared/baseentity.h | 1 + src/gs-entbase/shared/baseentity.qc | 9 +++++- src/server/vox.h | 2 ++ src/server/vox.qc | 31 +++++++++++++++++++++ src/shared/events.h | 1 + 7 files changed, 113 insertions(+), 3 deletions(-) diff --git a/src/client/vox.qc b/src/client/vox.qc index c21e68bd..1dd5b698 100644 --- a/src/client/vox.qc +++ b/src/client/vox.qc @@ -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); +} diff --git a/src/gs-entbase/server/env_message.qc b/src/gs-entbase/server/env_message.qc index b4c9d092..cd3f7021 100644 --- a/src/gs-entbase/server/env_message.qc +++ b/src/gs-entbase/server/env_message.qc @@ -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); +} diff --git a/src/gs-entbase/shared/baseentity.h b/src/gs-entbase/shared/baseentity.h index 8dfa0f6a..8264fb31 100644 --- a/src/gs-entbase/shared/baseentity.h +++ b/src/gs-entbase/shared/baseentity.h @@ -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; diff --git a/src/gs-entbase/shared/baseentity.qc b/src/gs-entbase/shared/baseentity.qc index d6eebb50..4d0d9ef1 100644 --- a/src/gs-entbase/shared/baseentity.qc +++ b/src/gs-entbase/shared/baseentity.qc @@ -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++; diff --git a/src/server/vox.h b/src/server/vox.h index 2a422595..92f844b8 100644 --- a/src/server/vox.h +++ b/src/server/vox.h @@ -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); diff --git a/src/server/vox.qc b/src/server/vox.qc index 6f5ed58d..31edd0f5 100644 --- a/src/server/vox.qc +++ b/src/server/vox.qc @@ -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); +} diff --git a/src/shared/events.h b/src/shared/events.h index de247835..cfc52943 100644 --- a/src/shared/events.h +++ b/src/shared/events.h @@ -43,6 +43,7 @@ enum EV_OBITUARY, // new one EV_SPEAK, EV_SENTENCE, + EV_SENTENCE_VOX, EV_CHAT, EV_CHAT_TEAM, EV_CHAT_VOX,