Skip to content

Commit

Permalink
game: support translated sounds in messages (Heretic 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
0lvin committed Sep 14, 2024
1 parent c51ccea commit 3a5d0af
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/game/g_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/game/g_newfnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/game/g_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions src/game/g_translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/game/g_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/game/header/local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/game/player/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3a5d0af

Please sign in to comment.