summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/ItemGrid.cpp47
-rw-r--r--source/ItemGrid.h6
2 files changed, 53 insertions, 0 deletions
diff --git a/source/ItemGrid.cpp b/source/ItemGrid.cpp
index 0495105f2..5a432e80f 100644
--- a/source/ItemGrid.cpp
+++ b/source/ItemGrid.cpp
@@ -355,6 +355,53 @@ int cItemGrid::ChangeSlotCount(int a_X, int a_Y, int a_AddToCount)
+cItem cItemGrid::RemoveOneItem(int a_SlotNum)
+{
+ if ((a_SlotNum < 0) || (a_SlotNum >= m_NumSlots))
+ {
+ LOGWARNING("%s: Invalid slot number %d out of %d slots, ignoring the call, returning empty item",
+ __FUNCTION__, a_SlotNum, m_NumSlots
+ );
+ return cItem();
+ }
+
+ // If the slot is empty, return an empty item
+ if (m_Slots[a_SlotNum].IsEmpty())
+ {
+ return cItem();
+ }
+
+ // Make a copy of the item in slot, set count to 1 and remove one from the slot
+ cItem res = m_Slots[a_SlotNum];
+ res.m_ItemCount = 1;
+ m_Slots[a_SlotNum].m_ItemCount -= 1;
+
+ // Emptying the slot correctly if appropriate
+ if (m_Slots[a_SlotNum].m_ItemCount == 0)
+ {
+ m_Slots[a_SlotNum].Empty();
+ }
+
+ // Notify everyone of the change
+ TriggerListeners(a_SlotNum);
+
+ // Return the stored one item
+ return res;
+}
+
+
+
+
+
+cItem cItemGrid::RemoveOneItem(int a_X, int a_Y)
+{
+ return RemoveOneItem(GetSlotNum(a_X, a_Y));
+}
+
+
+
+
+
int cItemGrid::HowManyItems(const cItem & a_Item)
{
int res = 0;
diff --git a/source/ItemGrid.h b/source/ItemGrid.h
index 22d64f076..82898537c 100644
--- a/source/ItemGrid.h
+++ b/source/ItemGrid.h
@@ -98,6 +98,12 @@ public:
*/
int ChangeSlotCount(int a_X, int a_Y, int a_AddToCount);
+ /// Removes one item from the specified slot, and returns it. If the slot was empty, returns an empty item
+ cItem RemoveOneItem(int a_SlotNum);
+
+ /// Removes one item from the specified slot, and returns it. If the slot was empty, returns an empty item
+ cItem RemoveOneItem(int a_X, int a_Y);
+
/// Returns the number of items of type a_Item that are stored
int HowManyItems(const cItem & a_Item);