From 6c500b492e4b82caa5b1ec420a41beaecdd426ae Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Mon, 10 Mar 2025 17:53:26 +0000 Subject: Slight cleanup in shopitem.cpp **** mana/plus!140 --- src/resources/item/shopitem.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/resources/item/shopitem.cpp b/src/resources/item/shopitem.cpp index c724be7ca..2ed6299cb 100644 --- a/src/resources/item/shopitem.cpp +++ b/src/resources/item/shopitem.cpp @@ -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) 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; } -- cgit v1.2.3-70-g09d2