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 items inside items carried by player being processed multiple times per turn #40875

Merged
merged 5 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,20 @@ std::vector<item_location> Character::all_items_loc()
return ret;
}

std::vector<item_location> Character::top_items_loc()
{
std::vector<item_location> ret;
if( has_weapon() ) {
item_location weap_loc( *this, &weapon );
ret.push_back( weap_loc );
}
for( item &worn_it : worn ) {
item_location worn_loc( *this, &worn_it );
ret.push_back( worn_loc );
}
return ret;
}

item *Character::invlet_to_item( const int linvlet )
{
// Invlets may come from curses, which may also return any kind of key codes, those being
Expand Down
2 changes: 2 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,8 @@ class Character : public Creature, public visitable<Character>
// returns a list of all item_location the character has, including items contained in other items.
// only for CONTAINER pocket type; does not look for magazines
std::vector<item_location> all_items_loc();
// Returns list of all the top level item_lodation the character has. Includes worn and held items.
std::vector<item_location> top_items_loc();
/** Return the item pointer of the item with given invlet, return nullptr if
* the player does not have such an item with that invlet. Don't use this on npcs.
* Only use the invlet in the user interface, otherwise always use the item position. */
Expand Down
7 changes: 1 addition & 6 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ void player::process_items()
}

std::vector<item_location> removed_items;
for( item_location it : all_items_loc() ) {
for( item_location it : top_items_loc() ) {
if( !it ) {
continue;
}
Expand All @@ -1777,11 +1777,6 @@ void player::process_items()
removed.remove_item();
}

// worn items
remove_worn_items_with( [this]( item & itm ) {
return itm.needs_processing() && itm.process( this, pos(), false );
} );

// Active item processing done, now we're recharging.
item *cloak = nullptr;
item *power_armor = nullptr;
Expand Down