summaryrefslogtreecommitdiff
path: root/src/resources/item/shopitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/item/shopitem.cpp')
-rw-r--r--src/resources/item/shopitem.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/resources/item/shopitem.cpp b/src/resources/item/shopitem.cpp
index c724be7ca..e55cbcd67 100644
--- a/src/resources/item/shopitem.cpp
+++ b/src/resources/item/shopitem.cpp
@@ -1,11 +1,11 @@
/*
- * The ManaPlus Client
+ * The ManaVerse Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
* Copyright (C) 2011-2020 The ManaPlus Developers
- * Copyright (C) 2020-2023 The ManaVerse Developers
+ * Copyright (C) 2020-2025 The ManaVerse Developers
*
- * This file is part of The ManaPlus Client.
+ * This file is part of The ManaVerse Client.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -105,13 +105,16 @@ void ShopItem::updateDisplayName(const int quantity)
else
#endif // TMWA_SUPPORT
mDisplayName = std::string(getInfo().getName(mColor));
+
if (mPrice != 0)
{
mDisplayName.append(" (").append(
UnitsDb::formatCurrency(mCurrency, mPrice)).append(") ");
}
- if (mShowQuantity && quantity > 1)
+
+ if (mShowQuantity && quantity > 0)
mDisplayName.append("[").append(toString(quantity)).append("]");
+
if (mUsedQuantity > 0)
mDisplayName.append(" +").append(toString(mUsedQuantity));
}
@@ -144,8 +147,7 @@ int ShopItem::sellCurrentDuplicate(const int quantity)
if (dupl == nullptr)
return 0;
- const int sellCount = quantity <= dupl->quantity
- ? quantity : dupl->quantity;
+ const int sellCount = std::min(quantity, dupl->quantity);
dupl->quantity -= sellCount;
mQuantity -= sellCount;
if (dupl->quantity == 0)
@@ -158,18 +160,18 @@ int ShopItem::sellCurrentDuplicate(const int quantity)
void ShopItem::increaseUsedQuantity(const int amount)
{
+ const int newUsedQuantity = mUsedQuantity + amount;
if (mShowQuantity && (mQuantity != 0))
{
- if (mQuantity < mUsedQuantity + amount ||
- mUsedQuantity + amount < 0)
+ if (newUsedQuantity < 0 || mQuantity < newUsedQuantity)
{
return;
}
}
- else if (mUsedQuantity + amount < 0)
+ else if (newUsedQuantity < 0)
{
return;
}
- mUsedQuantity += amount;
+ mUsedQuantity = newUsedQuantity;
}