Skip to content

Commit

Permalink
Merge pull request #35509 from davidpwbrown/camp_form_fix
Browse files Browse the repository at this point in the history
Fix basecamp storage zone inventory
  • Loading branch information
ZhilkinSerg authored Nov 16, 2019
2 parents e8ab102 + fbbe0bb commit 3766dc6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tripoint> &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<tripoint> 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
Expand Down
19 changes: 17 additions & 2 deletions src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tripoint> &zone_pts, const Character *pl,
bool assign_invlet )
{
std::vector<tripoint> 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 )
Expand All @@ -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<tripoint> 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();
Expand Down Expand Up @@ -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<item> inventory::reduce_stack( const int position, const int quantity )
Expand Down
6 changes: 6 additions & 0 deletions src/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include <list>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <utility>
#include <vector>
#include <set>
#include <limits>
#include <functional>
#include <map>
Expand Down Expand Up @@ -125,12 +127,16 @@ class inventory : public visitable<inventory>
* the player's worn items / weapon
*/
void restack( player &p );
void form_from_zone( map &m, std::unordered_set<tripoint> &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<tripoint> 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.
Expand Down

0 comments on commit 3766dc6

Please sign in to comment.