From 51b91befbd26b630cd2cecaec081edd03edfb5f3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 18 Jul 2014 23:11:59 +0200 Subject: Added RemoveItem() function to the player inventory. --- src/Inventory.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Inventory.cpp') diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 38d3c886d..5f7c24b60 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -151,6 +151,24 @@ int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a +int cInventory::RemoveItem(const cItem & a_ItemStack) +{ + int RemovedItems = m_HotbarSlots.RemoveItem(a_ItemStack); + + if (RemovedItems < a_ItemStack.m_ItemCount) + { + cItem Temp(a_ItemStack); + Temp.m_ItemCount -= RemovedItems; + RemovedItems += m_InventorySlots.RemoveItem(Temp); + } + + return RemovedItems; +} + + + + + bool cInventory::RemoveOneEquippedItem(void) { if (m_HotbarSlots.GetSlot(m_EquippedSlotNum).IsEmpty()) -- cgit v1.2.3 From 6be79575fd50e37ac275bd0cb9d16f9e51e8a225 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 20 Jul 2014 23:10:31 +0200 Subject: Style: Normalized spaces after if, for and while. --- src/Inventory.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Inventory.cpp') diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 5f7c24b60..93b2c8eee 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -500,15 +500,15 @@ int cInventory::ArmorSlotNumToEntityEquipmentID(short a_ArmorSlotNum) bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */ ) { // Fill already present stacks - if( a_Mode < 2 ) + if (a_Mode < 2 ) { int MaxStackSize = cItemHandler::GetItemHandler(a_Item.m_ItemType)->GetMaxStackSize(); - for(int i = 0; i < a_Size; i++) + for (int i = 0; i < a_Size; i++) { - if( m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType && m_Slots[i + a_Offset].m_ItemCount < MaxStackSize && m_Slots[i + a_Offset].m_ItemDamage == a_Item.m_ItemDamage ) + if (m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType && m_Slots[i + a_Offset].m_ItemCount < MaxStackSize && m_Slots[i + a_Offset].m_ItemDamage == a_Item.m_ItemDamage ) { int NumFree = MaxStackSize - m_Slots[i + a_Offset].m_ItemCount; - if( NumFree >= a_Item.m_ItemCount ) + if (NumFree >= a_Item.m_ItemCount ) { // printf("1. Adding %i items ( free: %i )\n", a_Item.m_ItemCount, NumFree ); @@ -528,12 +528,12 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, } } - if( a_Mode > 0 ) + if (a_Mode > 0 ) { // If we got more left, find first empty slot - for(int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++) + for (int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++) { - if( m_Slots[i + a_Offset].m_ItemType == -1 ) + if (m_Slots[i + a_Offset].m_ItemType == -1 ) { m_Slots[i + a_Offset] = a_Item; a_Item.m_ItemCount = 0; -- cgit v1.2.3 From 93d29555e58df172bafba530afbc593c16ec66a3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 21 Jul 2014 15:19:48 +0200 Subject: Style: Normalized to no spaces before closing parenthesis. --- src/Inventory.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Inventory.cpp') diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 93b2c8eee..0f9716d89 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -497,21 +497,21 @@ int cInventory::ArmorSlotNumToEntityEquipmentID(short a_ArmorSlotNum) #if 0 -bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */ ) +bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */) { // Fill already present stacks - if (a_Mode < 2 ) + if (a_Mode < 2) { int MaxStackSize = cItemHandler::GetItemHandler(a_Item.m_ItemType)->GetMaxStackSize(); for (int i = 0; i < a_Size; i++) { - if (m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType && m_Slots[i + a_Offset].m_ItemCount < MaxStackSize && m_Slots[i + a_Offset].m_ItemDamage == a_Item.m_ItemDamage ) + if (m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType && m_Slots[i + a_Offset].m_ItemCount < MaxStackSize && m_Slots[i + a_Offset].m_ItemDamage == a_Item.m_ItemDamage) { int NumFree = MaxStackSize - m_Slots[i + a_Offset].m_ItemCount; - if (NumFree >= a_Item.m_ItemCount ) + if (NumFree >= a_Item.m_ItemCount) { - // printf("1. Adding %i items ( free: %i )\n", a_Item.m_ItemCount, NumFree ); + // printf("1. Adding %i items ( free: %i)\n", a_Item.m_ItemCount, NumFree); m_Slots[i + a_Offset].m_ItemCount += a_Item.m_ItemCount; a_Item.m_ItemCount = 0; a_bChangedSlots[i + a_Offset] = true; @@ -519,7 +519,7 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, } else { - // printf("2. Adding %i items\n", NumFree ); + // printf("2. Adding %i items\n", NumFree); m_Slots[i + a_Offset].m_ItemCount += (char)NumFree; a_Item.m_ItemCount -= (char)NumFree; a_bChangedSlots[i + a_Offset] = true; @@ -528,12 +528,12 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, } } - if (a_Mode > 0 ) + if (a_Mode > 0) { // If we got more left, find first empty slot for (int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++) { - if (m_Slots[i + a_Offset].m_ItemType == -1 ) + if (m_Slots[i + a_Offset].m_ItemType == -1) { m_Slots[i + a_Offset] = a_Item; a_Item.m_ItemCount = 0; -- cgit v1.2.3