-/*
- * Inventory.cpp
- *
- * Created on: Aug 9, 2012
- * Author: holy
- */
-
#include "Inventory.h"
+#include "Item.h"
+
+#include <algorithm>
+
+
namespace common {
-Inventory::Inventory() {
+Inventory::Inventory()
+: scenarioEnd(0) {
}
}
}
+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)) {
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::stable_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]);
+}
+
}