Skip to content

Commit

Permalink
backport #75668 (#75828)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardianDll authored Aug 20, 2024
1 parent f062bae commit 4180cc3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion data/json/items/tool/explosives.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"color": "light_gray",
"use_action": { "type": "message", "message": "You've already set the %s's timer, you might want to get away from it." },
"countdown_action": { "type": "explosion", "explosion": { "power": 2000 } },
"flags": [ "TRADER_AVOID" ]
"countdown_interval": "6 seconds",
"flags": [ "TRADER_AVOID", "NPC_THROW_NOW" ]
},
{
"id": "dynamite",
Expand Down
20 changes: 14 additions & 6 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3643,16 +3643,24 @@ std::optional<int> iuse::granade_act( Character *, item *it, const tripoint &pos

std::optional<int> iuse::c4( Character *p, item *it, const tripoint & )
{
int time;
bool got_value = query_int( time, _( "Set the timer to how many seconds (0 to cancel)?" ) );
if( !got_value || time <= 0 ) {
p->add_msg_if_player( _( "Never mind." ) );
return std::nullopt;
int time = 0;
bool got_value = false;
if( p->is_avatar() ) {
got_value = query_int( time, _( "Set the timer to how many seconds (0 to cancel)?" ) );
if( !got_value || time <= 0 ) {
p->add_msg_if_player( _( "Never mind." ) );
return std::nullopt;
}
}
p->add_msg_if_player( n_gettext( "You set the timer to %d second.",
"You set the timer to %d seconds.", time ), time );
it->convert( itype_c4armed );
it->countdown_point = calendar::turn + time_duration::from_seconds( time );
if( got_value ) {
it->countdown_point = calendar::turn + time_duration::from_seconds( time );
} else {
// Uses value from the converted type (e.g. currently hardcoded c4armed)
it->countdown_point = calendar::turn + it->type->countdown_interval;
}
it->active = true;
return 1;
}
Expand Down
4 changes: 3 additions & 1 deletion src/npc_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,10 @@ void npc_attack_activate_item::use( npc &source, const tripoint &/*location*/ )
if( !source.wield( activatable_item ) ) {
debugmsg( "%s can't wield %s it tried to activate", source.disp_name(),
activatable_item.display_name() );
return;
}
source.activate_item( activatable_item );
// npc::wield may invalidate activatable_item's reference
source.activate_item( *source.get_wielded_item() );
}

bool npc_attack_activate_item::can_use( const npc &source ) const
Expand Down

0 comments on commit 4180cc3

Please sign in to comment.