]> git.localhorst.tv Git - l2e.git/blobdiff - src/common/Inventory.cpp
use stable_sort for sorting inventory
[l2e.git] / src / common / Inventory.cpp
index 6a6af81f3b52fe3dd0f94875cde38f00689f016b..793a0597f372f04b5668cff2777c9586ba15ce39 100644 (file)
@@ -1,10 +1,3 @@
-/*
- * Inventory.cpp
- *
- *  Created on: Aug 9, 2012
- *      Author: holy
- */
-
 #include "Inventory.h"
 
 #include "Item.h"
@@ -14,7 +7,8 @@
 
 namespace common {
 
-Inventory::Inventory() {
+Inventory::Inventory()
+: scenarioEnd(0) {
 
 }
 
@@ -53,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)) {
@@ -67,8 +65,19 @@ bool Inventory::SloteFree(int offset) const {
 }
 
 
+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);
+       std::stable_sort(entries, entries + 96, Entry::Less);
 }
 
 bool Inventory::Entry::Less(const Entry &lhs, const Entry &rhs) {
@@ -83,4 +92,8 @@ bool Inventory::Entry::Less(const Entry &lhs, const Entry &rhs) {
        }
 }
 
+void Inventory::SwapEntriesAt(int lhs, int rhs) {
+       std::swap(entries[lhs], entries[rhs]);
+}
+
 }