From 2c0a0a13379bd3d12ad3fd4db2be0e35ac8c4c4c Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sat, 30 Dec 2023 14:32:35 +0100 Subject: [PATCH] port: net: don't play death music, pain and pickup sounds from other players --- src/game/chraction.c | 2 +- src/game/music.c | 2 +- src/game/player.c | 14 ++++++++++++++ src/game/propobj.c | 16 ++++++++-------- src/game/propsnd.c | 9 +++++++-- src/include/game/player.h | 1 + 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/game/chraction.c b/src/game/chraction.c index 9867ef28b..4bf5ccb64 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -4042,7 +4042,7 @@ void chrChoke(struct chrdata *chr, s32 choketype) if (soundnum >= 0) { if (chr->prop->type == PROPTYPE_PLAYER) { if (g_Vars.players[playernum]->chokehandle == NULL) { - sndStart(var80095200, soundnum, &g_Vars.players[playernum]->chokehandle, -1, -1, -1, -1, -1); + playerSndStart(var80095200, soundnum, &g_Vars.players[playernum]->chokehandle, playernum, -1, -1, -1); } } else { psStopSound(chr->prop, PSTYPE_CHRTALK, 0); diff --git a/src/game/music.c b/src/game/music.c index 91b9967ed..769878576 100644 --- a/src/game/music.c +++ b/src/game/music.c @@ -521,7 +521,7 @@ void _musicStartMpDeath(f32 arg0) void musicStartMpDeath(void) { #ifndef PLATFORM_N64 - if (g_MusicDisableMpDeath) { + if (g_MusicDisableMpDeath || (g_NetMode && g_Vars.currentplayernum != 0)) { return; } #endif diff --git a/src/game/player.c b/src/game/player.c index 9d078fbd7..0c1352b57 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -5848,6 +5848,20 @@ void player0f0c3320(Mtxf *matrices, s32 count) } } +struct sndstate *playerSndStart(s32 arg0, s16 sound, struct sndstate **handle, s32 playernum, f32 pitch, s32 fxbus, s32 fxmix) +{ + s32 vol = -1; + s32 pan = -1; +#ifndef PLATFORM_N64 + const struct player *pl = g_Vars.players[playernum]; + if (g_NetMode && playernum != 0 && pl && pl->prop) { + // auto attenuate sounds for remote players + psGetTheoreticalVolPan(&pl->prop->pos, pl->prop->rooms, sound, &vol, &pan); + } +#endif + return sndStart(arg0, sound, handle, vol, pan, pitch, fxbus, fxmix); +} + #if MAX_PLAYERS > 4 s32 playerGetCount(void) diff --git a/src/game/propobj.c b/src/game/propobj.c index be4170787..598eae641 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -16890,7 +16890,7 @@ void ammotypePlayPickupSound(u32 ammotype) case AMMOTYPE_CLOAK: case AMMOTYPE_BOOST: case AMMOTYPE_TOKEN: - sndStart(var80095200, SFX_PICKUP_AMMO, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, SFX_PICKUP_AMMO, NULL, g_Vars.currentplayernum, -1, -1, -1); break; case AMMOTYPE_REMOTE_MINE: case AMMOTYPE_PROXY_MINE: @@ -16899,10 +16899,10 @@ void ammotypePlayPickupSound(u32 ammotype) case AMMOTYPE_MICROCAMERA: case AMMOTYPE_PLASTIQUE: case AMMOTYPE_ECM_MINE: - sndStart(var80095200, SFX_PICKUP_MINE, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, SFX_PICKUP_MINE, NULL, g_Vars.currentplayernum, -1, -1, -1); break; case AMMOTYPE_KNIFE: - sndStart(var80095200, SFX_PICKUP_KNIFE, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, SFX_PICKUP_KNIFE, NULL, g_Vars.currentplayernum, -1, -1, -1); break; } } @@ -16967,7 +16967,7 @@ void weaponPlayPickupSound(s32 weaponnum) sound = SFX_PICKUP_GUN; } - sndStart(var80095200, sound, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, sound, NULL, g_Vars.currentplayernum, -1, -1, -1); } void ammotypeGetPickupMessage(char *dst, s32 ammotype, s32 qty) @@ -17280,7 +17280,7 @@ s32 propPickupByPlayer(struct prop *prop, bool showhudmsg) switch (obj->type) { case OBJTYPE_KEY: if (g_Vars.in_cutscene == false) { - sndStart(var80095200, SFX_PICKUP_KEYCARD, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, SFX_PICKUP_KEYCARD, NULL, g_Vars.currentplayernum, -1, -1, -1); } if (showhudmsg) { @@ -17320,7 +17320,7 @@ s32 propPickupByPlayer(struct prop *prop, bool showhudmsg) } if (g_Vars.in_cutscene == false) { - sndStart(var80095200, SFX_PICKUP_AMMO, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, SFX_PICKUP_AMMO, NULL, g_Vars.currentplayernum, -1, -1, -1); } result = TICKOP_FREE; @@ -17473,7 +17473,7 @@ s32 propPickupByPlayer(struct prop *prop, bool showhudmsg) playerSetShieldFrac(((struct shieldobj *) prop->obj)->amount); if (!g_Vars.in_cutscene) { - sndStart(var80095200, SFX_PICKUP_SHIELD, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, SFX_PICKUP_SHIELD, NULL, g_Vars.currentplayernum, -1, -1, -1); } if (showhudmsg) { @@ -17510,7 +17510,7 @@ s32 propPickupByPlayer(struct prop *prop, bool showhudmsg) case OBJTYPE_TINTEDGLASS: default: if (g_Vars.in_cutscene == false) { - sndStart(var80095200, SFX_PICKUP_KEYCARD, NULL, -1, -1, -1, -1, -1); + playerSndStart(var80095200, SFX_PICKUP_KEYCARD, NULL, g_Vars.currentplayernum, -1, -1, -1); } if (showhudmsg) { diff --git a/src/game/propsnd.c b/src/game/propsnd.c index 9e6ab03ae..5125fe70e 100644 --- a/src/game/propsnd.c +++ b/src/game/propsnd.c @@ -1284,11 +1284,16 @@ s32 psCalculatePan2(struct coord *pos, s32 arg1, f32 arg2, struct pschannel *cha f32 f2; if (LOCALPLAYERCOUNT() < 2) { - struct coord *campos = &g_Vars.currentplayer->cam_pos; +#ifdef PLATFORM_N64 + struct player *player = g_Vars.currentplayer; +#else + struct player *player = g_Vars.players[0] ? g_Vars.players[0] : g_Vars.currentplayer; +#endif + struct coord *campos = &player->cam_pos; f32 sp3c; f32 sp38; - f2 = -(atan2f(pos->x - campos->x, pos->z - campos->z) * 180.0f / M_PI + g_Vars.currentplayer->vv_theta); + f2 = -(atan2f(pos->x - campos->x, pos->z - campos->z) * 180.0f / M_PI + player->vv_theta); if (arg2 >= 0.0f) { sp3c = sinf(0.017453292f * f2); diff --git a/src/include/game/player.h b/src/include/game/player.h index 4b2233cc1..6c84f2e56 100644 --- a/src/include/game/player.h +++ b/src/include/game/player.h @@ -107,5 +107,6 @@ void playerSetCamPropertiesWithoutRoom(struct coord *pos, struct coord *up, stru void playerSetCamProperties(struct coord *pos, struct coord *up, struct coord *look, s32 room); void playerClearMemCamRoom(void); s32 playerGetCount(void); +struct sndstate *playerSndStart(s32 arg0, s16 sound, struct sndstate **handle, s32 playernum, f32 pitch, s32 fxbus, s32 fxmix); #endif