aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--queen/logic.cpp76
-rw-r--r--queen/logic.h4
-rw-r--r--queen/xref.txt8
3 files changed, 81 insertions, 7 deletions
diff --git a/queen/logic.cpp b/queen/logic.cpp
index 50cd559c6f..336ede83ba 100644
--- a/queen/logic.cpp
+++ b/queen/logic.cpp
@@ -2040,19 +2040,89 @@ void Logic::inventoryRefresh() {
update();
}
+int16 Logic::previousInventoryItem(int16 start) const {
+ int i;
+ for (i = start - 1; i >= 1; i--)
+ if (_itemData[i].name > 0)
+ return i;
+ for (i = _numItems; i > start; i--)
+ if (_itemData[i].name > 0)
+ return i;
+
+ return 0; //nothing found
+}
+
+int16 Logic::nextInventoryItem(int16 start) const {
+ int i;
+ for (i = start + 1; i < _numItems; i++)
+ if (_itemData[i].name > 0)
+ return i;
+ for (i = 1; i < start; i++)
+ if (_itemData[i].name > 0)
+ return i;
+
+ return 0; //nothing found
+}
+
+void Logic::removeDuplicateItems() {
+ for (int i = 0; i < 4; i++)
+ for (int j = i + 1; j < 4; j++)
+ if (_inventoryItem[i] == _inventoryItem[j])
+ _inventoryItem[j] = 0;
+}
+
+uint16 Logic::numItemsInventory() const {
+ uint16 count = 0;
+ for (int i = 1; i < _numItems; i++)
+ if (_itemData[i].name > 0)
+ count++;
+
+ return count;
+}
void Logic::inventoryInsertItem(uint16 itemNum, bool refresh) {
- warning("Logic::inventoryInsertItem() unimplemented");
+ int16 item = _inventoryItem[0] = (int16)itemNum;
+ _itemData[itemNum].name = abs(_itemData[itemNum].name); //set visible
+ for (int i = 1; i < 4; i++) {
+ item = nextInventoryItem(item);
+ _inventoryItem[i] = item;
+ removeDuplicateItems();
+ }
+
+ if (refresh)
+ inventoryRefresh();
}
void Logic::inventoryDeleteItem(uint16 itemNum, bool refresh) {
- warning("Logic::inventoryDeleteItem() unimplemented");
+ int16 item = (int16)itemNum;
+ _itemData[itemNum].name = -abs(_itemData[itemNum].name); //set invisible
+ for (int i = 0; i < 4; i++) {
+ item = nextInventoryItem(item);
+ _inventoryItem[i] = item;
+ removeDuplicateItems();
+ }
+
+ if (refresh)
+ inventoryRefresh();
}
void Logic::inventoryScroll(uint16 count, bool up) {
- warning("Logic::inventoryScroll() unimplemented");
+ if (!(numItemsInventory() > 4))
+ return;
+
+ if (up) {
+ for (int i = 0; i < 3; i++)
+ _inventoryItem[i] = _inventoryItem[i + 1];
+ _inventoryItem[3] = nextInventoryItem(_inventoryItem[3]);
+ } else {
+ for (int i = 3; i > 0; i--)
+ _inventoryItem[i] = _inventoryItem[i - 1];
+ _inventoryItem[0] = previousInventoryItem(_inventoryItem[0]);
+ }
+
+ inventoryRefresh();
}
diff --git a/queen/logic.h b/queen/logic.h
index 6d94edff1d..82b6e974f5 100644
--- a/queen/logic.h
+++ b/queen/logic.h
@@ -256,6 +256,10 @@ public:
void inventorySetup();
uint16 findInventoryItem(int invSlot) const;
void inventoryRefresh();
+ int16 previousInventoryItem(int16 start) const;
+ int16 nextInventoryItem(int16 start) const;
+ void removeDuplicateItems();
+ uint16 numItemsInventory() const;
void inventoryInsertItem(uint16 itemNum, bool refresh = true);
void inventoryDeleteItem(uint16 itemNum, bool refresh = true);
void inventoryScroll(uint16 count, bool up);
diff --git a/queen/xref.txt b/queen/xref.txt
index b5a89406bb..06b80a75af 100644
--- a/queen/xref.txt
+++ b/queen/xref.txt
@@ -167,11 +167,11 @@ no_check_keys Input::_noCheckKeys
INVENTORY
=========
-DEL_ITEM_NUM() Logic::inventoryDeleteItem // TODO
-INS_ITEM_NUM() Logic::inventoryInsertItem // TODO
-INVDWN() Logic::inventoryScroll // TODO
+DEL_ITEM_NUM() Logic::inventoryDeleteItem
+INS_ITEM_NUM() Logic::inventoryInsertItem
+INVDWN() Logic::inventoryScroll
INVENTORY() Logic::inventoryRefresh
-INVUP() Logic::inventoryScroll // TODO
+INVUP() Logic::inventoryScroll
SETUP_ITEMS() Logic::inventorySetup
-
INV1,INV2,INV3,INV4 Logic::_inventoryItem