Skip to content

Commit

Permalink
Fix using ammo from favorite location even when it's far away.
Browse files Browse the repository at this point in the history
  • Loading branch information
BevapDin committed Sep 27, 2019
1 parent 28028a5 commit e03f5d5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,23 @@ bool avatar_action::fire( avatar &you, map &m )
// TODO: move handling "RELOAD_AND_SHOOT" flagged guns to a separate function.
if( gun->has_flag( "RELOAD_AND_SHOOT" ) ) {
if( !gun->ammo_remaining() ) {
item::reload_option opt =
you.ammo_location &&
gun->can_reload_with( you.ammo_location->typeId() ) ?
item::reload_option( &you, args.relevant, args.relevant, you.ammo_location ) :
you.select_ammo( *gun );
const auto ammo_location_is_valid = [&]() -> bool {
if( !you.ammo_location )
{
return false;
}
if( !gun->can_reload_with( you.ammo_location->typeId() ) )
{
return false;
}
if( square_dist( you.pos(), you.ammo_location.position() ) > 1 )
{
return false;
}
return true;
};
item::reload_option opt = ammo_location_is_valid() ? item::reload_option( &you, args.relevant,
args.relevant, you.ammo_location ) : you.select_ammo( *gun );
if( !opt ) {
// Menu canceled
return false;
Expand Down

0 comments on commit e03f5d5

Please sign in to comment.