Skip to content

Commit 11ee416

Browse files
authored
Merge pull request #82324 from sparr/dedupe_follower_list
Dedupe follower list creation
2 parents 897b765 + a401309 commit 11ee416

File tree

6 files changed

+28
-40
lines changed

6 files changed

+28
-40
lines changed

src/faction.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "localized_comparator.h"
2727
#include "map.h"
2828
#include "map_scale_constants.h"
29-
#include "memory_fast.h"
3029
#include "mission_companion.h"
3130
#include "mtype.h"
3231
#include "npc.h"
@@ -1068,16 +1067,7 @@ void faction_manager::display() const
10681067

10691068
avatar &player_character = get_avatar();
10701069
while( true ) {
1071-
// create a list of NPCs, visible and the ones on overmapbuffer
1072-
followers.clear();
1073-
for( const character_id &elem : g->get_follower_list() ) {
1074-
shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
1075-
if( !npc_to_get ) {
1076-
continue;
1077-
}
1078-
npc *npc_to_add = npc_to_get.get();
1079-
followers.push_back( npc_to_add );
1080-
}
1070+
overmap_buffer.populate_followers_vec( followers );
10811071
valfac.clear();
10821072
for( const auto &elem : g->faction_manager_ptr->all() ) {
10831073
if( elem.second.known_by_u && elem.second.id != faction_your_followers ) {

src/faction_camp.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,15 +2309,7 @@ void basecamp::worker_assignment_ui()
23092309

23102310
while( true ) {
23112311
// create a list of npcs stationed at this camp
2312-
followers.clear();
2313-
for( const character_id &elem : g->get_follower_list() ) {
2314-
shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
2315-
if( !npc_to_get || !npc_to_get->is_following() || npc_to_get->is_hallucination() ) {
2316-
continue;
2317-
}
2318-
npc *npc_to_add = npc_to_get.get();
2319-
followers.push_back( npc_to_add );
2320-
}
2312+
overmap_buffer.populate_followers_vec( followers, true, true );
23212313
cur_npc = nullptr;
23222314
if( !followers.empty() ) {
23232315
cur_npc = followers[selection];

src/npcmove.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,14 +3944,7 @@ bool npc::would_take_that( const item &it, const tripoint_bub_ms &p )
39443944
return false;
39453945
}
39463946
std::vector<npc *> followers;
3947-
for( const character_id &elem : g->get_follower_list() ) {
3948-
shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
3949-
if( !npc_to_get ) {
3950-
continue;
3951-
}
3952-
npc *npc_to_add = npc_to_get.get();
3953-
followers.push_back( npc_to_add );
3954-
}
3947+
overmap_buffer.populate_followers_vec( followers );
39553948
for( npc *&elem : followers ) {
39563949
if( elem->sees( here, this->pos_bub( here ) ) || elem->sees( here, p ) ) {
39573950
return false;

src/overmap_ui.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
#include "calendar.h"
2424
#include "cata_assert.h"
2525
#include "cata_variant.h"
26-
#include "character_id.h"
2726
#include "debug.h"
2827
#include "enum_conversions.h"
2928
#include "input_enums.h"
3029
#include "mapdata.h"
3130
#include "mapgen_parameter.h"
3231
#include "mapgendata.h"
33-
#include "memory_fast.h"
3432
#include "monster.h"
3533
#include "simple_pathfinding.h"
3634
#include "translation.h"
@@ -700,15 +698,7 @@ static void draw_ascii( const catacurses::window &w, overmap_draw_data_t &data )
700698
}
701699
}
702700
std::vector<npc *> followers;
703-
// get friendly followers
704-
for( const character_id &elem : g->get_follower_list() ) {
705-
shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
706-
if( !npc_to_get ) {
707-
continue;
708-
}
709-
npc *npc_to_add = npc_to_get.get();
710-
followers.push_back( npc_to_add );
711-
}
701+
overmap_buffer.populate_followers_vec( followers );
712702
if( !display_path.empty() ) {
713703
for( const tripoint_abs_omt &elem : display_path ) {
714704
npc_path_route.insert( elem );

src/overmapbuffer.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,22 @@ shared_ptr_fast<npc> overmapbuffer::find_npc( character_id id )
14201420
return nullptr;
14211421
}
14221422

1423+
void overmapbuffer::populate_followers_vec( std::vector<npc *> &followers,
1424+
bool only_following, bool ignore_hallu ) const
1425+
{
1426+
followers.clear();
1427+
for( const character_id &elem : g->get_follower_list() ) {
1428+
shared_ptr_fast<npc> npc_to_get = overmap_buffer.find_npc( elem );
1429+
if( !npc_to_get ||
1430+
( only_following && !npc_to_get->is_following() ) ||
1431+
( ignore_hallu && npc_to_get->is_hallucination() ) ) {
1432+
continue;
1433+
}
1434+
npc *npc_to_add = npc_to_get.get();
1435+
followers.push_back( npc_to_add );
1436+
}
1437+
}
1438+
14231439
void overmapbuffer::foreach_npc( const std::function<void( npc & )> &callback )
14241440
{
14251441
for( auto &it : overmaps ) {
@@ -1488,7 +1504,8 @@ std::vector<overmap *> overmapbuffer::get_overmaps_near( const tripoint_abs_sm &
14881504
return get_overmaps_near( location.xy(), radius );
14891505
}
14901506

1491-
std::vector<overmap *> overmapbuffer::get_overmaps_near( const point_abs_sm &p, const int radius )
1507+
std::vector<overmap *> overmapbuffer::get_overmaps_near( const point_abs_sm &p,
1508+
const int radius )
14921509
{
14931510
// Grab the corners of a square around the target location at distance radius.
14941511
// Convert to overmap coordinates and iterate from the minimum to the maximum.

src/overmapbuffer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ class overmapbuffer
318318
* Searches all loaded overmaps.
319319
*/
320320
shared_ptr_fast<npc> find_npc( character_id id );
321+
/**
322+
* Clear and fill a vector with NPCs who are your followers.
323+
* Optionally only include is_following() or exclude is_hallucination()
324+
*/
325+
void populate_followers_vec( std::vector<npc *> &followers, bool only_following = false,
326+
bool ignore_hallu = false ) const;
321327
void foreach_npc( const std::function<void( npc & )> &callback );
322328
shared_ptr_fast<npc> find_npc_by_unique_id( const std::string &unique_id );
323329
/**

0 commit comments

Comments
 (0)