From d908f9c55c17700ee5b8cd44c6939a465d6f6f92 Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Mon, 26 Aug 2024 15:54:15 +0000 Subject: Limit shop's Max button to available carry weight (cherry picked from M+ commit 13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c) --- src/gui/buydialog.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp index 56c3c261..1ac5cdaa 100644 --- a/src/gui/buydialog.cpp +++ b/src/gui/buydialog.cpp @@ -239,7 +239,8 @@ void BuyDialog::updateButtonsAndLabels() if (selectedItem > -1) { - int itemPrice = mShopItems->at(selectedItem)->getPrice(); + const ShopItem *shopItem = mShopItems->at(selectedItem); + const int itemPrice = shopItem->getPrice(); // Calculate how many the player can afford if (itemPrice > 0) @@ -253,6 +254,17 @@ void BuyDialog::updateButtonsAndLabels() mMaxItems = 1; } + // Calculate how many the player can carry + const int itemWeight = shopItem->getInfo().getWeight(); + if (itemWeight > 0) + { + const int myTotalWeight = PlayerInfo::getAttribute(TOTAL_WEIGHT); + const int myMaxWeight = PlayerInfo::getAttribute(MAX_WEIGHT); + const int myFreeWeight = myMaxWeight - myTotalWeight; + const int canCarry = myFreeWeight / itemWeight; + mMaxItems = std::min(mMaxItems, canCarry); + } + if (mAmountItems > mMaxItems) mAmountItems = mMaxItems; -- cgit v1.2.3-70-g09d2