X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcommon%2FInventory.cpp;h=6a6af81f3b52fe3dd0f94875cde38f00689f016b;hb=89aa9fbc77d72e98549bc3aabd7ced7cd8949bdc;hp=d118f2187daeb9bb28f84d2ccd48882bad6c8c58;hpb=cc3905e6ddd9536139cb5d613c3e2d90c83b60fc;p=l2e.git diff --git a/src/common/Inventory.cpp b/src/common/Inventory.cpp index d118f21..6a6af81 100644 --- a/src/common/Inventory.cpp +++ b/src/common/Inventory.cpp @@ -7,6 +7,11 @@ #include "Inventory.h" +#include "Item.h" + +#include + + namespace common { Inventory::Inventory() { @@ -61,4 +66,21 @@ bool Inventory::SloteFree(int offset) const { return !ItemAt(offset); } + +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; + } +} + }