Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing damage sources kills and suicide to kills list #2092

Merged

Conversation

leoCottret
Copy link
Collaborator

@leoCottret leoCottret commented Oct 20, 2022

Summary

Purpose of change

Explosion kills from player (grenades, launchers...) were not added to his kills list, probably due to the difficulty to know who's responsible for the explosion (it was a TODO somewhere).
Since explosions kills would be added to kills list, it seemed logical to add the player to his kills list if he killed himself.
Note that direct hit that killed a creature (from a grenade or launcher) already counted, but the explosion after the hit didn't.

Describe the solution

Non technical:
Kills from player with:

  • explosive throwing items (eg grenades)
  • launchers
  • explosions from spells
  • the shockwave generator bionic
  • explosions from computers and such that can only be triggered by a player

are now added to his kill count list

If the player kill himself through damages triggered/caused by himself (including explosions), or through the "Q" key, he will be added to his kill count list.
Both old and new explosions are supported.

Technical:

details
  • "explosive throwable items" -> item get an activated_by field that stores who activated the object. This field is now sent to intermediate functions that call the explosion() functions
  • "launchers" -> projectile_attack() already had an origin field that stores who is firing. This field is now sent to intermediate functions that call the explosion() functions
  • explosion() functions, get a source parameter, for who is the source of the explosion
  • The explosion() functions create a queued_explosion type, that will be executed later in the code. I stored the source here.
  • When the queued_explosion is executed, they will call the old/new explosions functions (in explosion_funcs::regular), and apply the damages. Before this function used a nullptr as source, now they use the source
  • When applying the damage, if something is killed by the damage and the source is the player, the kill is added to the kill list (same as before, but before the source of an explosion was always nullptr)

Describe alternatives you've considered

Developping this, I realised the many cases where a kill from a player is not added to his kill count, when it should.
So excluding what's fixed by this PR, there are still some cases, including but not limited to:

  • flamethrowers
  • emp damage that fries a robot
  • closing the door on a creature and it kills it
  • explosion from an explosive terrain (eg if a player shoot a gas pump)

Testing

  • kill a zombie with a grenade, it is added to the kill list
  • kill a zombie with the explosion of a launcher, same
  • kill a zombie with the shockwave generator bionic, same
  • same tests results when killing a NPC
  • kill yourself with a grenade, you are added to the kill list
  • kill yourself with a launcher, same

Have a friendly npc with a stack of grenades

  • If he kills a zombie with a grenade, it's not added to the kill list

@leoCottret leoCottret marked this pull request as draft October 20, 2022 04:14
@leoCottret leoCottret marked this pull request as ready for review October 20, 2022 07:42
@Coolthulhu Coolthulhu self-assigned this Oct 22, 2022
safe_reference<player> player::get_safe_reference()
{
return anchor.reference_to( this );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: should probably be in Character or even Creature.

@Coolthulhu Coolthulhu merged commit d3d50eb into cataclysmbnteam:upload Oct 30, 2022
@Coolthulhu
Copy link
Member

NPCs don't get hostile when hit by grenades yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants