game: support translated sounds in messages (Heretic 2)

This commit is contained in:
Denis Pauk 2024-09-14 23:44:01 +03:00
parent c51ccea802
commit 3a5d0afea5
7 changed files with 44 additions and 13 deletions

View file

@ -2601,6 +2601,8 @@ void
door_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */,
csurface_t *surf /* unused */)
{
int sound_index;
if (!self || !other)
{
return;
@ -2618,8 +2620,9 @@ door_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */,
self->touch_debounce_time = level.time + 5.0;
gi.centerprintf(other, "%s", LocalizationMessage(self->message));
gi.sound(other, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
sound_index = gi.soundindex("misc/talk1.wav");
gi.centerprintf(other, "%s", LocalizationMessage(self->message, &sound_index));
gi.sound(other, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
void

View file

@ -228,7 +228,15 @@ secret_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */, csurfa
if (self->message)
{
gi.centerprintf(other, LocalizationMessage(self->message));
int sound_index;
sound_index = 0;
gi.centerprintf(other, LocalizationMessage(self->message, &sound_index));
if (sound_index)
{
gi.sound(other, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
}
}

View file

@ -865,7 +865,8 @@ SP_worldspawn(edict_t *ent)
/* make some data visible to the server */
if (ent->message && ent->message[0])
{
Q_strlcpy(level.level_name, LocalizationMessage(ent->message), sizeof(level.level_name));
Q_strlcpy(level.level_name, LocalizationMessage(ent->message, NULL),
sizeof(level.level_name));
gi.configstring(CS_NAME, level.level_name);
}
else

View file

@ -270,9 +270,21 @@ LocalizationInit(void)
{
*sign = 0;
sign ++;
/* replace '\' with '/' in sound path */
currend = sign;
while(*currend)
{
if (*currend == '\\')
{
*currend = '/';
}
currend++;
}
}
/* replace @ with new line */
/* replace @ in message with new line */
currend = curr;
while(*currend)
{
@ -360,7 +372,7 @@ LocalizationSearch(const char *name)
}
const char*
LocalizationMessage(const char *message)
LocalizationMessage(const char *message, int *sound_index)
{
if (!message || !localmessages || !nlocalmessages)
{
@ -375,6 +387,11 @@ LocalizationMessage(const char *message)
i = LocalizationSearch(message);
if (i >= 0)
{
if (sound_index && localmessages[i].sound)
{
*sound_index = gi.soundindex(localmessages[i].sound);
}
return localmessages[i].value;
}
}

View file

@ -321,17 +321,19 @@ G_UseTargets(edict_t *ent, edict_t *activator)
/* print the message */
if (activator && (ent->message) && !(activator->svflags & SVF_MONSTER))
{
gi.centerprintf(activator, "%s", LocalizationMessage(ent->message));
int sound_index;
if (ent->noise_index)
{
gi.sound(activator, CHAN_AUTO, ent->noise_index, 1, ATTN_NORM, 0);
sound_index = ent->noise_index;
}
else
{
gi.sound(activator, CHAN_AUTO, gi.soundindex(
"misc/talk1.wav"), 1, ATTN_NORM, 0);
sound_index = gi.soundindex("misc/talk1.wav");
}
gi.centerprintf(activator, "%s", LocalizationMessage(ent->message, &sound_index));
gi.sound(activator, CHAN_AUTO, sound_index, 1, ATTN_NORM, 0);
}
/* kill killtargets */

View file

@ -996,7 +996,7 @@ void EndDMLevel(void);
/* g_translate.c */
void LocalizationInit(void);
const char* LocalizationMessage(const char *message);
const char* LocalizationMessage(const char *message, int *sound_index);
/* g_chase.c */
void UpdateChaseCam(edict_t *ent);

View file

@ -421,8 +421,8 @@ HelpComputerMessage(edict_t *ent)
"xv 50 yv 172 string2 \"%3i/%3i %i/%i %i/%i\" ",
sk,
level.level_name,
LocalizationMessage(game.helpmessage1),
LocalizationMessage(game.helpmessage2),
LocalizationMessage(game.helpmessage1, NULL),
LocalizationMessage(game.helpmessage2, NULL),
level.killed_monsters, level.total_monsters,
level.found_goals, level.total_goals,
level.found_secrets, level.total_secrets);