Skip to content

Commit

Permalink
Fix monsters not being alerted sometimes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bradharding committed Jan 17, 2025
1 parent 750e606 commit 92e8015
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/p_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//
Expand Down Expand Up @@ -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);
}

//
Expand Down
2 changes: 1 addition & 1 deletion src/p_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

//
Expand Down
4 changes: 2 additions & 2 deletions src/p_mobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
35 changes: 5 additions & 30 deletions src/p_pspr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

//
Expand All @@ -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);
}

//
Expand Down

0 comments on commit 92e8015

Please sign in to comment.