Move the ability to use sentences over to CBaseEntity for now.

This commit is contained in:
Marco Cawthorne 2020-03-26 12:19:27 +01:00
parent db4ed5ac3d
commit 7d330eb8cd
14 changed files with 121 additions and 124 deletions

View File

@ -80,3 +80,12 @@ void View_SetMuzzleflash(int);
void View_UpdateWeapon(entity, entity);
void View_PlayAnimation(int);
void Game_Input(void);
typedef struct
{
string m_strSnd;
float m_flPitch;
float len;
} sound_t;

View File

@ -42,7 +42,7 @@ void CSQC_Ent_Update(float new)
if (new) {
spawnfunc_CBaseNPC();
}
n.ReadEntity(readshort());
n.ReadEntity(readfloat());
break;
case ENT_SPRITE:
Sprite_Animated();

View File

@ -461,7 +461,7 @@ CSQC_Parse_Event(void)
sound(t, CHAN_VOICE, msg, 1.0, ATTN_NORM, pit);
break;
case EV_SENTENCE:
CBaseNPC_ParseSentence();
CBaseEntity_ParseSentence();
break;
case EV_FADE:
Fade_Parse();

View File

@ -14,29 +14,15 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
class CBaseNPC
class CBaseNPC:CBaseEntity
{
float m_flSentenceTime;
sound_t *m_pSentenceQue;
int m_iSentenceCount;
int m_iSentencePos;
int body;
float frame_last;
virtual float() predraw;
virtual void(string) Speak;
virtual void(string) Sentence;
virtual void() ProcessWordQue;
virtual void(float flChanged) ReadEntity;
};
void
CBaseNPC::Speak(string msg)
{
sound(this, CHAN_VOICE, msg, 1.0, ATTN_NORM);
}
float
CBaseNPC::predraw(void)
{
@ -65,60 +51,6 @@ CBaseNPC::predraw(void)
return PREDRAW_NEXT;
}
void
CBaseNPC::ProcessWordQue(void)
{
if (time < 2 || !m_iSentenceCount) {
return;
}
if (m_flSentenceTime > time) {
return;
}
Speak(m_pSentenceQue[m_iSentencePos].m_strSnd);
dprint(sprintf("^2CBaseNPC: Speaking %s\n", m_pSentenceQue[m_iSentencePos].m_strSnd));
m_iSentencePos++;
if (m_iSentenceCount == m_iSentenceCount) {
memfree(m_pSentenceQue);
m_iSentenceCount = 0;
m_iSentencePos = 0;
m_pSentenceQue = 0;
} else {
m_flSentenceTime = time + m_pSentenceQue[m_iSentenceCount - 1].len;
}
}
/* we'll pass it a sentences.txt word (e.g. !BA_TEST) and start queing it */
void
CBaseNPC::Sentence(string msg)
{
/* not defined */
if (msg == "") {
return;
}
if (m_iSentenceCount) {
dprint(sprintf("^1CBaseNPC::Sentence: Freeing que for new sentence\n", m_iSentenceCount));
memfree(m_pSentenceQue);
m_iSentenceCount = 0;
m_pSentenceQue = 0;
m_iSentencePos = 0;
}
m_iSentenceCount = tokenize(Sentences_GetSamples(msg));
dprint(sprintf("^2CBaseNPC::Sentence: Speaking %i word/s\n", m_iSentenceCount));
m_pSentenceQue = memalloc(sizeof(sound_t) * m_iSentenceCount);
for (int i = 0; i < m_iSentenceCount; i++) {
dprint(sprintf("^2CBaseNPC::Sentence: Constructing... %s\n", m_pSentenceQue[i].m_strSnd));
m_pSentenceQue[i].m_strSnd = sprintf("%s.wav", argv(i));
m_pSentenceQue[i].len = soundlength(m_pSentenceQue[i].m_strSnd);
m_pSentenceQue[i].m_flPitch = 100;
}
m_flSentenceTime = time;
}
void
CBaseNPC::ReadEntity(float fl)
{
@ -164,26 +96,3 @@ CBaseNPC::CBaseNPC(void)
customphysics = Empty;
setsize(this, VEC_HULL_MIN + [0,0,36], VEC_HULL_MAX + [0,0,36]);
}
/* our EV_SENTENCE event */
void
CBaseNPC_ParseSentence(void)
{
entity ent;
CBaseNPC targ;
string sentence;
float e;
/* parse packets */
e = readentitynum();
sentence = readstring();
ent = findfloat(world, entnum, e);
if (ent) {
targ = (CBaseNPC)ent;
targ.Sentence(sentence);
} else {
dprint(sprintf("^1CBaseNPC_ParseSentence: Entity %d not in PVS\n", e));
}
}

