diff options
author | Lloyd Bryant <lloyd_bryant@netzero.net> | 2008-09-12 17:12:24 +0000 |
---|---|---|
committer | Lloyd Bryant <lloyd_bryant@netzero.net> | 2008-09-12 17:12:24 +0000 |
commit | 8551f4a5c5e1feddc4f2868488bdefeae85aa26d (patch) | |
tree | 39b91c9d7124c1c03e954ceb9b3434adcaf022ce /src/inventory.cpp | |
parent | a9595f435664df56948ae70e954cf72143ddcfa1 (diff) | |
download | mana-8551f4a5c5e1feddc4f2868488bdefeae85aa26d.tar.gz mana-8551f4a5c5e1feddc4f2868488bdefeae85aa26d.tar.bz2 mana-8551f4a5c5e1feddc4f2868488bdefeae85aa26d.tar.xz mana-8551f4a5c5e1feddc4f2868488bdefeae85aa26d.zip |
Fixed /where, added /cast for heal and gather, some changes to inventory to support storage
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 20958c44..0b1b9613 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -36,15 +36,16 @@ struct SlotUsed : public std::unary_function<Item*, bool> } }; -Inventory::Inventory() +Inventory::Inventory(int size): + mSize(size) { - mItems = new Item*[INVENTORY_SIZE]; - std::fill_n(mItems, INVENTORY_SIZE, (Item*) 0); + mItems = new Item*[mSize]; + std::fill_n(mItems, mSize, (Item*) 0); } Inventory::~Inventory() { - for (int i = 0; i < INVENTORY_SIZE; i++) + for (int i = 0; i < mSize; i++) delete mItems[i]; delete [] mItems; @@ -52,7 +53,7 @@ Inventory::~Inventory() Item* Inventory::getItem(int index) const { - if (index < 0 || index >= INVENTORY_SIZE) + if (index < 0 || index >= mSize) return 0; return mItems[index]; @@ -60,7 +61,7 @@ Item* Inventory::getItem(int index) const Item* Inventory::findItem(int itemId) const { - for (int i = 0; i < INVENTORY_SIZE; i++) + for (int i = 0; i < mSize; i++) { if (mItems[i] && mItems[i]->getId() == itemId) return mItems[i]; @@ -75,7 +76,7 @@ void Inventory::addItem(int id, int quantity, bool equipment) void Inventory::setItem(int index, int id, int quantity, bool equipment) { - if (index < 0 || index >= INVENTORY_SIZE) { + if (index < 0 || index >= mSize) { logger->log("Warning: invalid inventory index: %d", index); return; } @@ -95,14 +96,14 @@ void Inventory::setItem(int index, int id, int quantity, bool equipment) void Inventory::clear() { - for (int i = 0; i < INVENTORY_SIZE; i++) { + for (int i = 0; i < mSize; i++) { removeItemAt(i); } } void Inventory::removeItem(int id) { - for (int i = 0; i < INVENTORY_SIZE; i++) { + for (int i = 0; i < mSize; i++) { if (mItems[i] && mItems[i]->getId() == id) { removeItemAt(i); } @@ -117,7 +118,7 @@ void Inventory::removeItemAt(int index) bool Inventory::contains(Item *item) const { - for (int i = 0; i < INVENTORY_SIZE; i++) { + for (int i = 0; i < mSize; i++) { if (mItems[i] && mItems[i]->getId() == item->getId()) { return true; } @@ -128,19 +129,19 @@ bool Inventory::contains(Item *item) const int Inventory::getFreeSlot() { - Item **i = std::find_if(mItems + 2, mItems + INVENTORY_SIZE, + Item **i = std::find_if(mItems + 2, mItems + mSize, std::not1(SlotUsed())); - return (i == mItems + INVENTORY_SIZE) ? -1 : (i - mItems); + return (i == mItems + mSize) ? -1 : (i - mItems); } int Inventory::getNumberOfSlotsUsed() { - return count_if(mItems, mItems + INVENTORY_SIZE, SlotUsed()); + return count_if(mItems, mItems + mSize, SlotUsed()); } int Inventory::getLastUsedSlot() { - for (int i = INVENTORY_SIZE - 1; i >= 0; i--) { + for (int i = mSize - 1; i >= 0; i--) { if (SlotUsed()(mItems[i])) { return i; } |