Skip to content

Commit

Permalink
feat: allow stashing items in holsters/sheathes in reload menu (cat…
Browse files Browse the repository at this point in the history
…aclysmbnteam#4874)

* feat: allow stashing items in holsters/sheathes in `r`eload menu

* Update character.cpp
  • Loading branch information
chaosvolt authored Jun 25, 2024
1 parent 08d452a commit 902302b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
16 changes: 13 additions & 3 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,9 +1232,19 @@ void avatar_action::reload( item &loc, bool prompt, bool empty )
use_loc = false;
}

// for holsters and ammo pouches try to reload any contained item
if( it->type->can_use( "holster" ) && !it->contents.empty() ) {
it = &it->contents.front();
if( it->is_holster() ) {
auto ptr = dynamic_cast<const holster_actor *>
( it->type->get_use( "holster" )->get_actor_ptr() );
if( static_cast<int>( it->contents.num_item_stacks() ) < ptr->multi ) {
item *loc = game_menus::inv::holster( u, *it );

if( !loc ) {
u.add_msg_if_player( _( "Never mind." ) );
return;
}
ptr->store( u, *it, loc->detach() );
return;
}
}

// for bandoliers we currently defer to iuse_actor methods
Expand Down
5 changes: 5 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11648,6 +11648,11 @@ int Character::hp_percentage() const

bool Character::can_reload( const item &it, const itype_id &ammo ) const
{
if( it.is_holster() ) {
const holster_actor *ptr = dynamic_cast<const holster_actor *>
( it.get_use( "holster" )->get_actor_ptr() );
return static_cast<int>( it.contents.num_item_stacks() ) < ptr->multi;
}
if( !it.is_reloadable_with( ammo ) ) {
return false;
}
Expand Down
13 changes: 9 additions & 4 deletions src/character_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "game.h"
#include "handle_liquid.h"
#include "itype.h"
#include "iuse_actor.h"
#include "make_static.h"
#include "map_iterator.h"
#include "map_selector.h"
Expand Down Expand Up @@ -1027,7 +1028,7 @@ item_reload_option select_ammo( const Character &who, item &base, bool prompt,
const bool ammo_match_found = list_ammo( who, base, ammo_list, include_empty_mags,
include_potential );

if( ammo_list.empty() ) {
if( ammo_list.empty() && !base.is_holster() ) {
if( !who.is_npc() ) {
if( !base.is_magazine() && !base.magazine_integral() && !base.magazine_current() ) {
who.add_msg_if_player( m_info, _( "You need a compatible magazine to reload the %s!" ),
Expand Down Expand Up @@ -1202,9 +1203,6 @@ std::vector<item *> find_reloadables( Character &who )
std::vector<item *> reloadables;

who.visit_items( [&]( item * node ) {
if( node->is_holster() ) {
return VisitResponse::NEXT;
}
bool reloadable = false;
if( node->is_gun() && !node->magazine_compatible().empty() ) {
reloadable = node->magazine_current() == nullptr ||
Expand All @@ -1214,6 +1212,13 @@ std::vector<item *> find_reloadables( Character &who )
( node->is_gun() && node->magazine_integral() ) ) &&
node->ammo_remaining() < node->ammo_capacity();
}
if( node->is_holster() ) {
const holster_actor *ptr = dynamic_cast<const holster_actor *>
( node->get_use( "holster" )->get_actor_ptr() );
if( static_cast<int>( node->contents.num_item_stacks() ) < ptr->multi ) {
reloadable = true;
}
}
if( reloadable ) {
reloadables.push_back( node );
}
Expand Down
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10052,7 +10052,7 @@ bool item::is_reloadable() const
if( has_flag( flag_NO_RELOAD ) && !has_flag( flag_VEHICLE ) ) {
return false; // turrets ignore NO_RELOAD flag

} else if( is_bandolier() ) {
} else if( is_bandolier() || is_holster() ) {
return true;

} else if( is_container() ) {
Expand Down

0 comments on commit 902302b

Please sign in to comment.