summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-13 16:06:07 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-13 16:06:07 +0100
commit83a3b6f920f446b3001725554ab15bed34d6f368 (patch)
tree7e29f4c3162c19b3ce50e9c32d7c22cce4219e39 /src/gui
parent3d8a5b02de7a05f412a36fc4d4ba85402e028e65 (diff)
downloadmana-client-83a3b6f920f446b3001725554ab15bed34d6f368.tar.gz
mana-client-83a3b6f920f446b3001725554ab15bed34d6f368.tar.bz2
mana-client-83a3b6f920f446b3001725554ab15bed34d6f368.tar.xz
mana-client-83a3b6f920f446b3001725554ab15bed34d6f368.zip
Fix a segfault when attempting to buy free items.
Resolves: Mana-mantis #277 Trivial fix.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/buy.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index cc135e07..4a8dae17 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -204,8 +204,10 @@ void BuyDialog::action(const gcn::ActionEvent &event)
// Update money and adjust the max number of items that can be bought
mMaxItems -= mAmountItems;
- setMoney(mMoney -
- mAmountItems * mShopItems->at(selectedItem)->getPrice());
+ int price = mShopItems->at(selectedItem)->getPrice();
+ if (price < 0)
+ price = 0;
+ setMoney(mMoney - mAmountItems * price);
// Reset selection
mAmountItems = 1;
@@ -234,12 +236,20 @@ void BuyDialog::updateButtonsAndLabels()
int itemPrice = mShopItems->at(selectedItem)->getPrice();
// Calculate how many the player can afford
- mMaxItems = mMoney / itemPrice;
- if (mAmountItems > mMaxItems)
+ if (itemPrice > 0)
{
- mAmountItems = mMaxItems;
+ mMaxItems = mMoney / itemPrice;
+ }
+ else
+ {
+ // Let the player no more than 1 of them at a time, since it
+ // shouldn't be a permitted case.
+ mMaxItems = 1;
}
+ if (mAmountItems > mMaxItems)
+ mAmountItems = mMaxItems;
+
// Calculate price of pending purchase
price = mAmountItems * itemPrice;
}