diff --git a/src/basecamp.cpp b/src/basecamp.cpp index d744a24c6f852..a62e090d03ad1 100644 --- a/src/basecamp.cpp +++ b/src/basecamp.cpp @@ -621,12 +621,8 @@ void basecamp::form_crafting_inventory( map &target_map ) mgr.cache_vzones(); } if( mgr.has_near( z_camp_storage, dump_spot, 60 ) ) { - const std::unordered_set &src_set = mgr.get_near( z_camp_storage, dump_spot, 60 ); - for( const tripoint &src : src_set ) { - for( const item &it : target_map.i_at( target_map.getlocal( src ) ) ) { - _inv.add_item( it ); - } - } + std::unordered_set src_set = mgr.get_near( z_camp_storage, dump_spot, 60 ); + _inv.form_from_zone( target_map, src_set, nullptr, false ); } /* * something of a hack: add the resources we know the camp has diff --git a/src/inventory.cpp b/src/inventory.cpp index 441ab9eed1570..a56efa0e15889 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -398,6 +398,16 @@ void inventory::form_from_map( const tripoint &origin, int range, const Characte form_from_map( g->m, origin, range, pl, assign_invlet, clear_path ); } +void inventory::form_from_zone( map &m, std::unordered_set &zone_pts, const Character *pl, + bool assign_invlet ) +{ + std::vector pts; + for( const tripoint &elem : zone_pts ) { + pts.push_back( m.getlocal( elem ) ); + } + form_from_map( m, pts, pl, assign_invlet ); +} + void inventory::form_from_map( map &m, const tripoint &origin, int range, const Character *pl, bool assign_invlet, bool clear_path ) @@ -414,9 +424,14 @@ void inventory::form_from_map( map &m, const tripoint &origin, int range, const reachable_pts.emplace_back( p ); } } + form_from_map( m, reachable_pts, pl, assign_invlet ); +} +void inventory::form_from_map( map &m, std::vector pts, const Character *pl, + bool assign_invlet ) +{ items.clear(); - for( const tripoint &p : reachable_pts ) { + for( const tripoint &p : pts ) { if( m.has_furn( p ) ) { const furn_t &f = m.furn( p ).obj(); const itype *type = f.crafting_pseudo_item_type(); @@ -583,7 +598,7 @@ void inventory::form_from_map( map &m, const tripoint &origin, int range, const add_item( chemistry_set ); } } - reachable_pts.clear(); + pts.clear(); } std::list inventory::reduce_stack( const int position, const int quantity ) diff --git a/src/inventory.h b/src/inventory.h index 308a40a3ab452..b0ca34c60324d 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -7,9 +7,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -125,12 +127,16 @@ class inventory : public visitable * the player's worn items / weapon */ void restack( player &p ); + void form_from_zone( map &m, std::unordered_set &zone_pts, const Character *pl = nullptr, + bool assign_invlet = true ); void form_from_map( const tripoint &origin, int range, const Character *pl = nullptr, bool assign_invlet = true, bool clear_path = true ); void form_from_map( map &m, const tripoint &origin, int range, const Character *pl = nullptr, bool assign_invlet = true, bool clear_path = true ); + void form_from_map( map &m, std::vector pts, const Character *pl, + bool assign_invlet = true ); /** * Remove a specific item from the inventory. The item is compared * by pointer. Contents of the item are removed as well.