Skip to content

Commit

Permalink
Use the global null item reference function in inventory
Browse files Browse the repository at this point in the history
Instead of keeping an `item` instance for that purpose only.
  • Loading branch information
BevapDin committed Apr 8, 2018
1 parent 4c1e7f3 commit 063f797
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ bool invlet_wrapper::valid( const long invlet ) const
}

inventory::inventory()
: nullitem()
, nullstack()
: nullstack()
, invlet_cache()
, items()
{
Expand Down Expand Up @@ -579,7 +578,7 @@ void inventory::dump(std::vector<item *> &dest)
const item &inventory::find_item(int position) const
{
if (position < 0 || position >= (int)items.size()) {
return nullitem;
return null_item_reference();
}
invstack::const_iterator iter = items.begin();
for (int j = 0; j < position; ++j) {
Expand Down Expand Up @@ -718,7 +717,7 @@ bool inventory::has_enough_painkiller(int pain) const
item *inventory::most_appropriate_painkiller(int pain)
{
int difference = 9999;
item *ret = &nullitem;
item *ret = &null_item_reference();
for( auto &elem : items ) {
int diff = 9999;
itype_id type = elem.front().typeId();
Expand All @@ -744,7 +743,7 @@ item *inventory::most_appropriate_painkiller(int pain)

item *inventory::best_for_melee( player &p, double &best )
{
item *ret = &nullitem;
item *ret = &null_item_reference();
for( auto &elem : items ) {
auto score = p.melee_value( elem.front() );
if( score > best ) {
Expand All @@ -758,7 +757,7 @@ item *inventory::best_for_melee( player &p, double &best )

item *inventory::most_loaded_gun()
{
item *ret = &nullitem;
item *ret = &null_item_reference();
int max = 0;
for( auto &elem : items ) {
item &gun = elem.front();
Expand Down
1 change: 0 additions & 1 deletion src/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class inventory : public visitable<inventory>
void json_save_invcache( JsonOut &jsout ) const;
void json_save_items( JsonOut &jsout ) const;

item nullitem;
std::list<item> nullstack;

// Assigns an invlet if any remain. If none do, will assign ` if force is
Expand Down

0 comments on commit 063f797

Please sign in to comment.