summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/debug.cc4
-rw-r--r--crawl-ref/source/decks.cc2
-rw-r--r--crawl-ref/source/food.cc4
-rw-r--r--crawl-ref/source/invent.cc50
-rw-r--r--crawl-ref/source/invent.h4
-rw-r--r--crawl-ref/source/item_use.cc98
-rw-r--r--crawl-ref/source/quiver.cc4
7 files changed, 89 insertions, 77 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 93339c928b..7b08beaec1 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -2136,8 +2136,8 @@ static void _debug_acquirement_stats(FILE *ostat)
static void _debug_rap_stats(FILE *ostat)
{
- int i = prompt_invent_item(
- "Generate ranandart stats on which item?", MT_INVLIST, -1 );
+ int i = prompt_invent_item( "Generate randart stats on which item?",
+ MT_INVLIST, -1 );
if (i == PROMPT_ABORT)
{
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index 12b1cf1aa5..9766a536fe 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -713,7 +713,7 @@ static int _choose_inventory_deck( const char* prompt )
{
const int slot = prompt_invent_item( prompt,
MT_INVLIST, OSEL_DRAW_DECK,
- true, true, true, 0, NULL,
+ true, true, true, 0, -1, NULL,
OPER_EVOKE );
if (prompt_failed(slot))
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index 7a20b95fbe..776ae2dbb2 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -708,7 +708,7 @@ bool prompt_eat_from_inventory(int slot)
prompt_invent_item( "Eat which item?",
MT_INVLIST,
OBJ_FOOD,
- true, true, true, 0, NULL,
+ true, true, true, 0, -1, NULL,
OPER_EAT );
}
else
@@ -717,7 +717,7 @@ bool prompt_eat_from_inventory(int slot)
prompt_invent_item( "Drain what?",
MT_INVLIST,
OSEL_VAMP_EAT,
- true, true, true, 0, NULL,
+ true, true, true, 0, -1, NULL,
OPER_EAT );
}
diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc
index 7bc3b3732b..93458657bc 100644
--- a/crawl-ref/source/invent.cc
+++ b/crawl-ref/source/invent.cc
@@ -52,8 +52,8 @@
///////////////////////////////////////////////////////////////////////////////
// Inventory menu shenanigans
-static void _get_inv_items_to_show(
- std::vector<const item_def*> &v, int selector);
+static void _get_inv_items_to_show( std::vector<const item_def*> &v,
+ int selector, int excluded_slot = -1);
InvTitle::InvTitle( Menu *mn, const std::string &title,
invtitle_annotator tfn )
@@ -364,21 +364,18 @@ static std::string _no_selectables_message(int item_selector)
return("You aren't carrying any such object.");
}
-void InvMenu::load_inv_items(int item_selector,
+void InvMenu::load_inv_items(int item_selector, int excluded_slot,
MenuEntry *(*procfn)(MenuEntry *me))
{
std::vector<const item_def *> tobeshown;
- _get_inv_items_to_show(tobeshown, item_selector);
+ _get_inv_items_to_show(tobeshown, item_selector, excluded_slot);
load_items(tobeshown, procfn);
+
if (!item_count())
- {
set_title(_no_selectables_message(item_selector));
- }
else
- {
set_title("");
- }
}
void InvMenu::draw_stock_item(int index, const MenuEntry *me) const
@@ -714,15 +711,17 @@ unsigned char get_invent( int invent_type )
while (true)
{
- select = invent_select(NULL, MT_INVLIST, invent_type,
- MF_SINGLESELECT);
- if ( isalpha(select) )
+ select = invent_select(NULL, MT_INVLIST, invent_type, -1,
+ MF_SINGLESELECT);
+
+ if (isalpha(select))
{
const int invidx = letter_to_index(select);
if ( is_valid_item(you.inv[invidx]) )
describe_item( you.inv[invidx], true );
}
- else break;
+ else
+ break;
}
redraw_screen();
return select;
@@ -879,11 +878,13 @@ static bool _is_item_selected(const item_def &i, int selector)
|| _userdef_item_selected(i, selector));
}
-static void _get_inv_items_to_show(std::vector<const item_def*> &v, int selector)
+static void _get_inv_items_to_show(std::vector<const item_def*> &v,
+ int selector, int excluded_slot)
{
for (int i = 0; i < ENDOFPACK; i++)
{
if (is_valid_item(you.inv[i])
+ && you.inv[i].slot != excluded_slot
&& _is_item_selected(you.inv[i], selector))
{
v.push_back( &you.inv[i] );
@@ -907,6 +908,7 @@ static bool _any_items_to_select(int selector)
unsigned char invent_select( const char *title,
menu_type type,
int item_selector,
+ int excluded_slot,
int flags,
invtitle_annotator titlefn,
std::vector<SelItem> *items,
@@ -921,7 +923,7 @@ unsigned char invent_select( const char *title,
menu.f_selitem = selitemfn;
if (filter)
menu.set_select_filter( *filter );
- menu.load_inv_items(item_selector);
+ menu.load_inv_items(item_selector, excluded_slot);
menu.set_type(type);
// Don't override title if there are no items.
@@ -940,7 +942,7 @@ unsigned char invent( int item_class_inv, bool show_price )
{
InvShowPrices show_item_prices(show_price);
return (invent_select(NULL, MT_INVLIST, item_class_inv));
-} // end invent()
+}
// Reads in digits for a count and apprends then to val, the
// return value is the character that stopped the reading.
@@ -1040,13 +1042,13 @@ std::vector<SelItem> prompt_invent_items(
MF_MULTISELECT | MF_ALLOW_FILTER;
// The "view inventory listing" mode.
- int ch = invent_select(
- prompt,
- mtype,
- keyin == '*'? OSEL_ANY : type_expect,
- selmode,
- titlefn, &items, select_filter, fn,
- pre_select );
+ int ch = invent_select( prompt,
+ mtype,
+ keyin == '*' ? OSEL_ANY : type_expect,
+ -1,
+ selmode,
+ titlefn, &items, select_filter, fn,
+ pre_select );
if ((selmode & MF_SINGLESELECT) || ch == ESCAPE)
{
@@ -1321,6 +1323,7 @@ int prompt_invent_item( const char *prompt,
bool must_exist, bool allow_auto_list,
bool allow_easy_quit,
const char other_valid_char,
+ int excluded_slot,
int *const count,
operation_types oper )
{
@@ -1382,7 +1385,8 @@ int prompt_invent_item( const char *prompt,
keyin = invent_select(
prompt,
mtype,
- keyin == '*'? OSEL_ANY : type_expect,
+ keyin == '*' ? OSEL_ANY : type_expect,
+ excluded_slot,
MF_SINGLESELECT | MF_ANYPRINTABLE | MF_NO_SELECT_QTY
| MF_EASY_EXIT,
NULL,
diff --git a/crawl-ref/source/invent.h b/crawl-ref/source/invent.h
index 8ff0a75e35..4f6bffc642 100644
--- a/crawl-ref/source/invent.h
+++ b/crawl-ref/source/invent.h
@@ -143,7 +143,7 @@ public:
// Loads items from the player's inventory into the menu, and sets the
// title to the stock title. If "procfn" is provided, it'll be called for
// each MenuEntry added, *excluding the title*.
- void load_inv_items(int item_selector = OSEL_ANY,
+ void load_inv_items(int item_selector = OSEL_ANY, int excluded_slot = -1,
MenuEntry *(*procfn)(MenuEntry *me) = NULL);
std::vector<SelItem> get_selitems() const;
@@ -177,6 +177,7 @@ int prompt_invent_item( const char *prompt,
bool allow_auto_list = true,
bool allow_easy_quit = true,
const char other_valid_char = '\0',
+ int excluded_slot = -1,
int *const count = NULL,
operation_types oper = OPER_ANY );
@@ -210,6 +211,7 @@ unsigned char invent_select(
// MT_DROP allows the multidrop toggle
menu_type type = MT_INVLIST,
int item_selector = OSEL_ANY,
+ int excluded_slot = -1,
int menu_select_flags = MF_NOSELECT,
invtitle_annotator titlefn = NULL,
std::vector<SelItem> *sels = NULL,
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 9581778641..c84b2542d9 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -268,7 +268,7 @@ bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages)
item_slot = prompt_invent_item(
"Wield which item (- for none, * to show all)?",
MT_INVLIST, OSEL_WIELD,
- true, true, true, '-', NULL, OPER_WIELD);
+ true, true, true, '-', -1, NULL, OPER_WIELD);
}
else
item_slot = PROMPT_GOT_SPECIAL;
@@ -785,7 +785,7 @@ bool armour_prompt( const std::string & mesg, int *index, operation_types oper)
else
{
slot = prompt_invent_item( mesg.c_str(), MT_INVLIST, OBJ_ARMOUR,
- true, true, true, 0, NULL,
+ true, true, true, 0, -1, NULL,
oper );
if (!prompt_failed(slot))
@@ -1493,8 +1493,8 @@ static int _fire_prompt_for_item(std::string& err)
int slot = prompt_invent_item( "Fire/throw which item? (* to show all)",
MT_INVLIST,
- OSEL_THROWABLE, true, true, true, 0, NULL,
- OPER_FIRE );
+ OSEL_THROWABLE, true, true, true, 0, -1,
+ NULL, OPER_FIRE );
if (slot == PROMPT_ABORT || slot == PROMPT_NOTHING)
{
@@ -3161,9 +3161,11 @@ bool puton_ring(int slot, bool prompt_finger)
if (slot != -1)
item_slot = slot;
else
+ {
item_slot = prompt_invent_item( "Put on which piece of jewellery?",
- MT_INVLIST, OBJ_JEWELLERY, true, true, true, 0, NULL,
- OPER_PUTON );
+ MT_INVLIST, OBJ_JEWELLERY, true, true, true, 0, -1,
+ NULL, OPER_PUTON );
+ }
if (prompt_failed(item_slot))
return (false);
@@ -3309,7 +3311,7 @@ bool remove_ring(int slot, bool announce)
(slot == -1)? prompt_invent_item( "Remove which piece of jewellery?",
MT_INVLIST,
OBJ_JEWELLERY, true, true, true,
- 0, NULL, OPER_REMOVE)
+ 0, -1, NULL, OPER_REMOVE)
: slot;
if (prompt_failed(equipn))
@@ -3414,10 +3416,10 @@ void zap_wand( int slot )
else
{
item_slot = prompt_invent_item( "Zap which item?",
- MT_INVLIST,
- OBJ_WANDS,
- true, true, true, 0, NULL,
- OPER_ZAP );
+ MT_INVLIST,
+ OBJ_WANDS,
+ true, true, true, 0, -1, NULL,
+ OPER_ZAP );
}
if (prompt_failed(item_slot))
@@ -3642,7 +3644,7 @@ void drink( int slot )
{
item_slot = prompt_invent_item( "Drink which item?",
MT_INVLIST, OBJ_POTIONS,
- true, true, true, 0, NULL,
+ true, true, true, 0, -1, NULL,
OPER_QUAFF );
}
@@ -4166,21 +4168,27 @@ static void handle_read_book( int item_slot )
// something that is affected by the scroll. Once they're identified, you'll
// get the limited inventory listing.
// Returns true if the scroll had an obvious effect and should be identified.
-static bool scroll_modify_item(const scroll_type scroll)
+static bool _scroll_modify_item(item_def scroll)
{
- int item_slot = prompt_invent_item( "Use on which item?", MT_INVLIST,
- OSEL_ANY, true, true, false );
+ ASSERT(scroll.base_type == OBJ_SCROLLS);
+
+ // Get the slot of the scroll just read.
+ int item_slot = scroll.slot;
+
+ // Get the slot of the item the scroll is to be used on.
+ // Ban the scroll's own slot from the prompt to avoid the stupid situation
+ // where you use identify on itself.
+ item_slot = prompt_invent_item("Use on which item?", MT_INVLIST,
+ OSEL_ANY, true, true, false, 0, item_slot);
- if (prompt_failed(item_slot))
- return (false);
+ if (prompt_failed(item_slot))
+ return (false);
- item_def &item = you.inv[item_slot];
+ item_def &item = you.inv[item_slot];
- switch (scroll)
- {
- case SCR_IDENTIFY:
- // This can cause a stupid situation where you try to identify the
- // very scroll you just read, causing you to waste the scroll.
+ switch (scroll.sub_type)
+ {
+ case SCR_IDENTIFY:
if (!fully_identified(item))
{
mpr("This is a scroll of identify!");
@@ -4188,7 +4196,7 @@ static bool scroll_modify_item(const scroll_type scroll)
return (true);
}
break;
- case SCR_RECHARGING:
+ case SCR_RECHARGING:
if (item_is_rechargable(item))
{
// Might still fail on highly enchanted weapons of electrocution.
@@ -4198,7 +4206,7 @@ static bool scroll_modify_item(const scroll_type scroll)
return (false);
}
break;
- case SCR_ENCHANT_ARMOUR:
+ case SCR_ENCHANT_ARMOUR:
if (is_enchantable_armour(item, true))
{
// Might still fail because of already high enchantment.
@@ -4208,14 +4216,14 @@ static bool scroll_modify_item(const scroll_type scroll)
return (false);
}
break;
- default:
+ default:
mpr("Buggy scroll can't modify item!");
break;
- }
+ }
- // Oops, wrong item...
- canned_msg(MSG_NOTHING_HAPPENS);
- return (false);
+ // Oops, wrong item...
+ canned_msg(MSG_NOTHING_HAPPENS);
+ return (false);
}
void read_scroll( int slot )
@@ -4241,14 +4249,12 @@ void read_scroll( int slot )
return;
}
- int item_slot = (slot != -1) ?
- slot :
- prompt_invent_item(
- "Read which item?",
- MT_INVLIST,
- OBJ_SCROLLS,
- true, true, true, 0, NULL,
- OPER_READ );
+ int item_slot = (slot != -1) ? slot
+ : prompt_invent_item( "Read which item?",
+ MT_INVLIST,
+ OBJ_SCROLLS,
+ true, true, true, 0, -1,
+ NULL, OPER_READ );
if (prompt_failed(item_slot))
return;
@@ -4520,22 +4526,22 @@ void read_scroll( int slot )
break;
case SCR_IDENTIFY:
- if ( !item_type_known(scroll) )
- id_the_scroll = scroll_modify_item(which_scroll);
+ if (!item_type_known(scroll))
+ id_the_scroll = _scroll_modify_item(scroll);
else
- identify(-1);
+ identify(-1);
break;
case SCR_RECHARGING:
- if ( !item_type_known(scroll) )
- id_the_scroll = scroll_modify_item(which_scroll);
+ if (!item_type_known(scroll))
+ id_the_scroll = _scroll_modify_item(scroll);
else
- recharge_wand(-1);
+ recharge_wand(-1);
break;
case SCR_ENCHANT_ARMOUR:
if (!item_type_known(scroll))
- id_the_scroll = scroll_modify_item(which_scroll);
+ id_the_scroll = _scroll_modify_item(scroll);
else
_handle_enchant_armour(-1);
break;
@@ -4623,7 +4629,7 @@ void examine_object(void)
{
int item_slot = prompt_invent_item( "Examine which item?",
MT_INVLIST, -1,
- true, true, true, 0, NULL,
+ true, true, true, 0, -1, NULL,
OPER_EXAMINE );
if (prompt_failed(item_slot))
return;
diff --git a/crawl-ref/source/quiver.cc b/crawl-ref/source/quiver.cc
index 011976e6fa..d6e52d5f36 100644
--- a/crawl-ref/source/quiver.cc
+++ b/crawl-ref/source/quiver.cc
@@ -144,8 +144,8 @@ void choose_item_for_quiver()
{
int slot = prompt_invent_item( "Quiver which item? (- for none, * to show all)",
MT_INVLIST,
- OSEL_THROWABLE, true, true, true, '-', NULL,
- OPER_QUIVER );
+ OSEL_THROWABLE, true, true, true, '-', -1,
+ NULL, OPER_QUIVER );
if (slot == PROMPT_ABORT)
{