10 : id(item::
Id::Unknown)
19 for (
const Item& i : items) {
26 for (
const Item& i : items) {
33 result.reserve(items.size());
34 for (
const Item& i : items) { result.push_back(i); }
38 const unsigned int i = find(
id);
39 return i < items.size() ? items[i].qty : 0;
45 const unsigned int i = find(
id);
46 if (i < items.size()) { items[i].qty += qty; }
48 items.emplace_back(
id, qty);
53 const unsigned int i = find(
id);
54 if (i < items.size()) {
55 if (items[i].qty >= qty) {
57 if (items[i].qty == 0) items.erase(items.begin() + i);
66 unsigned int Bag::find(
item::Id id)
const {
67 for (
unsigned int i = 0; i < items.size(); ++i) {
68 if (items[i].
id ==
id)
return i;
Type
The type classification of an item. This is used to determine when an item may be used and how to use...
Category
Represents a category that an item can belong to. Used for bag sorting.
Id
Represents an item in its simplist form.
Core classes and functionality for both the editor and game.
static Category getCategory(Id item)
Returns the category of the given item.
static Type getType(Id item)
Returns the type of the given item.
void getAll(std::vector< Item > &result) const
Returns all owned items.
void getByCategory(item::Category category, std::vector< Item > &result) const
Returns the set of owned items in the given category.
bool removeItem(item::Id item, unsigned int qty=1)
Removes the given item from the bag.
void addItem(item::Id item, unsigned int qty=1)
Adds the given item to the bag.
void getByType(item::Type type, std::vector< Item > &result) const
Returns the set of owned items of the given type.
unsigned int itemCount(item::Id item) const
Returns the number of the given item owned.
void clear()
Removes all items.
bool hasItem(item::Id item) const
Returns true if at least one of the given items is owned.
Simple struct representing a set of items in the bag.
Item()
Construct an empty item.