Skip to content

Commit

Permalink
clear up item ownership for dead factions
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwb committed Feb 25, 2020
1 parent dbe55a1 commit f51e53c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,17 @@ void npc::die( Creature *nkiller )
elem->remove_owner();
elem->remove_old_owner();
}
// broadcast a signal to any items this NPC may have dropped nearby to clear their ownership too
// this will also validate when the items are interacted with
// but may as well solve what we can now.
for( const tripoint tri_elem : g->m.points_in_radius( pos(), 60 ) ) {
for( item &elem : g->m.i_at( tri_elem ) ) {
if( !elem.get_owner().is_null() && !g->faction_manager_ptr->get( elem.get_owner(), false ) ) {
elem.remove_owner();
elem.remove_old_owner();
}
}
}
}
my_fac->remove_member( getID() );
}
Expand Down
5 changes: 5 additions & 0 deletions src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from )
std::vector<std::list<item_stack::iterator>> stacked_here;
for( item_stack::iterator it : here ) {
bool found_stack = false;
// an NPC may have dropped an item, then later died, the faction is now invalid.
if( !it->get_owner().is_null() && !g->faction_manager_ptr->get( it->get_owner(), false ) ) {
it->remove_owner();
it->remove_old_owner();
}
for( std::list<item_stack::iterator> &stack : stacked_here ) {
if( stack.front()->display_stacked_with( *it ) ) {
stack.push_back( it );
Expand Down

0 comments on commit f51e53c

Please sign in to comment.