View File

@ -23,7 +23,12 @@
* we'll just default to those whenever there's no custom value set.
*/
#define DYNAMIC_SENTENCES 0
/* sentences are the voice-acting backbone of the sound system.
* http://articles.thewavelength.net/230/
* has pretty good documentation of how the format is meant to work */
/* enable this if you want to use memalloc */
#define DYNAMIC_SENTENCES 1
typedef struct
{

View File

@ -52,14 +52,6 @@ void Sound_ParseLoopingEntity(entity sndent, float isNew)
sound(new, CHAN_VOICE, new.m_strSample, new.m_flVolume, new.m_flAttn, new.m_flPitch);
}
typedef struct
{
string m_strSnd;
float m_flPitch;
float len;
} sound_t;
sound_t *g_voxque;
void Sound_PlayVOX(string msg)

View File

@ -15,6 +15,7 @@
*/
string __fullspawndata;
string Sentences_GetSamples(string);
// keep in sync with client/baseentity.cpp
enumflags
@ -33,26 +34,86 @@ enumflags
class CBaseEntity
{
float m_flSentenceTime;
sound_t *m_pSentenceQue;
int m_iSentenceCount;
int m_iSentencePos;
string targetname;
string target;
float spawnflags;
void() CBaseEntity;
virtual void() Init;
virtual void() Initialized;
virtual void(string, string) SpawnKey;
virtual void(string) Sentence;
virtual void() ProcessWordQue;
virtual void(float flChanged) ReadEntity;
virtual float(void) predraw;
};
float CBaseEntity::predraw(void)
float
CBaseEntity::predraw(void)
{
frame1time += clframetime;
ProcessWordQue();
addentity(this);
return PREDRAW_NEXT;
}
void
CBaseEntity::ProcessWordQue(void)
{
if (time < 1 || !m_iSentenceCount) {
return;
}
if (m_flSentenceTime > time) {
return;
}
sound(this, CHAN_VOICE, m_pSentenceQue[m_iSentencePos].m_strSnd, 1.0, ATTN_NORM);
print(sprintf("^2CBaseNPC: Speaking %s\n", m_pSentenceQue[m_iSentencePos].m_strSnd));
m_iSentencePos++;
if (m_iSentenceCount == m_iSentenceCount) {
memfree(m_pSentenceQue);
m_iSentenceCount = 0;
m_iSentencePos = 0;
m_pSentenceQue = 0;
} else {
m_flSentenceTime = time + m_pSentenceQue[m_iSentenceCount - 1].len;
}
}
/* we'll pass it a sentences.txt word (e.g. !BA_TEST) and start queing it */
void
CBaseEntity::Sentence(string msg)
{
/* not defined */
if (msg == "") {
return;
}
if (m_iSentenceCount) {
memfree(m_pSentenceQue);
m_iSentenceCount = 0;
m_pSentenceQue = 0;
m_iSentencePos = 0;
}
m_iSentenceCount = tokenize(Sentences_GetSamples(msg));
m_pSentenceQue = memalloc(sizeof(sound_t) * m_iSentenceCount);
for (int i = 0; i < m_iSentenceCount; i++) {
m_pSentenceQue[i].m_strSnd = sprintf("%s.wav", argv(i));
m_pSentenceQue[i].len = soundlength(m_pSentenceQue[i].m_strSnd);
m_pSentenceQue[i].m_flPitch = 100;
}
m_flSentenceTime = time;
}
void CBaseEntity::ReadEntity(float flChanged)
{
if (flChanged & BASEFL_CHANGED_ORIGIN) {
@ -181,3 +242,26 @@ void CBaseEntity::Initialized(void)
void CBaseEntity::CBaseEntity(void)
{
}
/* our EV_SENTENCE event */
void
CBaseEntity_ParseSentence(void)
{
entity ent;
CBaseEntity targ;
string sentence;
float e;
/* parse packets */
e = readentitynum();
sentence = readstring();
ent = findfloat(world, entnum, e);
if (ent) {
targ = (CBaseEntity)ent;
targ.Sentence(sentence);
} else {
print(sprintf("^1CBaseNPC_ParseSentence: Entity %d not in PVS\n", e));
}
}

View File

@ -60,7 +60,7 @@ float CBaseMonster::SendEntity(entity ePEnt, float fChanged)
}
WriteByte(MSG_ENTITY, ENT_NPC);
WriteShort(MSG_ENTITY, fChanged);
WriteFloat(MSG_ENTITY, fChanged);
if (fChanged & NPC_MODELINDEX)
WriteShort(MSG_ENTITY, modelindex);

View File

@ -63,7 +63,7 @@ CBaseNPC::Sentence(string sentence)
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_SENTENCE);
WriteEntity(MSG_MULTICAST, this);
WriteString(MSG_MULTICAST, Sentences_GetSamples(sentence));
WriteString(MSG_MULTICAST, seq);
msg_entity = this;
multicast(origin, MULTICAST_PVS);
}

