Attached Files |
8934.patch [^] (4,531 bytes) 2015-03-07 03:42 [Show Content] [Hide Content]From 09e14ba18ae6ffb6d3f996467f656fb0669d35e0 Mon Sep 17 00:00:00 2001
From: "Edgar A. Bering IV" <trizor@gmail.com>
Date: Fri, 6 Mar 2015 20:00:54 -0600
Subject: [PATCH] Simplify shop/shopping list interaction with duplicate stock
(8934)
Previously had a display bug, and didn't make sense. This still has the wart
that if a player selects to purchase one of a duplicate group the whole group
is removed from the shopping list, but it at least makes sense over the old
behavior (which was to keep the item selected, but display nothing, and buggily
accumulate nonsense total cost display).
---
crawl-ref/source/shopping.cc | 33 ++++++++++-----------------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index e0f6628..651c3c0 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -338,7 +338,7 @@ static void _shop_print_stock(const vector<bool>& selected,
const char c = i + 'a';
// Colour stock as follows:
- // * lightcyan, if on the shopping list.
+ // * lightcyan, if on the shopping list and not selected.
// * lightred, if you can't buy all you selected.
// * lightgreen, if this item is purchasable along with your selections
// * red, if this item is not purchasable even by itself.
@@ -347,7 +347,7 @@ static void _shop_print_stock(const vector<bool>& selected,
// Is this too complicated? (jpeg)
- if (in_list[stock_pos])
+ if (in_list[stock_pos] && !selected[stock_pos])
textcolour(LIGHTCYAN);
else if (total_cost > you.gold && selected[stock_pos])
textcolour(LIGHTRED);
@@ -361,7 +361,7 @@ static void _shop_print_stock(const vector<bool>& selected,
else
textcolour(YELLOW);
- if (in_list[stock_pos])
+ if (in_list[stock_pos] && !selected[stock_pos])
cprintf("%c $ ", c);
else if (selected[stock_pos])
cprintf("%c + ", c);
@@ -488,12 +488,17 @@ static bool _in_a_shop(int shopidx, int &num_in_list)
num_in_list = 0;
int num_selected = 0;
+ total_cost = 0;
for (size_t i = 0; i < shop.stock.size(); i++)
{
if (in_list[i])
num_in_list++;
if (selected[i])
+ {
+ total_cost += _shop_get_item_value(shop.stock[i],
+ shop.greed, id_stock);
num_selected++;
+ }
}
clrscr();
@@ -821,46 +826,28 @@ static bool _in_a_shop(int shopidx, int &num_in_list)
}
else
{
- const int gp_value = _shop_get_item_value(item, shop.greed,
- id_stock);
if (in_list[key])
{
if (to_shoplist)
{
shopping_list.del_thing(item);
- in_list[key] = false;
selected[key] = false;
- continue;
}
else
{
shopping_list.del_thing(item);
- in_list[key] = false;
- // Will be toggled to true later
- selected[key] = false;
+ selected[key] = !selected[key];
}
}
else if (to_shoplist)
{
- in_list[key] = true;
- if (selected[key])
- total_cost -= gp_value;
selected[key] = false;
const int cost = _shop_get_item_value(item, shop.greed,
id_stock);
shopping_list.add_thing(item, cost);
- continue;
}
-
- // Okay, we are now selecting an item normally, and it
- // is not on the shopping list.
- ASSERT(!in_list[key]);
-
- selected[key] = !selected[key];
- if (selected[key])
- total_cost += gp_value;
else
- total_cost -= gp_value;
+ selected[key] = !selected[key];
ASSERT(total_cost >= 0);
}
--
1.9.3 (Apple Git-50)
|