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

feat: Weapons track what is killed with them #5394

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions data/raw/keybindings/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,13 @@
"name": "Disassemble",
"bindings": [ { "input_method": "keyboard", "key": "D" } ]
},
{
"id": "SHOW_KILL_LIST",
"type": "keybinding",
"category": "INVENTORY_ITEM",
"name": "Kills",
"bindings": [ { "input_method": "keyboard", "key": "K" } ]
},
{
"id": "FAVORITE_ADD",
"type": "keybinding",
Expand Down
6 changes: 3 additions & 3 deletions src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ projectile_attack_aim projectile_attack_roll( const dispersion_sources &dispersi

dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tripoint &source,
const tripoint &target_arg, const dispersion_sources &dispersion,
Creature *origin, const vehicle *in_veh )
Creature *origin, item *s_weapon, const vehicle *in_veh )
{
const bool do_animation = get_option<bool>( "ANIMATION_PROJECTILES" );

Expand Down Expand Up @@ -432,7 +432,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
continue;
}
attack.missed_by = cur_missed_by;
critter->deal_projectile_attack( null_source ? nullptr : origin, attack );
critter->deal_projectile_attack( null_source ? nullptr : origin, s_weapon, attack );
// Critter can still dodge the projectile
// In this case hit_critter won't be set
if( attack.hit_critter != nullptr ) {
Expand Down Expand Up @@ -501,7 +501,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
Creature &z = *mon_ptr;
add_msg( _( "The attack bounced to %s!" ), z.get_name() );
z.add_effect( effect_bounced, 1_turns );
projectile_attack( proj, tp, z.pos(), dispersion, origin, in_veh );
projectile_attack( proj, tp, z.pos(), dispersion, origin, s_weapon, in_veh );
sfx::play_variant_sound( "fire_gun", "bio_lightning_tail",
sfx::get_heard_volume( z.pos() ), sfx::get_heard_angle( z.pos() ) );
}
Expand Down
3 changes: 2 additions & 1 deletion src/ballistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define CATA_SRC_BALLISTICS_H

class Creature;
class item;
class dispersion_sources;
class vehicle;
struct dealt_projectile_attack;
Expand Down Expand Up @@ -32,7 +33,7 @@ projectile_attack_aim projectile_attack_roll( const dispersion_sources &dispersi
*/
dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tripoint &source,
const tripoint &target_arg, const dispersion_sources &dispersion,
Creature *origin = nullptr, const vehicle *in_veh = nullptr );
Creature *origin = nullptr, item *s_weapon = nullptr, const vehicle *in_veh = nullptr );

