Permalink
Browse files

Made the shop remember the price of items when refreshing the sell list.

Previously, the price was set to 0 when you wanted to sell
starting from the second time in a row.
  • Loading branch information...
1 parent d935a70 commit 100fe0412f086daab082498737e5cfa042c0ebb4 Yohann Ferreira committed Aug 28, 2012
Showing with 20 additions and 13 deletions.
  1. +7 −3 src/modes/shop/shop.cpp
  2. +12 −9 src/modes/shop/shop_sell.cpp
  3. +1 −1 src/modes/shop/shop_sell.h
View
@@ -1141,6 +1141,7 @@ void ShopMode::_UpdateAvailableObjectsToSell() {
else {
ShopObject *new_shop_object = new ShopObject(it->second);
new_shop_object->IncrementOwnCount(it->second->GetCount());
+ new_shop_object->SetPricing(GetBuyPriceLevel(), GetSellPriceLevel());
_available_sell.insert(make_pair(it->second->GetID(), new_shop_object));
}
}
@@ -1509,15 +1510,18 @@ void ShopMode::UpdateFinances(int32 costs_amount, int32 sales_amount) {
int32 updated_sales = _total_sales + sales_amount;
if (updated_costs < 0) {
- IF_PRINT_WARNING(SHOP_DEBUG) << "updated amount causes costs to become negative: " << costs_amount << endl;
+ PRINT_WARNING << "updated amount causes costs to become negative: "
+ << costs_amount << std::endl;
return;
}
if (updated_sales < 0) {
- IF_PRINT_WARNING(SHOP_DEBUG) << "updated amount causes sales to become negative: " << sales_amount << endl;
+ PRINT_WARNING << "updated amount causes sales to become negative: "
+ << sales_amount << std::endl;
return;
}
if ((static_cast<int32>(GlobalManager->GetDrunes()) + updated_sales - updated_costs) < 0) {
- IF_PRINT_WARNING(SHOP_DEBUG) << "updated costs and sales values cause negative balance: " << costs_amount << ", " << sales_amount << endl;
+ PRINT_WARNING << "updated costs and sales values cause negative balance: "
+ << costs_amount << ", " << sales_amount << std::endl;
return;
}
@@ -513,7 +513,7 @@ bool SellInterface::_ChangeCategory(bool left_or_right) {
-bool SellInterface::_ChangeSelection(bool up_or_down) {
+bool SellInterface::_ChangeSelection(bool down) {
if (_current_category >= _list_displays.size())
return false;
@@ -522,7 +522,7 @@ bool SellInterface::_ChangeSelection(bool up_or_down) {
if (!selected_list)
return false;
- if (up_or_down == false)
+ if (!down)
selected_list->InputUp();
else
selected_list->InputDown();
@@ -593,18 +593,19 @@ void SellListDisplay::RefreshEntry(uint32 index) {
-bool SellListDisplay::ChangeSellQuantity(bool less_or_more, uint32 amount) {
+bool SellListDisplay::ChangeSellQuantity(bool more, uint32 amount) {
ShopObject* obj = GetSelectedObject();
- if (obj == NULL) {
- IF_PRINT_WARNING(SHOP_DEBUG) << "function could not perform operation because list was empty" << endl;
+ if (!obj) {
+ PRINT_WARNING << "function could not perform operation because list was empty"
+ << std::endl;
return false;
}
// Holds the amount that the quantity will actually increase or decrease by. May be less than the
// amount requested if there is an limitation such as shop stock or available funds
uint32 change_amount = amount;
- if (less_or_more == false) {
+ if (!more) {
// Make sure that there is at least one more count to sell and that the player has enough funds to return it
if ((obj->GetSellCount() == 0) ||
(obj->GetSellPrice() > ShopMode::CurrentInstance()->GetTotalRemaining()))
@@ -632,19 +633,21 @@ bool SellListDisplay::ChangeSellQuantity(bool less_or_more, uint32 amount) {
RefreshEntry(GetCurrentSelection());
return true;
}
- else {
+ else { // more
// Make sure that there is at least one more object available to sell in the player's inventory
if (obj->GetSellCount() >= obj->GetOwnCount()) {
return false;
}
- // Determine if there's enough of the object in stock to sell. If not, sell as many left as possible
+ // Determine if there's enough of the object in stock to sell.
+ // If not, sell as many left as possible
if ((obj->GetOwnCount() - obj->GetSellCount()) < change_amount) {
change_amount = obj->GetOwnCount() - obj->GetSellCount();
}
obj->IncrementSellCount(change_amount);
- ShopMode::CurrentInstance()->UpdateFinances(0, (obj->GetSellPrice() * change_amount));
+
+ ShopMode::CurrentInstance()->UpdateFinances(0, obj->GetSellPrice() * change_amount);
RefreshEntry(GetCurrentSelection());
return true;
}
@@ -194,7 +194,7 @@ class SellListDisplay : public ObjectListDisplay {
*** the player only has 3 instances of the selected object in inventory, the function will increase
*** the quantity by 3 (not 8) and return true.
**/
- bool ChangeSellQuantity(bool less_or_more, uint32 amount = 1);
+ bool ChangeSellQuantity(bool more, uint32 amount = 1);
}; // class SellListDisplay : public ObjectListDisplay
} // namespace private_shop

0 comments on commit 100fe04

Please sign in to comment.