summaryrefslogtreecommitdiff
path: root/src/inventory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 11c52421..d9bd79f8 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -30,7 +30,7 @@
struct SlotUsed : public std::unary_function<Item, bool>
{
bool operator()(const Item &item) const {
- return (item.getId() != -1 && item.getQuantity() > 0);
+ return (item.getId() && item.getQuantity());
}
};
@@ -72,8 +72,7 @@ void Inventory::addItem(int index, int id, int quantity)
void Inventory::clear()
{
for (int i = 0; i < INVENTORY_SIZE; i++) {
- mItems[i].setId(-1);
- mItems[i].setQuantity(0);
+ removeItemIndex(i);
}
}
@@ -81,12 +80,17 @@ void Inventory::removeItem(int id)
{
for (int i = 0; i < INVENTORY_SIZE; i++) {
if (mItems[i].getId() == id) {
- mItems[i].setId(-1);
- mItems[i].setQuantity(0);
+ removeItemIndex(i);
}
}
}
+void Inventory::removeItemIndex(int index)
+{
+ mItems[index].setId(0);
+ mItems[index].setQuantity(0);
+}
+
bool Inventory::contains(Item *item)
{
for (int i = 0; i < INVENTORY_SIZE; i++) {