void Inventory::addItem(PItem item) { itemsCache.push_back(item.get()); for (ItemIndex ind : ENUM_ALL(ItemIndex)) if (indexes[ind] && getIndexPredicate(ind)(item.get())) indexes[ind]->push_back(item.get()); items.push_back(std::move(item)); }
PItem Inventory::removeItem(Item* itemRef) { int ind = -1; for (int i : All(items)) if (items[i].get() == itemRef) { ind = i; break; } CHECK(ind > -1) << "Tried to remove unknown item."; PItem item = std::move(items[ind]); items.erase(items.begin() + ind); removeElement(itemsCache, itemRef); for (ItemIndex ind : ENUM_ALL(ItemIndex)) if (indexes[ind] && getIndexPredicate(ind)(item.get())) removeElement(*indexes[ind], itemRef); return item; }
void Inventory::addItem(PItem item) { itemsCache.push_back(item.get()); items.push_back(move(item)); }