From e03f5d5a5146c73e86994e37f4a6d5d0a4081027 Mon Sep 17 00:00:00 2001 From: BevapDin Date: Fri, 27 Sep 2019 23:20:02 +0200 Subject: [PATCH] Fix using ammo from favorite location even when it's far away. --- src/avatar_action.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/avatar_action.cpp b/src/avatar_action.cpp index e6a659ee0a572..385993dccb27a 100644 --- a/src/avatar_action.cpp +++ b/src/avatar_action.cpp @@ -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;