summaryrefslogtreecommitdiffstats
path: root/source/cPlayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/cPlayer.cpp')
-rw-r--r--source/cPlayer.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index c260330f6..7c0f0c703 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -792,38 +792,52 @@ AString cPlayer::GetColor(void) const
-void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ )
+void cPlayer::TossItem(
+ bool a_bDraggingItem,
+ int a_Amount /* = 1 */,
+ int a_CreateType /* = 0 */,
+ int a_CreateHealth /* = 0 */
+)
{
cItems Drops;
- if (a_bDraggingItem)
+ if (a_CreateType)
{
- cItem * Item = GetInventory().GetWindow()->GetDraggingItem();
- if (!Item->IsEmpty())
- {
- Drops.push_back(*Item);
- if( Item->m_ItemCount > a_Amount )
- Item->m_ItemCount -= (char)a_Amount;
- else
- Item->Empty();
- }
+ // Just create item without touching the inventory (used in creative mode)
+ Drops.push_back(cItem((ENUM_ITEM_ID)a_CreateType, (char)a_Amount, a_CreateHealth));
}
else
{
- // Else drop equipped item
- cItem DroppedItem = GetInventory().GetEquippedItem();
- if (!DroppedItem.IsEmpty())
+ // Drop an item from the inventory:
+ if (a_bDraggingItem)
+ {
+ cItem * Item = GetInventory().GetWindow()->GetDraggingItem();
+ if (!Item->IsEmpty())
+ {
+ Drops.push_back(*Item);
+ if( Item->m_ItemCount > a_Amount )
+ Item->m_ItemCount -= (char)a_Amount;
+ else
+ Item->Empty();
+ }
+ }
+ else
{
- DroppedItem.m_ItemCount = 1;
- if (GetInventory().RemoveItem(DroppedItem))
+ // Else drop equipped item
+ cItem DroppedItem = GetInventory().GetEquippedItem();
+ if (!DroppedItem.IsEmpty())
{
- DroppedItem.m_ItemCount = 1; // RemoveItem decreases the count, so set it to 1 again
- Drops.push_back(DroppedItem);
+ DroppedItem.m_ItemCount = 1;
+ if (GetInventory().RemoveItem(DroppedItem))
+ {
+ DroppedItem.m_ItemCount = 1; // RemoveItem decreases the count, so set it to 1 again
+ Drops.push_back(DroppedItem);
+ }
}
}
}
float vX = 0, vY = 0, vZ = 0;
- EulerToVector( -GetRotation(), GetPitch(), vZ, vX, vY );
- vY = -vY*2 + 1.f;
+ EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY);
+ vY = -vY * 2 + 1.f;
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 2, vY * 2, vZ * 2);
}