From 92e801555df43ed353cc9152151f553dd51e28b6 Mon Sep 17 00:00:00 2001 From: Brad Harding Date: Sat, 18 Jan 2025 09:04:45 +1100 Subject: [PATCH] Fix monsters not being alerted sometimes The calls to P_NoiseAlert() were originally changed many years ago for the purpose of not alerting monsters when the player punches without making contact with anything. Discovered that broke monsters teleporting in when collecting yellow skull key in MAP02 of Eviternity II. This commit also fixes MBF21's A_NoiseAlert(), where maybe target != emitter. --- src/p_enemy.c | 6 +++--- src/p_local.h | 2 +- src/p_mobj.c | 4 ++-- src/p_pspr.c | 35 +++++------------------------------ 4 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/p_enemy.c b/src/p_enemy.c index 750972dd7..441242c99 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -108,14 +108,14 @@ static void P_RecursiveSound(sector_t *sec, const int soundblocks, mobj_t *sound // If a monster yells at the player, // it will alert other monsters to the player. // -void P_NoiseAlert(mobj_t *target) +void P_NoiseAlert(mobj_t *target, mobj_t *emitter) { // [BH] don't alert if notarget CCMD is enabled if (target->player && (viewplayer->cheats & CF_NOTARGET)) return; validcount++; - P_RecursiveSound(target->subsector->sector, 0, target); + P_RecursiveSound(emitter->subsector->sector, 0, target); } // @@ -2740,7 +2740,7 @@ void A_NoiseAlert(mobj_t *actor, player_t *player, pspdef_t *psp) if (!actor->target) return; - P_NoiseAlert(actor); + P_NoiseAlert(actor->target, actor); } // diff --git a/src/p_local.h b/src/p_local.h index b73fdb5d3..c3861ee87 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -177,7 +177,7 @@ bool P_SeekerMissile(mobj_t *actor, mobj_t **seektarget, angle_t thresh, angle_t extern uint64_t shake; extern int shakeduration; -void P_NoiseAlert(mobj_t *target); +void P_NoiseAlert(mobj_t *target, mobj_t *emitter); bool P_CheckMeleeRange(mobj_t *actor); // diff --git a/src/p_mobj.c b/src/p_mobj.c index 218112213..7db887d90 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -703,7 +703,7 @@ void P_MobjThinker(mobj_t *mobj) player->deltaviewheight = mobj->momz / 8; if (mobj->momz < -23 * FRACUNIT) - P_NoiseAlert(mobj); + P_NoiseAlert(mobj, mobj); } if (onmo->z + onmo->height - mobj->z <= 24 * FRACUNIT) @@ -1755,7 +1755,7 @@ mobj_t *P_SpawnPlayerMissile(mobj_t *source, mobjtype_t type) th->momz = FixedMul(speed, slope); th->interpolate = -1; - P_NoiseAlert(source); + P_NoiseAlert(source, source); if (type == MT_ROCKET && r_rockettrails && !(th->flags & MF_BOUNCES) && viewplayer->readyweapon == wp_missile && !chex && !hacx && !norockettrails && !incompatiblepalette) diff --git a/src/p_pspr.c b/src/p_pspr.c index 275d90e0a..d5a4a7116 100644 --- a/src/p_pspr.c +++ b/src/p_pspr.c @@ -222,6 +222,9 @@ void P_FireWeapon(void) P_SetMobjState(viewplayer->mo, S_PLAY_ATK1); P_SetPlayerSprite(ps_weapon, weaponinfo[readyweapon].atkstate); + if (!(weaponinfo[readyweapon].flags & WPF_SILENT)) + P_NoiseAlert(viewplayer->mo, viewplayer->mo); + if (readyweapon == wp_bfg) P_RumbleWeapon(wp_bfg); @@ -423,9 +426,6 @@ void A_Punch(mobj_t *actor, player_t *player, pspdef_t *psp) if (linetarget || hitwall) { - if (!(weaponinfo[readyweapon].flags & WPF_SILENT)) - P_NoiseAlert(actor); - S_StartSound(actor, sfx_punch); // turn to face target @@ -469,9 +469,6 @@ void A_Saw(mobj_t *actor, player_t *player, pspdef_t *psp) A_Recoil(readyweapon); P_RumbleWeapon(readyweapon); - if (!(weaponinfo[readyweapon].flags & WPF_SILENT)) - P_NoiseAlert(actor); - player->shotsfired[readyweapon]++; stat_shotsfired[wp_chainsaw] = SafeAdd(stat_shotsfired[wp_chainsaw], 1); idlechainsawrumblestrength = 0; @@ -683,9 +680,6 @@ void A_FirePistol(mobj_t *actor, player_t *player, pspdef_t *psp) const weapontype_t readyweapon = player->readyweapon; const weaponinfo_t readyweaponinfo = weaponinfo[readyweapon]; - if (!(weaponinfo[player->readyweapon].flags & WPF_SILENT)) - P_NoiseAlert(actor); - S_StartSound(actor, sfx_pistol); P_SetMobjState(player->mo, S_PLAY_ATK2); P_SubtractAmmo(); @@ -716,9 +710,6 @@ void A_FireShotgun(mobj_t *actor, player_t *player, pspdef_t *psp) const weapontype_t readyweapon = player->readyweapon; const weaponinfo_t readyweaponinfo = weaponinfo[readyweapon]; - if (!(readyweaponinfo.flags & WPF_SILENT)) - P_NoiseAlert(actor); - S_StartSound(actor, sfx_shotgn); P_SetMobjState(player->mo, S_PLAY_ATK2); P_SubtractAmmo(); @@ -753,9 +744,6 @@ void A_FireShotgun2(mobj_t *actor, player_t *player, pspdef_t *psp) const weapontype_t readyweapon = player->readyweapon; const weaponinfo_t readyweaponinfo = weaponinfo[readyweapon]; - if (!(readyweaponinfo.flags & WPF_SILENT)) - P_NoiseAlert(actor); - S_StartSound(actor, sfx_dshtgn); P_SetMobjState(player->mo, S_PLAY_ATK2); P_SubtractAmmo(); @@ -814,9 +802,6 @@ void A_FireCGun(mobj_t *actor, player_t *player, pspdef_t *psp) P_SetMobjState(player->mo, S_PLAY_ATK2); S_StartSound(actor, sfx_pistol); - if (!(readyweaponinfo.flags & WPF_SILENT)) - P_NoiseAlert(actor); - P_SubtractAmmo(); P_SetPlayerSprite(ps_flash, readyweaponinfo.flashstate + (unsigned int)((psp->state - &states[S_CHAIN1]) & 1)); P_BulletSlope(actor); @@ -864,9 +849,6 @@ void A_BFGSpray(mobj_t *actor, player_t *player, pspdef_t *psp) mobj_t *mo = actor->target; angle_t an = actor->angle - ANG90 / 2; - if (!(weaponinfo[wp_bfg].flags & WPF_SILENT)) - P_NoiseAlert(actor); - // offset angles from its attack angle for (int i = 0; i < 40; i++) { @@ -1072,9 +1054,6 @@ void A_WeaponBulletAttack(mobj_t *actor, player_t *player, pspdef_t *psp) numbullets = state->args[2]; readyweapon = player->readyweapon; - if (!(weaponinfo[readyweapon].flags & WPF_SILENT)) - P_NoiseAlert(actor); - P_BulletSlope(player->mo); for (int i = 0; i < numbullets; i++) @@ -1103,7 +1082,6 @@ void A_WeaponMeleeAttack(mobj_t *actor, player_t *player, pspdef_t *psp) int slope; int damage; state_t *state = psp->state; - weapontype_t readyweapon; if (!state) return; @@ -1132,16 +1110,13 @@ void A_WeaponMeleeAttack(mobj_t *actor, player_t *player, pspdef_t *psp) if (!linetarget) return; - if (!(weaponinfo[(readyweapon = player->readyweapon)].flags & WPF_SILENT)) - P_NoiseAlert(actor); - // un-missed! S_StartSound(player->mo, state->args[3]); // turn to face target player->mo->angle = R_PointToAngle2(player->mo->x, player->mo->y, linetarget->x, linetarget->y); - P_RumbleWeapon(readyweapon); + P_RumbleWeapon(player->readyweapon); } // @@ -1166,7 +1141,7 @@ void A_WeaponSound(mobj_t *actor, player_t *player, pspdef_t *psp) // void A_WeaponAlert(mobj_t *actor, player_t *player, pspdef_t *psp) { - P_NoiseAlert(player->mo); + P_NoiseAlert(player->mo, player->mo); } //