/* pick the context menu options appropiate for the item */ int context_menu_object(const object_type *o_ptr) { menu_type *m; rect_region r; int selected; int location = 0; char *labels; char header[120]; s16b *list; m = menu_dynamic_new(); if (!m || !o_ptr) { return 0; } object_desc(header, o_ptr, TRUE, 2, sizeof(header)); list = look_up_list((object_type*)o_ptr); if (list) { if (list == &(p_ptr->inventory)) { location = USE_INVEN; } else if (list == &(area(p_ptr->px, p_ptr->py)->o_idx)) { location = USE_FLOOR; } else { /* check if in a container */ location = USE_INVEN; } } else if (GET_ARRAY_INDEX(p_ptr->equipment, o_ptr) >= EQUIP_WIELD) { location = USE_EQUIP; } labels = (char*)string_make(lower_case); m->selections = labels; menu_dynamic_add_label(m, "Inspect", 'I', 1, labels); if (item_tester_hook_is_book(o_ptr)) { if (player_can_cast_from(o_ptr)) { if (player_can_cast()) { menu_dynamic_add_label(m, "Cast", 'm', 8, labels); } else { menu_dynamic_add_label(m, "$Cast", 'm', 8, labels); } if (player_can_study()) { menu_dynamic_add_label(m, "Study", 'G', 10, labels); } else { menu_dynamic_add_label(m, "$Study", 'G', 10, labels); } } if (player_is_caster() && player_can_read()) { menu_dynamic_add_label(m, "Browse", 'b', 9, labels); } } else if (item_tester_hook_useable(o_ptr)) { if (obj_is_wand(o_ptr)) { if (obj_has_charges(o_ptr)) { menu_dynamic_add_label(m, "Aim", 'a', 8, labels); } else { menu_dynamic_add_label(m, "$Aim", 'a', 8, labels); } } else if (obj_is_rod(o_ptr)) { if (obj_can_zap(o_ptr)) { menu_dynamic_add_label(m, "Zap", 'z', 8, labels); } else { menu_dynamic_add_label(m, "$Zap", 'z', 8, labels); } } else if (obj_is_staff(o_ptr)) { if (obj_has_charges(o_ptr)) { menu_dynamic_add_label(m, "Use", 'u', 8, labels); } else { menu_dynamic_add_label(m, "$Use", 'u', 8, labels); } } else if (obj_is_scroll(o_ptr)) { if (player_can_read()) { menu_dynamic_add_label(m, "Read", 'r', 8, labels); } else { menu_dynamic_add_label(m, "$Read", 'r', 8, labels); } } else if (obj_is_potion(o_ptr)) { menu_dynamic_add_label(m, "Quaff", 'q', 8, labels); } else if (obj_is_food(o_ptr)) { menu_dynamic_add_label(m, "Eat", 'E', 8, labels); } else if (item_tester_hook_activate(o_ptr)) { if (obj_is_activatable(o_ptr)) { menu_dynamic_add_label(m, "Activate", 'A', 8, labels); } else { menu_dynamic_add_label(m, "$Activate", 'A', 8, labels); } } else { menu_dynamic_add_label(m, "Use", 'U', 8, labels); } } else if (item_tester_hook_ammo(o_ptr)) { if (obj_can_fire(o_ptr)) { menu_dynamic_add_label(m, "Fire", 'f', 15, labels); } else { menu_dynamic_add_label(m, "$Fire", 'f', 15, labels); } } if (obj_can_refill(o_ptr)) { menu_dynamic_add_label(m, "Refill", 'F', 11, labels); } if (item_tester_hook_wear(o_ptr)) { if (location == USE_EQUIP) { menu_dynamic_add_label(m, "Take off", 't', 3, labels); } else if (location == USE_INVEN) { if (item_tester_hook_armour(o_ptr)) { menu_dynamic_add_label(m, "Wear", 'w', 2, labels); } else { menu_dynamic_add_label(m, "Wield", 'w', 2, labels); } /*menu_dynamic_add_label(m, "Equip", 'w', 2, labels);*/ } } if ((location == USE_INVEN) || (location == USE_EQUIP)) { menu_dynamic_add_label(m, "Drop", 'd', 6, labels); if (o_ptr->number > 1) { menu_dynamic_add_label(m, "Drop All", 'd', 13, labels); } } else if (location == USE_FLOOR) { if (inven_carry_okay(o_ptr)) { menu_dynamic_add_label(m, "Pickup", 'g', 7, labels); } else { menu_dynamic_add_label(m, "$Pickup", 'g', 7, labels); } } menu_dynamic_add_label(m, "Throw", 'v', 12, labels); /*if (obj_has_inscrip(o_ptr)) {*/ if (o_ptr->inscription) { menu_dynamic_add_label(m, "Uninscribe", '}', 5, labels); } else { menu_dynamic_add_label(m, "Inscribe", '{', 4, labels); } menu_dynamic_add_label(m, "Destroy", 'k', 14, labels); #if 0 if (object_is_squelched(o_ptr)) { menu_dynamic_add_label(m, "Unignore", 'k', 14, labels); } else { menu_dynamic_add_label(m, "Ignore", 'k', 14, labels); } #endif /* work out display region */ r.width = menu_dynamic_longest_entry(m) + 3 + 2; /* +3 for tag, 2 for pad */ r.col = Term->wid - r.width - 1; r.row = 1; r.page_rows = m->count; /* Hack -- no flush needed */ msg_flag = FALSE; screen_save(); button_backup_all(TRUE); /* Recall object */ roff_set_width(r.col); roff_obj_aux(o_ptr); roff_set_width(0); menu_layout(m, &r); rect_region_erase_bordered(&r); prtf(0, 0, "($UEnter to select$Y\n$V, $UESC$Y%c$V) Command for %s:", ESCAPE, header); selected = menu_dynamic_select(m); menu_dynamic_free(m); string_free(labels); button_restore(); screen_load(); if (selected == 1) { /* inspect it */ identify_fully_aux(o_ptr); return 2; } else if (selected == 2) { /* wield the item */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'w'; do_cmd_wield(); /*cmd_insert(CMD_WIELD); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 3) { /* take the item off */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = 't'; do_cmd_takeoff(); /*cmd_insert(CMD_TAKEOFF); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 4) { /* inscribe the item */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = '{'; do_cmd_inscribe(); /*cmd_insert(CMD_INSCRIBE); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 5) { /* uninscribe the item */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = '}'; do_cmd_uninscribe(); /*cmd_insert(CMD_UNINSCRIBE); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 6) { /* drop the item */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'd'; do_cmd_drop(); /*cmd_insert(CMD_DROP); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 7) { /* pick the item up */ p_ptr->cmd.cmd = 'g'; if (inven_carry_okay(o_ptr)) { py_pickup_aux((object_type*)o_ptr); } else { carry(TRUE); } /*cmd_insert(CMD_PICKUP); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 8) { /* use the item */ bool full = item_tester_full; item_tester_full = FALSE; if (player_can_cast_from(o_ptr)) { set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'm'; do_cmd_cast(); } else { set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'u'; repeat_check(); do_cmd_use(); /*cmd_insert(CMD_USE_ANY); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } item_tester_full = full; } else if (selected == 9) { /* browse a spellbook */ p_ptr->cmd.cmd = 'b'; do_cmd_browse_aux(o_ptr); /* copied from textui_spell_browse */ /*textui_book_browse(o_ptr);*/ return 2; } else if (selected == 10) { /* study a spell book */ p_ptr->cmd.cmd = 'G'; do_cmd_study(FALSE, (object_type*)o_ptr); } else if (selected == 11) { /* use the item to refill a light source */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'F'; do_cmd_refill(); /*cmd_insert(CMD_REFILL); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 12) { /* throw the item */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'v'; repeat_check(); do_cmd_throw(); /*cmd_insert(CMD_THROW); cmd_set_arg_item(cmd_get_top(), 0, slot);*/ } else if (selected == 13) { /* drop all of the item stack */ if (get_check(format("Drop %s? ", header))) { set_get_item_object(o_ptr); p_ptr->cmd.arg = o_ptr->number; p_ptr->cmd.cmd = 'd'; do_cmd_drop(); /*cmd_insert(CMD_DROP); cmd_set_arg_item(cmd_get_top(), 0, slot); cmd_set_arg_number(cmd_get_top(), 1, o_ptr->number);*/ } } else if (selected == 14) { /* squelch or unsquelch the item */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'k'; do_cmd_destroy(); /*textui_cmd_destroy_menu(slot);*/ } else if (selected == 15) { /* fire some ammo */ set_get_item_object(o_ptr); p_ptr->cmd.cmd = 'f'; repeat_check(); do_cmd_fire(); } else if (selected == -1) { /* this menu was canceled, tell whatever called us to display its menu again */ return 3; } return 1; }
/* * Use an item, a unified 'use' command. */ void do_cmd_use_item(void) { int item; object_type *o_ptr; cptr q, s; /* Unrestricted choice */ item_tester_tval = 0; /* Get an item */ q = "Use which item? "; s = "You have no items use."; if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } // determine the action based on the item type switch (o_ptr->tval) { case TV_BOW: case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN: case TV_SHIELD: case TV_CLOAK: case TV_SOFT_ARMOR: case TV_MAIL: case TV_LIGHT: case TV_AMULET: case TV_RING: case TV_ARROW: case TV_FLASK: { if (item < INVEN_WIELD) { object_type *l_ptr = &inventory[INVEN_LITE]; bool try_to_wield = TRUE; // possibly refuel a light if ((o_ptr->tval == TV_FLASK) || ((l_ptr->tval == o_ptr->tval) && (l_ptr->sval == o_ptr->sval) && ((o_ptr->sval == SV_LIGHT_TORCH) || (o_ptr->sval == SV_LIGHT_LANTERN)))) { if ((l_ptr->sval == SV_LIGHT_TORCH) && (o_ptr->tval != TV_FLASK)) { if ((o_ptr->timeout + l_ptr->timeout <= FUEL_TORCH) || get_check("Refueling from this torch will waste some fuel. Proceed? ")) { do_cmd_refuel_torch(o_ptr, item); } else { try_to_wield = FALSE; } break; } else if (l_ptr->sval == SV_LIGHT_LANTERN) { if (((o_ptr->tval == TV_FLASK) && ((l_ptr->timeout + o_ptr->pval <= FUEL_LAMP) || get_check("Refueling from this flask will waste some fuel. Proceed? "))) || ((o_ptr->tval == TV_LIGHT) && (o_ptr->sval == SV_LIGHT_LANTERN) && ((l_ptr->timeout + o_ptr->timeout <= FUEL_LAMP) || get_check("Refueling from this lantern will waste some fuel. Proceed? ")))) { do_cmd_refuel_lamp(o_ptr, item); } else { try_to_wield = FALSE; } break; } else if (o_ptr->tval == TV_FLASK) { msg_print("That can only be used to refuel a wielded lantern."); break; } } if (!item_tester_hook_wear(o_ptr)) { msg_print("It is far too large to be worn."); } else if (try_to_wield) { do_cmd_wield(o_ptr, item); } } else { do_cmd_takeoff(o_ptr, item); } break; } case TV_NOTE: { note_info_screen(o_ptr); break; } case TV_METAL: { msg_print("To melt down pieces of mithril, take them to a forge and type (,)."); break; } case TV_CHEST: { msg_print("You would need to put it down to open it."); break; } case TV_STAFF: { do_cmd_activate_staff(o_ptr, item); break; } case TV_TRUMPET: { do_cmd_play_instrument(o_ptr, item); break; } case TV_POTION: { do_cmd_quaff_potion(o_ptr, item); break; } case TV_FOOD: { do_cmd_eat_food(o_ptr, item); break; } default: { msg_print("It has no use."); break; } } }