Skip to content

Commit

Permalink
Merge pull request #77056 from ehughsbaird/track-grenade-kills
Browse files Browse the repository at this point in the history
Track kills through grenades and other explosives
  • Loading branch information
Maleclypse authored Oct 16, 2024
2 parents 6451810 + e7fdb40 commit 90591e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ stacking_info item::stacks_with( const item &rhs, bool check_components, bool co
bits.set( tname::segments::UPS, _stacks_ups( *this, rhs ) );
// Guns that differ only by dirt/shot_counter can still stack,
// but other item_vars such as label/note will prevent stacking
static const std::set<std::string> ignore_keys = { "dirt", "shot_counter", "spawn_location_omt", "ethereal" };
static const std::set<std::string> ignore_keys = { "dirt", "shot_counter", "spawn_location_omt", "ethereal", "last_act_by_char_id" };
bits.set( tname::segments::VARS, map_equal_ignoring_keys( item_vars, rhs.item_vars, ignore_keys ) );
bits.set( tname::segments::ETHEREAL, _stacks_ethereal( *this, rhs ) );
bits.set( tname::segments::LOCATION_HINT, _stacks_location_hint( *this, rhs ) );
Expand Down
15 changes: 13 additions & 2 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ std::optional<int> iuse_transform::use( Character *p, item &it, const tripoint &
return std::nullopt;
}

it.set_var( "last_act_by_char_id", p->getID().get_value() );

int result = 0;

if( need_fire ) {
Expand Down Expand Up @@ -652,10 +654,19 @@ void explosion_iuse::load( const JsonObject &obj, const std::string & )
obj.read( "scrambler_blast_radius", scrambler_blast_radius );
}

std::optional<int> explosion_iuse::use( Character *p, item &, const tripoint &pos ) const
std::optional<int> explosion_iuse::use( Character *p, item &it, const tripoint &pos ) const
{
if( explosion.power >= 0.0f ) {
explosion_handler::explosion( p, pos, explosion );
Character *source = p;
if( it.has_var( "last_act_by_char_id" ) ) {
character_id thrower( it.get_var( "last_act_by_char_id", 0 ) );
if( thrower == get_player_character().getID() ) {
source = &get_player_character();
} else {
source = g->find_npc( thrower );
}
}
explosion_handler::explosion( source, pos, explosion );
}

if( draw_explosion_radius >= 0 ) {
Expand Down
1 change: 1 addition & 0 deletions src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ dealt_projectile_attack Character::throw_item( const tripoint_bub_ms &target, co
{
// Copy the item, we may alter it before throwing
item thrown = to_throw;
thrown.set_var( "last_act_by_char_id", getID().get_value() );

const int move_cost = throw_cost( *this, to_throw );
mod_moves( -move_cost );
Expand Down

0 comments on commit 90591e5

Please sign in to comment.