View File

@ -34,7 +34,7 @@ enumflags
MF_FADECORPSE
};
class monster_generic : CBaseEntity
class monster_generic:CBaseEntity
{
void() monster_generic;
//virtual void() Respawn;

View File

@ -43,13 +43,20 @@ class scripted_sentence:CBaseTrigger
void scripted_sentence::Trigger(void)
{
entity speaker = find(world, CBaseEntity::m_strTargetName, m_strSpeaker);
if (!speaker) {
return;
}
print(sprintf("Speaking on %s\n", m_strSpeaker));
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EV_SENTENCE);
WriteEntity(MSG_MULTICAST, find(world, ::classname, m_strSpeaker));
WriteEntity(MSG_MULTICAST, speaker);
WriteString(MSG_MULTICAST, m_strSentence);
WriteFloat(MSG_MULTICAST, m_flPitch);
msg_entity = this;
multicast(origin, MULTICAST_PHS);
msg_entity = speaker;
multicast(speaker.origin, MULTICAST_PVS);
}
/* TODO: Make this redundant */

View File

@ -23,13 +23,6 @@
* we'll just default to those whenever there's no custom value set.
*/
typedef struct
{
string m_strSnd;
float m_flPitch;
float len;
} sound_t;
string *g_sentences;
int g_sentences_count;
@ -38,7 +31,7 @@ Sentences_Init(void)
{
filestream fs_sentences;
string temp;
int c, i;
int c;
fs_sentences = fopen("sound/sentences.txt", FILE_READ);

View File

@ -14,8 +14,8 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
float Skill_GetValue(string var)
float Skill_GetValue(string variable)
{
float skill = cvar("skill");
return cvar(sprintf("sk_%s%d", var, skill));
return cvar(sprintf("sk_%s%d", variable, skill));
}

View File

@ -290,8 +290,6 @@ void monster_barney::touch(void)
void monster_barney::PlayerUse(void)
{
int r;
if (m_iFlags & BARNF_FEAR) {
return;
}