FWGS / hlsdk-portable

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

[They Hunger] Friendly cops attack player for killing zombified cops. #134

Closed malortie closed 4 years ago

malortie commented 4 years ago

In the original They Hunger, normal cops do not attack players for killing zombified cops.

In the crossplatform release of They Hunger, normal cops attack players for killing zombified cops.

A custom level bug_barney.zip is provided to allow for easier testing and debugging. It includes two cops - a normal cop and a zombie cop, as well as a glock at player spawn.

Steps to reproduce

  1. In the console, type the following commands:

    map bug_barney
  2. Kill the zombified cop with the glock. Make sure the normal cop can see you.

Expected behavior: Normal cop should remain friendly to the player. Actual behavior: Normal cop attacks the player.

Possible cause

According to the reverse engineered source code, there is an extra condition at the end of the line. Please, see the following below:

https://github.com/FWGS/hlsdk-xash3d/blob/1ffb009983ec7d36859e559e5dfbf0c478437846/dlls/talkmonster.cpp#L627-L628

This code is in the function EnumFriends, which is responsible for listing all 'friend' entities to this monster. The context in which the function is used is as follows: If a player kills a 'barney' monster, then it searches for every entity whose classname is part of the barney's friend array, and makes them enemy of the player.

The condition from the code snippet above determines if a friend entity must be skipped/ignored.

Normal cops and zombified cops use the same class, so to prevent zombified cops from making normal cops enemies of players whenever a player kills a zombified cop, the code above should probably rather be:

if( pFriend == this || !pFriend->IsAlive()
      // Skip if a zombie cop has been killed and the the target friend is a normal cop.
      || ( FBitSet( pev->spawnflags, SF_MONSTER_ZOMBIECOP )
      && !FBitSet( pFriend->pev->spawnflags, SF_MONSTER_ZOMBIECOP ) ) )
      continue;
nekonomicon commented 4 years ago

Thanks! Fixed.