]> git.localhorst.tv Git - l2e.git/blobdiff - src/common/Inventory.cpp
added Sort function to Inventory
[l2e.git] / src / common / Inventory.cpp
index d118f2187daeb9bb28f84d2ccd48882bad6c8c58..6a6af81f3b52fe3dd0f94875cde38f00689f016b 100644 (file)
@@ -7,6 +7,11 @@
 
 #include "Inventory.h"
 
+#include "Item.h"
+
+#include <algorithm>
+
+
 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;
+       }
+}
+
 }