Implement talk sounds

We're in Undertale
This commit is contained in:
Sally Coolatta 2023-08-25 07:53:09 -04:00
parent 3009f1c106
commit 764010b3ab
6 changed files with 54 additions and 10 deletions

View file

@ -1943,12 +1943,17 @@ bool CallFunc_DialogueSetCustomSpeaker(ACSVM::Thread *thread, const ACSVM::Word
ACSVM::String *patchStr = nullptr;
const char *patchName = nullptr;
patch_t *patch = nullptr;
ACSVM::String *colorStr = nullptr;
const char *colorName = nullptr;
skincolornum_t colorID = SKINCOLOR_NONE;
UINT8 *colormap = nullptr;
ACSVM::String *voiceStr = nullptr;
const char *voiceName = nullptr;
sfxenum_t voiceID = sfx_None;
(void)argC;
map = thread->scopeMap;
@ -1958,16 +1963,20 @@ bool CallFunc_DialogueSetCustomSpeaker(ACSVM::Thread *thread, const ACSVM::Word
patchStr = map->getString(argV[1]);
patchName = patchStr->str;
patch = static_cast<patch_t *>( W_CachePatchName(patchName, PU_CACHE) );
colorStr = map->getString(argV[1]);
colorStr = map->getString(argV[2]);
colorName = colorStr->str;
if (ACS_GetColorFromString(colorName, &colorID) == true)
{
colormap = R_GetTranslationColormap(TC_DEFAULT, colorID, GTC_CACHE);
}
g_dialogue.SetSpeaker(nametag, patchName, colormap);
voiceStr = map->getString(argV[3]);
voiceName = voiceStr->str;
ACS_GetSFXFromString(voiceName, &voiceID);
g_dialogue.SetSpeaker(nametag, patch, colormap, voiceID);
return false;
}

View file

@ -6677,6 +6677,7 @@ struct int_const_s const INT_CONST[] = {
{"SKSKSLOW",SKSKSLOW}, // Overtake taunt
{"SKSKHITM",SKSKHITM}, // Hit confirm taunt
{"SKSKPOWR",SKSKPOWR}, // Power item taunt
{"SKSKTALK",SKSKTALK}, // Dialogue
// 3D Floor/Fake Floor/FOF/whatever flags
{"FOF_EXISTS",FOF_EXISTS}, ///< Always set, to check for validity.

View file

@ -18,11 +18,13 @@
#include <algorithm>
#include "info.h"
#include "sounds.h"
#include "g_game.h"
#include "v_video.h"
#include "r_draw.h"
#include "m_easing.h"
#include "r_skins.h"
#include "s_sound.h"
#include "z_zone.h"
#include "v_draw.hpp"
@ -35,14 +37,18 @@ void Dialogue::Init(void)
{
active = true;
dismissable = false;
syllable = true;
}
void Dialogue::SetSpeaker(void)
{
// Unset speaker
speaker.clear();
portrait = nullptr;
portraitColormap = nullptr;
voiceSfx = sfx_None;
}
void Dialogue::SetSpeaker(std::string skinName, int portraitID)
@ -69,8 +75,11 @@ void Dialogue::SetSpeaker(std::string skinName, int portraitID)
const spriteframe_t *sprframe = &sprdef->spriteframes[portraitID];
speaker = skin->realname;
portrait = static_cast<patch_t *>( W_CachePatchNum(sprframe->lumppat[0], PU_CACHE) );
portraitColormap = R_GetTranslationColormap(skinID, static_cast<skincolornum_t>(skin->prefcolor), GTC_CACHE);
voiceSfx = skin->soundsid[ S_sfx[sfx_ktalk].skinsound ];
}
else
{
@ -78,22 +87,25 @@ void Dialogue::SetSpeaker(std::string skinName, int portraitID)
}
}
void Dialogue::SetSpeaker(std::string customName, std::string customPatch, UINT8 *customColormap)
void Dialogue::SetSpeaker(std::string name, patch_t *patch, UINT8 *colormap, sfxenum_t voice)
{
Init();
// Set custom speaker
speaker = customName;
speaker = name;
if (speaker.empty())
{
portrait = nullptr;
portraitColormap = nullptr;
voiceSfx = sfx_None;
return;
}
portrait = static_cast<patch_t *>( W_CachePatchName(customPatch.c_str(), PU_CACHE) );
portraitColormap = customColormap;
portrait = patch;
portraitColormap = colormap;
voiceSfx = voice;
}
void Dialogue::NewText(std::string newText)
@ -106,7 +118,7 @@ void Dialogue::NewText(std::string newText)
0, HU_FONT,
newText.c_str()
);
text.clear();
textDest = newText;
@ -139,6 +151,8 @@ void Dialogue::SetDismissable(bool value)
void Dialogue::WriteText(void)
{
bool voicePlayed = false;
textTimer -= textSpeed;
while (textTimer <= 0 && !textDest.empty())
@ -146,7 +160,21 @@ void Dialogue::WriteText(void)
char c = textDest.back();
text.push_back(c);
if (c == '.' || c == '!' || c == '?')
if (voicePlayed == false
&& std::isprint(c)
&& c != ' ')
{
if (syllable)
{
S_StopSoundByNum(voiceSfx);
S_StartSound(nullptr, voiceSfx);
}
syllable = !syllable;
voicePlayed = true;
}
if (c == '.' || c == ',' || c == ';' || c == '!' || c == '?')
{
// slow down for punctuation
textTimer += kTextPunctPause;

View file

@ -19,6 +19,7 @@
#include "doomdef.h"
#include "doomtype.h"
#include "typedef.h"
#include "sounds.h"
#include "v_video.h"
namespace srb2
@ -33,6 +34,7 @@ private:
std::string speaker;
patch_t *portrait;
UINT8 *portraitColormap;
sfxenum_t voiceSfx;
std::string text;
std::string textDest;
@ -43,6 +45,7 @@ private:
fixed_t textTimer;
fixed_t textSpeed;
bool textDone;
bool syllable;
bool dismissable;
@ -59,7 +62,7 @@ public:
void SetSpeaker(void);
void SetSpeaker(std::string skinName, int portraitID);
void SetSpeaker(std::string customName, std::string customPatch, UINT8 *customColormap);
void SetSpeaker(std::string name, patch_t *patch, UINT8 *colormap, sfxenum_t voice);
void NewText(std::string newText);

View file

@ -1439,6 +1439,7 @@ sfxinfo_t S_sfx[NUMSFX] =
{"kslow", false, 64, 32, -1, NULL, 0, SKSKSLOW, -1, LUMPERROR, ""},
{"khitem", false, 128, 32, -1, NULL, 0, SKSKHITM, -1, LUMPERROR, ""},
{"kgloat", false, 64, 48, -1, NULL, 0, SKSKPOWR, -1, LUMPERROR, ""},
{"ktalk", false, 64, 48, -1, NULL, 0, SKSKTALK, -1, LUMPERROR, ""},
// skin sounds free slots to add sounds at run time (Boris HACK!!!)
// initialized to NULL

View file

@ -56,6 +56,7 @@ typedef enum
SKSKSLOW, // Overtake taunt
SKSKHITM, // Hit confirm taunt
SKSKPOWR, // Power item taunt
SKSKTALK,
NUMSKINSOUNDS
} skinsound_t;
@ -1506,6 +1507,7 @@ typedef enum
sfx_kslow,
sfx_khitem,
sfx_kgloat,
sfx_ktalk,
// free slots for S_AddSoundFx() at run-time --------------------
sfx_freeslot0,