Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPC wielding items from within holsters and the like #36506

Merged
merged 2 commits into from
Dec 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,20 @@ bool npc::wield( item &it )

// check if the item is in a holster
int position = inv.position_by_item( &it );
item &holster = inv.find_item( position );
if( holster.tname() != it.tname() && holster.is_holster() && !holster.contents.empty() ) {
invoke_item( &holster );
if( position != INT_MIN ) {
item &maybe_holster = inv.find_item( position );
assert( !maybe_holster.is_null() );
if( &maybe_holster != &it && maybe_holster.is_holster() ) {
assert( !maybe_holster.contents.empty() );
const size_t old_size = maybe_holster.contents.size();
invoke_item( &maybe_holster );
// @TODO change invoke_item to somehow report this change
// Hacky: test whether wielding the item from the holster has been done.
// (Wielding may be prevented by various reasons: see player::wield_contained)
if( old_size != maybe_holster.contents.size() ) {
return true;
}
}
}

moves -= 15;
Expand Down