diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-13 16:06:07 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-13 18:51:32 +0100 |
commit | 10e5f2e1d88897c16f2ce5e2ef26898ae05ab9ef (patch) | |
tree | 368ed89ddc7c5098e367d59300cdfb28d3fd70b1 | |
parent | 27cdfc3e15846983ee877ac74c0fcc87b118bf15 (diff) | |
download | mana-10e5f2e1d88897c16f2ce5e2ef26898ae05ab9ef.tar.gz mana-10e5f2e1d88897c16f2ce5e2ef26898ae05ab9ef.tar.bz2 mana-10e5f2e1d88897c16f2ce5e2ef26898ae05ab9ef.tar.xz mana-10e5f2e1d88897c16f2ce5e2ef26898ae05ab9ef.zip |
Fix a segfault when attempting to buy free items.
Resolves: Mana-mantis #277
Trivial fix.
-rw-r--r-- | src/gui/buy.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 031c53dd..faa86cc9 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -199,8 +199,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; @@ -229,12 +231,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; } |