summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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;