FWGS / hlsdk-portable

Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
https://xash.su
Other
272 stars 124 forks source link

When finding nearest friend, skip the dying ones as well #398

Closed FreeSlave closed 1 year ago

FreeSlave commented 1 year ago

Some talkmonster code leads to the monster changing their schedule.

https://github.com/FWGS/hlsdk-portable/blob/17b34aa42b2060706deb20aa82df0ea2766e1b18/dlls/talkmonster.cpp#L1154-L1161

https://github.com/FWGS/hlsdk-portable/blob/17b34aa42b2060706deb20aa82df0ea2766e1b18/dlls/talkmonster.cpp#L1140-L1145

The FindNearestFriend (used in both cases) can return a dying (but not dead yet) monster because IsAlive is implemented differently for monsters (it returns true if monster is in dying animation).

To reproduce the bug:

  1. Have two monster_barneys nearby
  2. Kill one of them.
  3. Kill the second one while the first one is still in dying animation.

The first barney will play a death sound two times because at the time when the second barney takes damage, it makes the first barney change his schedule to slIdleStopShooting, and then he gets back to the dying schedule since he's in the dead state, playing the death sound again via TASK_SOUND_DIE. Same thing potentially can happen if the monster that is chosen to answer the question is dying at the moment of question being asked, but it's harder to reproduce.