Skip to content

Commit

Permalink
Check for duplicate entries in active_npc before inserting.
Browse files Browse the repository at this point in the history
  • Loading branch information
ipcyborg authored and Ramza13 committed Oct 16, 2019
1 parent 5733a0e commit 588654d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,14 @@ void game::load_npcs()
// uses submap coordinates
std::vector<std::shared_ptr<npc>> just_added;
for( const auto &temp : overmap_buffer.get_npcs_near_player( radius ) ) {
const character_id &id = temp->getID();
const auto found = std::find_if( active_npc.begin(), active_npc.end(),
[id]( const std::shared_ptr<npc> &n ) {
return n->getID() == id;
} );
if( found != active_npc.end() ) {
continue;
}
if( temp->is_active() ) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ class game
bool safe_mode_warning_logged;
bool bVMonsterLookFire;
character_id next_npc_id;
std::vector<std::shared_ptr<npc>> active_npc;
std::list<std::shared_ptr<npc>> active_npc;
int next_mission_id;
std::set<character_id> follower_ids; // Keep track of follower NPC IDs
int moves_since_last_save;
Expand Down
2 changes: 1 addition & 1 deletion src/overmapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ void overmapbuffer::insert_npc( const std::shared_ptr<npc> &who )
get( npc_om_pos ).insert_npc( who );
}

std::shared_ptr<npc> overmapbuffer::remove_npc( const character_id id )
std::shared_ptr<npc> overmapbuffer::remove_npc( const character_id &id )
{
for( auto &it : overmaps ) {
if( const auto p = it.second->erase_npc( id ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/overmapbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class overmapbuffer
* Find npc by id and if found, erase it from the npc list
* and return it ( or return nullptr if not found ).
*/
std::shared_ptr<npc> remove_npc( character_id id );
std::shared_ptr<npc> remove_npc( const character_id &id );
/**
* Adds the npc to an overmap ( based on the npcs current location )
* and stores it there. The overmap takes ownership of the pointer.
Expand Down

0 comments on commit 588654d

Please sign in to comment.