summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2024-08-26 15:54:15 +0000
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-08-26 17:57:01 +0200
commitd908f9c55c17700ee5b8cd44c6939a465d6f6f92 (patch)
tree6b1f519a6884730476e4d29729ce3cf199fa14c1 /src
parent221d67c4774bf41e6f2f0f73fb6914030e33bdde (diff)
downloadmana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.tar.gz
mana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.tar.bz2
mana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.tar.xz
mana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.zip
Limit shop's Max button to available carry weight
(cherry picked from M+ commit 13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c)
Diffstat (limited to 'src')
-rw-r--r--src/gui/buydialog.cpp14
1 files changed, 13 insertions, 1 deletions
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;