namespace ranged
{
Expand Down
25 changes: 22 additions & 3 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8919,7 +8919,8 @@ void Character::on_hit( Creature *source, bodypart_id bp_hit,
Where damage to character is actually applied to hit body parts
Might be where to put bleed stuff rather than in player::deal_damage()
*/
void Character::apply_damage( Creature *source, bodypart_id hurt, int dam,
void Character::apply_damage( Creature *source, item *s_weapon, item *s_proj, bodypart_id hurt,
int dam,
const bool bypass_med )
{
if( is_dead_state() || has_trait( trait_DEBUG_NODMG ) ) {
Expand Down Expand Up @@ -8961,6 +8962,12 @@ void Character::apply_damage( Creature *source, bodypart_id hurt, int dam,
get_name() );
}
set_killer( source );
if( s_weapon ) {
s_weapon->add_npc_kill( get_name() );
}
if( s_proj ) {
s_proj->add_npc_kill( get_name() );
}
}

if( !bypass_med ) {
Expand All @@ -8974,9 +8981,21 @@ void Character::apply_damage( Creature *source, bodypart_id hurt, int dam,
}
}
}
void Character::apply_damage( Creature *source, item *s_weapon, bodypart_id hurt,
int dam,
const bool bypass_med )
{
apply_damage( source, s_weapon, nullptr, hurt, dam, bypass_med );
}
void Character::apply_damage( Creature *source, bodypart_id hurt,
int dam,
const bool bypass_med )
{
apply_damage( source, nullptr, nullptr, hurt, dam, bypass_med );
}

dealt_damage_instance Character::deal_damage( Creature *source, bodypart_id bp,
const damage_instance &d )
const damage_instance &d, item *s_weapon, item *s_proj )
{
if( has_trait( trait_DEBUG_NODMG ) ) {
return dealt_damage_instance();
Expand All @@ -8989,7 +9008,7 @@ dealt_damage_instance Character::deal_damage( Creature *source, bodypart_id bp,
}

//damage applied here
dealt_damage_instance dealt_dams = Creature::deal_damage( source, bp, d );
dealt_damage_instance dealt_dams = Creature::deal_damage( source, bp, d, s_weapon, s_proj );
//block reduction should be by applied this point
int dam = dealt_dams.total_damage();

Expand Down
6 changes: 5 additions & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,15 @@ class Character : public Creature, public location_visitable<Character>
void did_hit( Creature &target );

/** Actually hurt the player, hurts a body_part directly, no armor reduction */
void apply_damage( Creature *source, item *s_weapon, item *s_proj, bodypart_id hurt, int dam,
bool bypass_med = false ) override;
void apply_damage( Creature *source, item *s_weapon, bodypart_id hurt, int dam,
bool bypass_med = false ) override;
void apply_damage( Creature *source, bodypart_id hurt, int dam,
bool bypass_med = false ) override;
/** Calls Creature::deal_damage and handles damaged effects (waking up, etc.) */
dealt_damage_instance deal_damage( Creature *source, bodypart_id bp,
const damage_instance &d ) override;
const damage_instance &d, item *s_weapon = nullptr, item *s_proj = nullptr ) override;
/** Reduce healing effect intensity, return initial intensity of the effect */
int reduce_healing_effect( const efftype_id &eff_id, int remove_med, const bodypart_id &hurt );

Expand Down
46 changes: 35 additions & 11 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ int Creature::deal_melee_attack( Creature *source, int hitroll )
return hit_spread;
}

void Creature::deal_melee_hit( Creature *source, int hit_spread, bool critical_hit,
void Creature::deal_melee_hit( Creature *source, item *s_weapon, int hit_spread, bool critical_hit,
const damage_instance &dam, dealt_damage_instance &dealt_dam )
{
if( source == nullptr || source->is_hallucination() ) {
Expand All @@ -592,7 +592,7 @@ void Creature::deal_melee_hit( Creature *source, int hit_spread, bool critical_h
if( mons && mons->mounted_player ) {
if( !mons->has_flag( MF_MECH_DEFENSIVE ) &&
one_in( std::max( 2, mons->get_size() - mons->mounted_player->get_size() ) ) ) {
mons->mounted_player->deal_melee_hit( source, hit_spread, critical_hit, dam, dealt_dam );
mons->mounted_player->deal_melee_hit( source, s_weapon, hit_spread, critical_hit, dam, dealt_dam );
return;
}
}
Expand All @@ -603,9 +603,14 @@ void Creature::deal_melee_hit( Creature *source, int hit_spread, bool critical_h
block_hit( source, bp_hit, d );

on_hit( source, bp_hit ); // trigger on-gethit events
dealt_dam = deal_damage( source, bp_hit, d );
dealt_dam = deal_damage( source, bp_hit, d, s_weapon );
dealt_dam.bp_hit = bp_token;
}
void Creature::deal_melee_hit( Creature *source, int hit_spread, bool critical_hit,
const damage_instance &dam, dealt_damage_instance &dealt_dam )
{
deal_melee_hit( source, nullptr, hit_spread, critical_hit, dam, dealt_dam );
}

namespace ranged
{
Expand Down Expand Up @@ -677,7 +682,8 @@ void print_dmg_msg( Creature &target, Creature *source, const dealt_damage_insta
}
}

dealt_damage_instance hit_with_aoe( Creature &target, Creature *source, const damage_instance &di )
dealt_damage_instance hit_with_aoe( Creature &target, Creature *source, item *s_weapon,
const damage_instance &di )
{
auto &all_body_parts = target.get_body();
float hit_size_sum = std::accumulate( all_body_parts.begin(), all_body_parts.end(), 0.0f,
Expand All @@ -692,7 +698,7 @@ dealt_damage_instance hit_with_aoe( Creature &target, Creature *source, const da
bool hit_this_bp = false;
damage_instance impact = di;
impact.mult_damage( pr.first->hit_size / hit_size_sum );
dealt_damage_instance bp_damage = target.deal_damage( source, pr.first.id(), impact );
dealt_damage_instance bp_damage = target.deal_damage( source, pr.first.id(), impact, s_weapon );
for( size_t i = 0; i < dealt_damage.dealt_dams.size(); i++ ) {
dealt_damage.dealt_dams[i] += bp_damage.dealt_dams[i];
hit_this_bp |= bp_damage.dealt_dams[i] > 0;
Expand All @@ -717,7 +723,7 @@ dealt_damage_instance hit_with_aoe( Creature &target, Creature *source, const da
monster *mons = dynamic_cast<monster *>( &target );
if( mons && mons->mounted_player && !mons->has_flag( MF_MECH_DEFENSIVE ) ) {
// TODO: Return value
hit_with_aoe( *mons->mounted_player, source, di );
hit_with_aoe( *mons->mounted_player, source, s_weapon, di );
}
}

Expand Down Expand Up @@ -755,10 +761,12 @@ auto get_stun_srength( const projectile &proj, creature_size size ) -> int
* Attempts to harm a creature with a projectile.
*
* @param source Pointer to the creature who shot the projectile.
* @param s_weapon Pointer to the weapon used to fire the projectile.
* @param attack A structure describing the attack and its results.
* @param print_messages enables message printing by default.
*/
void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack &attack )
void Creature::deal_projectile_attack( Creature *source, item *s_weapon,
dealt_projectile_attack &attack )
{
const bool magic = attack.proj.has_effect( ammo_effect_magic );
const bool targetted_crit_allowed = !attack.proj.has_effect( ammo_effect_NO_CRIT );
Expand All @@ -773,7 +781,7 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack
if( mons && mons->mounted_player ) {
if( !mons->has_flag( MF_MECH_DEFENSIVE ) &&
one_in( std::max( 2, mons->get_size() - mons->mounted_player->get_size() ) ) ) {
mons->mounted_player->deal_projectile_attack( source, attack );
mons->mounted_player->deal_projectile_attack( source, s_weapon, attack );
return;
}
}
Expand Down Expand Up @@ -891,7 +899,8 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack

// If we have a shield, it might passively block ranged impacts
block_ranged_hit( source, bp_hit, impact );
dealt_dam = deal_damage( source, bp_hit, impact );
// If the projectile survives, both it and the launcher get credit for the kill.
dealt_dam = deal_damage( source, bp_hit, impact, s_weapon, attack.proj.get_drop() );
dealt_dam.bp_hit = bp_hit->token;

// Apply ammo effects to target.
Expand Down Expand Up @@ -973,8 +982,13 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack
attack.missed_by = goodhit;
}

void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack &attack )
{
deal_projectile_attack( source, nullptr, attack );
}

dealt_damage_instance Creature::deal_damage( Creature *source, bodypart_id bp,
const damage_instance &dam )
const damage_instance &dam, item *s_weapon, item *s_proj )
{
if( is_dead_state() ) {
return dealt_damage_instance();
Expand All @@ -998,9 +1012,19 @@ dealt_damage_instance Creature::deal_damage( Creature *source, bodypart_id bp,

mod_pain( total_pain );

apply_damage( source, bp, total_damage );
apply_damage( source, s_weapon, s_proj, bp, total_damage );
return dealt_dams;
}
dealt_damage_instance Creature::deal_damage( Creature *source, bodypart_id bp,
const damage_instance &dam, item *s_weapon )
{
return deal_damage( source, bp, dam, s_weapon, nullptr );
}
dealt_damage_instance Creature::deal_damage( Creature *source, bodypart_id bp,
const damage_instance &dam )
{
return deal_damage( source, bp, dam, nullptr, nullptr );
}
void Creature::deal_damage_handle_type( const damage_unit &du, bodypart_id bp, int &damage,
int &pain )
{
Expand Down
16 changes: 16 additions & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,15 @@

// completes a melee attack against the creature
// dealt_dam is overwritten with the values of the damage dealt
virtual void deal_melee_hit( Creature *source, item *s_weapon, int hit_spread, bool critical_hit,
const damage_instance &dam, dealt_damage_instance &dealt_dam );
virtual void deal_melee_hit( Creature *source, int hit_spread, bool critical_hit,
const damage_instance &dam, dealt_damage_instance &dealt_dam );

// Makes a ranged projectile attack against the creature
// Sets relevant values in `attack`.
virtual void deal_projectile_attack( Creature *source, item *s_weapon,
dealt_projectile_attack &attack );
virtual void deal_projectile_attack( Creature *source, dealt_projectile_attack &attack );

/**
Expand All @@ -374,15 +378,27 @@
* @param source The attacking creature, can be null.
* @param bp The attacked body part
* @param dam The damage dealt
* @param s_weapon The weapon used in the attack, optional
* @param s_proj The projectile fired in the attack, optional
*/
virtual dealt_damage_instance deal_damage( Creature *source, bodypart_id bp,
const damage_instance &dam, item *s_weapon, item *s_proj );
virtual dealt_damage_instance deal_damage( Creature *source, bodypart_id bp,

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]

Check warning on line 386 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&, item*)’ was hidden [-Woverloaded-virtual]
const damage_instance &dam, item *s_weapon );
virtual dealt_damage_instance deal_damage( Creature *source, bodypart_id bp,

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Curses

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]

Check warning on line 388 in src/creature.h

View workflow job for this annotation

GitHub Actions / GCC 12, Ubuntu, Tiles, Sound, Lua

‘virtual dealt_damage_instance Creature::deal_damage(Creature*, bodypart_id, const damage_instance&)’ was hidden [-Woverloaded-virtual]
const damage_instance &dam );

// for each damage type, how much gets through and how much pain do we
// accrue? mutates damage and pain
virtual void deal_damage_handle_type( const damage_unit &du,
bodypart_id bp, int &damage, int &pain );
// directly decrements the damage. ONLY handles damage, doesn't
// increase pain, apply effects, etc
virtual void apply_damage( Creature *source, item *s_weapon, item *s_proj, bodypart_id bp,
int amount,
bool bypass_med = false ) = 0;
virtual void apply_damage( Creature *source, item *s_weapon, bodypart_id bp, int amount,
bool bypass_med = false ) = 0;
virtual void apply_damage( Creature *source, bodypart_id bp, int amount,
bool bypass_med = false ) = 0;

Expand Down
7 changes: 7 additions & 0 deletions src/examine_item_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ bool run(
return true;
} );

if( itm.kills_set() ) {
add_entry( "SHOW_KILL_LIST", hint_rating::good, [&]() {
itm.show_kill_list();
return true;
} );
}

if( !itm.is_favorite ) {
add_entry( "FAVORITE_ADD",
hint_rating::good, [&]() {
Expand Down
41 changes: 41 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
#include "ret_val.h"
#include "rot.h"
#include "rng.h"
#include "scores_ui.h"
#include "skill.h"
#include "stomach.h"
#include "string_formatter.h"
Expand Down Expand Up @@ -10702,3 +10703,43 @@ location_vector<item> &item::get_components()
{
return components;
}

bool item::kills_set()
{
if( kills ) {
return true;
} else {
return false;
}
}

void item::add_monster_kill( mtype_id mon )
{
if( !kills ) {
kills = std::make_unique<kill_tracker>( false );
}
kills->add_monster( mon );
}
void item::add_npc_kill( std::string npc )
{
if( !kills ) {
kills = std::make_unique<kill_tracker>( false );
}
kills->add_npc( npc );
}
void item::show_kill_list()
{
if( !kills ) {
debugmsg( "Tried to display empty kill list" );
return;
}
show_kills( *kills );
}
int item::kill_count()
{
if( !kills ) {
return 0;
} else {
return kills->monster_kill_count() + kills->npc_kill_count();
}
}
12 changes: 12 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "units.h"
#include "value_ptr.h"
#include "visitable.h"
#include <kill_tracker.h>

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

Check failure on line 34 in src/item.h

View workflow job for this annotation

GitHub Actions / build

'kill_tracker.h' file not found with <angled> include; use "quotes" instead [clang-diagnostic-error]

class Character;
class JsonIn;
Expand Down Expand Up @@ -2425,6 +2426,17 @@
* Ideally, this would be stored outside item class.
*/
pimpl<item_drop_token> drop_token;

/** Kill tracker */
private:
std::unique_ptr<kill_tracker> kills;

public:
bool kills_set();
void add_monster_kill( mtype_id );
void add_npc_kill( std::string );
void show_kill_list();
int kill_count();
};

bool item_compare_by_charges( const item &left, const item &right );
Expand Down
Loading
Loading