X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcommon%2FInventory.cpp;h=e279ac5856d0b608a1866fd97a3e26193f16286a;hb=ec25171b0b27999eb126e2144dae1e35f271b945;hp=d118f2187daeb9bb28f84d2ccd48882bad6c8c58;hpb=341371f1ac26af555407bf9fe9b78794297a385b;p=l2e.git diff --git a/src/common/Inventory.cpp b/src/common/Inventory.cpp index d118f21..e279ac5 100644 --- a/src/common/Inventory.cpp +++ b/src/common/Inventory.cpp @@ -1,15 +1,14 @@ -/* - * Inventory.cpp - * - * Created on: Aug 9, 2012 - * Author: holy - */ - #include "Inventory.h" +#include "Item.h" + +#include + + namespace common { -Inventory::Inventory() { +Inventory::Inventory() +: scenarioEnd(0) { } @@ -48,6 +47,10 @@ void Inventory::Remove(const Item *item, int count) { } } +void Inventory::RemoveAll(const Item *item) { + Remove(item, 255); +} + Inventory::Entry *Inventory::FindItem(const Item *item) { for (int i(0); i < MaxItems(); ++i) { if (item == ItemAt(i)) { @@ -61,4 +64,36 @@ bool Inventory::SloteFree(int offset) const { return !ItemAt(offset); } + +bool Inventory::AddScenarioItem(const Item *i) { + if (scenarioEnd < MaxScenarioItems()) { + scenario[scenarioEnd] = i; + ++scenarioEnd; + return true; + } else { + return false; + } +} + + +void Inventory::Sort() { + std::sort(entries, entries + 96, Entry::Less); +} + +bool Inventory::Entry::Less(const Entry &lhs, const Entry &rhs) { + if (lhs.item) { + if (rhs.item) { + return Item::Less(*lhs.item, *rhs.item); + } else { + return true; + } + } else { + return false; + } +} + +void Inventory::SwapEntriesAt(int lhs, int rhs) { + std::swap(entries[lhs], entries[rhs]); +} + }