3 * @brief Functions for making use of inventory items.
30 #include "godconduct.h"
32 #include "godpassive.h"
45 #include "player-equip.h"
46 #include "player-stats.h"
54 #include "spl-clouds.h"
55 #include "spl-goditem.h"
56 #include "spl-selfench.h"
57 #include "spl-summoning.h"
58 #include "spl-transloc.h"
59 #include "spl-wpnench.h"
62 #include "stringutil.h"
65 #include "transform.h"
71 static bool _safe_to_remove_or_wear(const item_def &item, bool remove,
74 // Rather messy - we've gathered all the can't-wield logic from wield_weapon()
76 bool can_wield(const item_def *weapon, bool say_reason,
77 bool ignore_temporary_disability, bool unwield, bool only_known)
79 #define SAY(x) {if (say_reason) { x; }}
80 if (!ignore_temporary_disability && you.berserk())
82 SAY(canned_msg(MSG_TOO_BERSERK));
86 if (you.melded[EQ_WEAPON] && unwield)
88 SAY(mpr("Your weapon is melded into your body!"));
92 if (!ignore_temporary_disability && !form_can_wield(you.form))
94 SAY(mpr("You can't wield anything in your present form."));
98 if (!ignore_temporary_disability
100 && is_weapon(*you.weapon())
101 && you.weapon()->cursed())
103 SAY(mprf("You can't unwield your weapon%s!",
104 !unwield ? " to draw a new one" : ""));
108 // If we don't have an actual weapon to check, return now.
112 if (player_mutation_level(MUT_MISSING_HAND)
113 && you.hands_reqd(*weapon) == HANDS_TWO)
115 SAY(mpr("You can't wield that without your missing limb."));
119 for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_WORN; i++)
121 if (you.equip[i] != -1 && &you.inv[you.equip[i]] == weapon)
123 SAY(mpr("You are wearing that object!"));
128 if (!you.could_wield(*weapon, true, true, !say_reason))
131 // All non-weapons only need a shield check.
132 if (weapon->base_type != OBJ_WEAPONS)
134 if (!ignore_temporary_disability && is_shield_incompatible(*weapon))
136 SAY(mpr("You can't wield that with a shield."));
143 bool id_brand = false;
145 if (you.undead_or_demonic() && is_holy_item(*weapon)
146 && (item_type_known(*weapon) || !only_known))
150 mpr("This weapon is holy and will not allow you to wield it.");
154 else if (!ignore_temporary_disability
155 && you.hunger_state < HS_FULL
156 && get_weapon_brand(*weapon) == SPWPN_VAMPIRISM
157 && you.undead_state() == US_ALIVE
159 && (item_type_known(*weapon) || !only_known))
163 mpr("This weapon is vampiric, and you must be Full or above to equip it.");
167 #if TAG_MAJOR_VERSION == 34
168 else if (you.species == SP_DJINNI
169 && get_weapon_brand(*weapon) == SPWPN_ANTIMAGIC
170 && (item_type_known(*weapon) || !only_known))
174 mpr("As you grasp it, you feel your magic disrupted. Quickly, you stop.");
182 auto wwpn = const_cast<item_def*>(weapon);
183 if (!is_artefact(*weapon) && !is_blessed(*weapon)
184 && !item_type_known(*weapon))
186 set_ident_flags(*wwpn, ISFLAG_KNOW_TYPE);
187 if (in_inventory(*weapon))
188 mprf_nocap("%s", weapon->name(DESC_INVENTORY_EQUIP).c_str());
190 else if (is_artefact(*weapon) && !item_type_known(*weapon))
191 artefact_learn_prop(*wwpn, ARTP_BRAND);
195 if (!ignore_temporary_disability && is_shield_incompatible(*weapon))
197 SAY(mpr("You can't wield that with a shield."));
201 // We can wield this weapon. Phew!
208 * @param force If true, don't check weapon inscriptions.
209 * (Assuming the player was already prompted for that.)
211 bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages,
212 bool force, bool show_unwield_msg, bool show_wield_msg,
213 bool adjust_time_taken)
217 canned_msg(MSG_NOTHING_CARRIED);
221 // Look for conditions like berserking that could prevent wielding
223 if (!can_wield(nullptr, true, false, slot == SLOT_BARE_HANDS))
226 int item_slot = 0; // default is 'a'
230 if (item_slot == you.equip[EQ_WEAPON]
231 || you.equip[EQ_WEAPON] == -1
232 && !item_is_wieldable(you.inv[item_slot]))
234 item_slot = 1; // backup is 'b'
237 if (slot != -1) // allow external override
241 // If the swap slot has a bad (but valid) item in it,
242 // the swap will be to bare hands.
243 const bool good_swap = (item_slot == SLOT_BARE_HANDS
244 || item_is_wieldable(you.inv[item_slot]));
246 // Prompt if not using the auto swap command, or if the swap slot
248 if (item_slot != SLOT_BARE_HANDS
249 && (!auto_wield || !you.inv[item_slot].defined() || !good_swap))
253 item_slot = prompt_invent_item(
254 "Wield which item (- for none, * to show all)?",
255 MT_INVLIST, OSEL_WIELD,
256 true, true, true, '-', -1, nullptr, OPER_WIELD);
259 item_slot = SLOT_BARE_HANDS;
262 if (prompt_failed(item_slot))
264 else if (item_slot == you.equip[EQ_WEAPON])
266 mpr("You are already wielding that!");
270 // Reset the warning counter.
271 you.received_weapon_warning = false;
273 if (item_slot == SLOT_BARE_HANDS)
275 if (const item_def* wpn = you.weapon())
277 bool penance = false;
278 // Can we safely unwield this item?
279 if (needs_handle_warning(*wpn, OPER_WIELD, penance))
282 "Really unwield " + wpn->name(DESC_INVENTORY) + "?";
284 prompt += " This could place you under penance!";
286 if (!yesno(prompt.c_str(), false, 'n'))
293 // check if you'd get stat-zeroed
294 if (!_safe_to_remove_or_wear(*wpn, true))
297 if (!unwield_item(show_weff_messages))
300 if (show_unwield_msg)
301 canned_msg(MSG_EMPTY_HANDED_NOW);
303 // Switching to bare hands is extra fast.
304 you.turn_is_over = true;
305 if (adjust_time_taken)
308 you.time_taken /= 10;
312 canned_msg(MSG_EMPTY_HANDED_ALREADY);
317 item_def& new_wpn(you.inv[item_slot]);
319 // Non-auto_wield cases are checked below.
320 if (auto_wield && !force
321 && !check_warning_inscriptions(new_wpn, OPER_WIELD))
326 // Ensure wieldable, stat loss non-fatal
327 if (!can_wield(&new_wpn, true) || !_safe_to_remove_or_wear(new_wpn, false))
330 // Really ensure wieldable, even unknown brand
331 if (!can_wield(&new_wpn, true, false, false, false))
334 // Unwield any old weapon.
337 if (unwield_item(show_weff_messages))
339 // Enable skills so they can be re-disabled later
346 const unsigned int old_talents = your_talents(false).size();
348 // Go ahead and wield the weapon.
349 equip_item(EQ_WEAPON, item_slot, show_weff_messages);
352 mprf_nocap("%s", new_wpn.name(DESC_INVENTORY_EQUIP).c_str());
354 check_item_hint(new_wpn, old_talents);
356 // Time calculations.
357 if (adjust_time_taken)
360 you.wield_change = true;
361 you.m_quiver.on_weapon_changed();
362 you.turn_is_over = true;
367 bool item_is_worn(int inv_slot)
369 for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_WORN; ++i)
370 if (inv_slot == you.equip[i])
377 * Prompt user for carried armour.
379 * @param mesg Title for the prompt
380 * @param index[out] the inventory slot of the item chosen; not initialised
381 * if a valid item was not chosen.
382 * @param oper if equal to OPER_TAKEOFF, only show items relevant to the 'T'
384 * @return whether a valid armour item was chosen.
386 bool armour_prompt(const string & mesg, int *index, operation_types oper)
388 ASSERT(index != nullptr);
391 canned_msg(MSG_NOTHING_CARRIED);
392 else if (you.berserk())
393 canned_msg(MSG_TOO_BERSERK);
396 int selector = OBJ_ARMOUR;
397 if (oper == OPER_TAKEOFF && !Options.equip_unequip)
398 selector = OSEL_WORN_ARMOUR;
399 int slot = prompt_invent_item(mesg.c_str(), MT_INVLIST, selector,
400 true, true, true, 0, -1, nullptr,
403 if (!prompt_failed(slot))
414 void wear_armour(int slot) // slot is for tiles
416 if (you.species == SP_FELID)
418 mpr("You can't wear anything.");
422 if (!form_can_wear())
424 mpr("You can't wear anything in your present form.");
428 int armour_wear_2 = 0;
431 armour_wear_2 = slot;
432 else if (!armour_prompt("Wear which item?", &armour_wear_2, OPER_WEAR))
435 do_wear_armour(armour_wear_2, false);
439 * The number of turns it takes to put on or take off a given piece of armour.
441 * @param item The armour in question.
442 * @return The number of turns it takes to don or doff the item.
444 static int armour_equip_delay(const item_def &item)
450 * Can you wear this item of armour currently?
452 * Ignores whether or not an item is equipped in its slot already.
453 * If the item is Lear's hauberk, some of this comment may be incorrect.
455 * @param item The item. Only the base_type and sub_type really should get
456 * checked, since you_can_wear passes in a dummy item.
457 * @param verbose Whether to print a message about your inability to wear item.
458 * @param ignore_temporary Whether to take into account forms/fishtail. Note
459 * that no matter what this is set to, all mutations
460 * will be taken into account, except for Beastly
461 * Appendage (and then only if this is false).
463 bool can_wear_armour(const item_def &item, bool verbose, bool ignore_temporary)
465 const object_class_type base_type = item.base_type;
466 if (base_type != OBJ_ARMOUR || you.species == SP_FELID)
469 mpr("You can't wear that.");
474 const int sub_type = item.sub_type;
475 const equipment_type slot = get_armour_slot(item);
477 if (you.species == SP_OCTOPODE && slot != EQ_HELMET && slot != EQ_SHIELD)
480 mpr("You can't wear that!");
484 if (species_is_draconian(you.species) && slot == EQ_BODY_ARMOUR)
488 mprf("Your wings%s won't fit in that.", you.mutation[MUT_BIG_WINGS]
489 ? "" : ", even vestigial as they are,");
494 if (sub_type == ARM_NAGA_BARDING || sub_type == ARM_CENTAUR_BARDING)
496 if (you.species == SP_NAGA && sub_type == ARM_NAGA_BARDING
497 || you.species == SP_CENTAUR && sub_type == ARM_CENTAUR_BARDING)
499 if (ignore_temporary || !player_is_shapechanged())
502 mpr("You can wear that only in your normal form.");
505 mpr("You can't wear that!");
509 if (player_mutation_level(MUT_MISSING_HAND) && is_shield(item))
513 if (you.species == SP_OCTOPODE)
514 mpr("You need the rest of your tentacles for walking.");
516 mprf("You'd need another %s to do that!", you.hand_name(false).c_str());
521 if (!ignore_temporary && you.weapon()
523 && is_shield_incompatible(*you.weapon(), &item))
527 if (you.species == SP_OCTOPODE)
528 mpr("You need the rest of your tentacles for walking.");
531 // Singular hand should have already been handled above.
532 mprf("You'd need three %s to do that!",
533 you.hand_name(true).c_str());
539 // Lear's hauberk covers also head, hands and legs.
540 if (is_unrandom_artefact(item, UNRAND_LEAR))
542 if (!player_has_feet(!ignore_temporary))
545 mpr("You have no feet.");
549 if (ignore_temporary)
551 // Hooves and talons were already checked by player_has_feet.
553 if (player_mutation_level(MUT_CLAWS, false) >= 3)
557 mprf("The hauberk won't fit your %s.",
558 you.hand_name(true).c_str());
563 if (player_mutation_level(MUT_HORNS, false) >= 3
564 || player_mutation_level(MUT_ANTENNAE, false) >= 3)
567 mpr("The hauberk won't fit your head.");
573 for (int s = EQ_HELMET; s <= EQ_BOOTS; s++)
575 // No strange race can wear this.
576 const string parts[] = { "head", you.hand_name(true),
577 you.foot_name(true) };
578 COMPILE_CHECK(ARRAYSZ(parts) == EQ_BOOTS - EQ_HELMET + 1);
580 // Auto-disrobing would be nice.
581 if (you.equip[s] != -1)
585 mprf("You'd need your %s free.",
586 parts[s - EQ_HELMET].c_str());
591 if (!get_form()->slot_available(s))
595 mprf("The hauberk won't fit your %s.",
596 parts[s - EQ_HELMET].c_str());
603 else if (slot >= EQ_HELMET && slot <= EQ_BOOTS
605 && player_equip_unrand(UNRAND_LEAR))
607 // The explanation is iffy for loose headgear, especially crowns:
608 // kings loved hooded hauberks, according to portraits.
610 mpr("You can't wear this over your hauberk.");
614 size_type player_size = you.body_size(PSIZE_TORSO, ignore_temporary);
615 int bad_size = fit_armour_size(item, player_size);
616 if (is_unrandom_artefact(item, UNRAND_TALOS))
618 // adjust bad_size for the oversized plate armour
619 // negative means levels too small, positive means levels too large
620 bad_size = SIZE_LARGE - player_size;
627 mprf("This armour is too %s for you!",
628 (bad_size > 0) ? "big" : "small");
634 if (you.form == TRAN_APPENDAGE
636 && slot == beastly_slot(you.attribute[ATTR_APPENDAGE])
637 && you.mutation[you.attribute[ATTR_APPENDAGE]])
639 unwind_var<uint8_t> mutv(you.mutation[you.attribute[ATTR_APPENDAGE]], 0);
640 // disable the mutation then check again
641 return can_wear_armour(item, verbose, ignore_temporary);
644 if (sub_type == ARM_GLOVES)
646 if (you.has_claws(false) == 3)
650 mprf("You can't wear a glove with your huge claw%s!",
651 player_mutation_level(MUT_MISSING_HAND) ? "" : "s");
657 if (sub_type == ARM_BOOTS)
659 if (player_mutation_level(MUT_HOOVES, false) == 3)
662 mpr("You can't wear boots with hooves!");
666 if (you.has_talons(false) == 3)
669 mpr("Boots don't fit your talons!");
673 if (you.species == SP_NAGA
674 #if TAG_MAJOR_VERSION == 34
675 || you.species == SP_DJINNI
680 mpr("You have no legs!");
684 if (!ignore_temporary && you.fishtail)
687 mpr("You don't currently have feet!");
692 if (slot == EQ_HELMET)
694 // Horns 3 & Antennae 3 mutations disallow all headgear
695 if (player_mutation_level(MUT_HORNS, false) == 3)
698 mpr("You can't wear any headgear with your large horns!");
702 if (player_mutation_level(MUT_ANTENNAE, false) == 3)
705 mpr("You can't wear any headgear with your large antennae!");
709 // Soft helmets (caps and wizard hats) always fit, otherwise.
710 if (is_hard_helmet(item))
712 if (player_mutation_level(MUT_HORNS, false))
715 mpr("You can't wear that with your horns!");
719 if (player_mutation_level(MUT_BEAK, false))
722 mpr("You can't wear that with your beak!");
726 if (player_mutation_level(MUT_ANTENNAE, false))
729 mpr("You can't wear that with your antennae!");
733 if (species_is_draconian(you.species))
736 mpr("You can't wear that with your reptilian head.");
740 if (you.species == SP_OCTOPODE)
743 mpr("You can't wear that!");
749 // Can't just use Form::slot_available because of shroom caps.
750 if (!ignore_temporary && !get_form()->can_wear_item(item))
753 mpr("You can't wear that in your present form.");
760 bool do_wear_armour(int item, bool quiet)
762 const item_def &invitem = you.inv[item];
763 if (!invitem.defined())
766 mpr("You don't have any such object.");
770 if (!can_wear_armour(invitem, !quiet, false))
773 const equipment_type slot = get_armour_slot(invitem);
775 if (item == you.equip[EQ_WEAPON])
778 mpr("You are wielding that object!");
782 if (item_is_worn(item))
784 if (Options.equip_unequip)
785 return !takeoff_armour(item);
788 mpr("You're already wearing that object!");
793 bool swapping = false;
794 if ((slot == EQ_CLOAK
799 || slot == EQ_BODY_ARMOUR)
800 && you.equip[slot] != -1)
802 if (!takeoff_armour(you.equip[slot]))
807 you.turn_is_over = true;
809 if (!_safe_to_remove_or_wear(invitem, false))
812 const int delay = armour_equip_delay(invitem);
814 start_delay(DELAY_ARMOUR_ON, delay - (swapping ? 0 : 1), item);
819 bool takeoff_armour(int item)
821 const item_def& invitem = you.inv[item];
823 if (invitem.base_type != OBJ_ARMOUR)
825 mpr("You aren't wearing that!");
831 canned_msg(MSG_TOO_BERSERK);
835 const equipment_type slot = get_armour_slot(invitem);
836 if (item == you.equip[slot] && you.melded[slot])
838 mprf("%s is melded into your body!",
839 invitem.name(DESC_YOUR).c_str());
843 if (!item_is_worn(item))
845 if (Options.equip_unequip)
846 return do_wear_armour(item, true);
849 mpr("You aren't wearing that object!");
854 // If we get here, we're wearing the item.
855 if (invitem.cursed())
857 mprf("%s is stuck to your body!", invitem.name(DESC_YOUR).c_str());
861 if (!_safe_to_remove_or_wear(invitem, true))
873 if (item != you.equip[slot])
875 mpr("You aren't wearing that!");
884 you.turn_is_over = true;
886 const int delay = armour_equip_delay(invitem);
887 start_delay(DELAY_ARMOUR_OFF, delay - 1, item);
892 // Returns a list of possible ring slots.
893 static vector<equipment_type> _current_ring_types()
895 vector<equipment_type> ret;
896 if (you.species == SP_OCTOPODE)
898 for (int i = 0; i < 8; ++i)
900 const equipment_type slot = (equipment_type)(EQ_RING_ONE + i);
902 if (player_mutation_level(MUT_MISSING_HAND)
903 && slot == EQ_RING_EIGHT)
908 if (get_form()->slot_available(slot))
914 if (player_mutation_level(MUT_MISSING_HAND) == 0)
915 ret.push_back(EQ_LEFT_RING);
916 ret.push_back(EQ_RIGHT_RING);
918 if (player_equip_unrand(UNRAND_FINGER_AMULET))
919 ret.push_back(EQ_RING_AMULET);
923 static vector<equipment_type> _current_jewellery_types()
925 vector<equipment_type> ret = _current_ring_types();
926 ret.push_back(EQ_AMULET);
930 static const char _ring_slot_key(equipment_type slot)
934 case EQ_LEFT_RING: return '<';
935 case EQ_RIGHT_RING: return '>';
936 case EQ_RING_AMULET: return '^';
937 case EQ_RING_ONE: return '1';
938 case EQ_RING_TWO: return '2';
939 case EQ_RING_THREE: return '3';
940 case EQ_RING_FOUR: return '4';
941 case EQ_RING_FIVE: return '5';
942 case EQ_RING_SIX: return '6';
943 case EQ_RING_SEVEN: return '7';
944 case EQ_RING_EIGHT: return '8';
946 die("Invalid ring slot");
950 static int _prompt_ring_to_remove(int new_ring)
952 const vector<equipment_type> ring_types = _current_ring_types();
953 vector<char> slot_chars;
954 vector<item_def*> rings;
955 for (auto eq : ring_types)
957 rings.push_back(you.slot_item(eq, true));
958 ASSERT(rings.back());
959 slot_chars.push_back(index_to_letter(rings.back()->link));
965 "You're wearing all the rings you can. Remove which one?");
966 mprf(MSGCH_PROMPT, "(<w>?</w> for menu, <w>Esc</w> to cancel)");
968 // FIXME: Needs TOUCH_UI version
970 for (size_t i = 0; i < rings.size(); i++)
973 const char key = _ring_slot_key(ring_types[i]);
978 m += "</w> or " + rings[i]->name(DESC_INVENTORY);
979 mprf_nocap("%s", m.c_str());
981 flush_prev_message();
983 // Deactivate choice from tile inventory.
984 // FIXME: We need to be able to get the choice (item letter)n
985 // *without* the choice taking action by itself!
986 int eqslot = EQ_NONE;
988 mouse_control mc(MOUSE_MODE_PROMPT);
993 for (size_t i = 0; i < slot_chars.size(); i++)
995 if (c == slot_chars[i]
996 || c == _ring_slot_key(ring_types[i]))
998 eqslot = ring_types[i];
1003 } while (!key_is_escape(c) && c != ' ' && c != '?');
1009 else if (key_is_escape(c) || eqslot == EQ_NONE)
1012 return you.equip[eqslot];
1015 // Checks whether a to-be-worn or to-be-removed item affects
1016 // character stats and whether wearing/removing it could be fatal.
1017 // If so, warns the player, or just returns false if quiet is true.
1018 static bool _safe_to_remove_or_wear(const item_def &item, bool remove, bool quiet)
1020 if (remove && !safe_to_remove(item, quiet))
1026 if (item.base_type == OBJ_JEWELLERY
1027 && item_ident(item, ISFLAG_KNOW_PLUSES))
1029 switch (item.sub_type)
1033 prop_str = item.plus;
1035 case RING_DEXTERITY:
1037 prop_dex = item.plus;
1039 case RING_INTELLIGENCE:
1041 prop_int = item.plus;
1047 else if (item.base_type == OBJ_ARMOUR && item_type_known(item))
1051 case SPARM_STRENGTH:
1054 case SPARM_INTELLIGENCE:
1057 case SPARM_DEXTERITY:
1065 if (is_artefact(item))
1067 prop_str += artefact_known_property(item, ARTP_STRENGTH);
1068 prop_int += artefact_known_property(item, ARTP_INTELLIGENCE);
1069 prop_dex += artefact_known_property(item, ARTP_DEXTERITY);
1078 stat_type red_stat = NUM_STATS;
1079 if (prop_str >= you.strength() && you.strength() > 0)
1080 red_stat = STAT_STR;
1081 else if (prop_int >= you.intel() && you.intel() > 0)
1082 red_stat = STAT_INT;
1083 else if (prop_dex >= you.dex() && you.dex() > 0)
1084 red_stat = STAT_DEX;
1086 if (red_stat == NUM_STATS)
1095 if (item.base_type == OBJ_WEAPONS)
1098 verb = "Remov"; // -ing, not a typo
1102 if (item.base_type == OBJ_WEAPONS)
1108 string prompt = make_stringf("%sing this item will reduce your %s to zero "
1109 "or below. Continue?", verb.c_str(),
1110 stat_desc(red_stat, SD_NAME));
1111 if (!yesno(prompt.c_str(), true, 'n', true, false))
1119 // Checks whether removing an item would cause flight to end and the
1120 // player to fall to their death.
1121 bool safe_to_remove(const item_def &item, bool quiet)
1123 item_info inf = get_item_info(item);
1125 const bool grants_flight =
1126 inf.is_type(OBJ_JEWELLERY, RING_FLIGHT)
1127 || inf.base_type == OBJ_ARMOUR && inf.brand == SPARM_FLYING
1129 && artefact_known_property(inf, ARTP_FLY);
1131 // assumes item can't grant flight twice
1132 const bool removing_ends_flight = you.airborne()
1133 && !you.racial_permanent_flight()
1134 && !you.attribute[ATTR_FLIGHT_UNCANCELLABLE]
1135 && (you.evokable_flight() == 1);
1137 const dungeon_feature_type feat = grd(you.pos());
1139 if (grants_flight && removing_ends_flight
1140 && is_feat_dangerous(feat, false, true))
1143 mpr("Losing flight right now would be fatal!");
1151 // you.inv[ring_slot] is a valid ring.
1152 // EQ_LEFT_RING and EQ_RIGHT_RING are both occupied, and ring_slot is not
1153 // one of the worn rings.
1155 // Does not do amulets.
1156 static bool _swap_rings(int ring_slot)
1158 vector<equipment_type> ring_types = _current_ring_types();
1159 const int num_rings = ring_types.size();
1161 int last_inscribed = 0;
1164 int melded = 0; // Both melded rings and unavailable slots.
1166 bool all_same = true;
1167 item_def* first_ring = nullptr;
1168 for (auto eq : ring_types)
1170 item_def* ring = you.slot_item(eq, true);
1171 if (!you_can_wear(eq, true) || you.melded[eq])
1173 else if (ring != nullptr)
1175 if (first_ring == nullptr)
1179 if (ring->sub_type != first_ring->sub_type
1180 || ring->plus != first_ring->plus
1181 || is_artefact(*ring) || is_artefact(*first_ring))
1189 else if (strstr(ring->inscription.c_str(), "=R"))
1192 last_inscribed = you.equip[eq];
1197 unwanted = you.equip[eq];
1202 // If the only swappable rings are inscribed =R, go ahead and use them.
1203 if (available == 0 && inscribed > 0)
1205 available += inscribed;
1206 unwanted = last_inscribed;
1209 // We can't put a ring on, because we're wearing all cursed ones.
1210 if (melded == num_rings)
1212 // Shouldn't happen, because hogs and bats can't put on jewellery at
1213 // all and thus won't get this far.
1214 mpr("You can't wear that in your present form.");
1217 else if (available == 0)
1219 mprf("You're already wearing %s cursed ring%s!%s",
1220 number_in_words(cursed).c_str(),
1221 (cursed == 1 ? "" : "s"),
1222 (cursed > 2 ? " Isn't that enough for you?" : ""));
1225 // The simple case - only one available ring.
1226 // If the jewellery_prompt option is true, always allow choosing the
1227 // ring slot (even if we still have empty slots).
1228 else if (available == 1 && !Options.jewellery_prompt)
1230 if (!remove_ring(unwanted, false))
1233 // We can't put a ring on without swapping - because we found
1234 // multiple available rings.
1237 // Don't prompt if all the rings are the same.
1238 if (!all_same || Options.jewellery_prompt)
1239 unwanted = _prompt_ring_to_remove(ring_slot);
1248 if (!remove_ring(unwanted, false))
1252 // Put on the new ring.
1253 start_delay(DELAY_JEWELLERY_ON, 1, ring_slot);
1258 static equipment_type _choose_ring_slot()
1263 "Put ring on which %s? (<w>Esc</w> to cancel)", you.hand_name(false).c_str());
1265 const vector<equipment_type> slots = _current_ring_types();
1266 for (auto eq : slots)
1269 const char key = _ring_slot_key(eq);
1274 item_def* ring = you.slot_item(eq, true);
1276 msg += "</w> or " + ring->name(DESC_INVENTORY);
1278 msg += "</w> - no ring";
1280 if (eq == EQ_LEFT_RING)
1282 else if (eq == EQ_RIGHT_RING)
1284 else if (eq == EQ_RING_AMULET)
1286 mprf_nocap("%s", msg.c_str());
1288 flush_prev_message();
1290 equipment_type eqslot = EQ_NONE;
1291 mouse_control mc(MOUSE_MODE_PROMPT);
1296 for (auto eq : slots)
1298 if (c == _ring_slot_key(eq)
1299 || (you.slot_item(eq, true)
1300 && c == index_to_letter(you.slot_item(eq, true)->link)))
1307 } while (!key_is_escape(c) && c != ' ');
1314 static bool _puton_item(int item_slot, bool prompt_slot)
1316 item_def& item = you.inv[item_slot];
1318 for (int eq = EQ_LEFT_RING; eq < NUM_EQUIP; eq++)
1319 if (item_slot == you.equip[eq])
1321 // "Putting on" an equipped item means taking it off.
1322 if (Options.equip_unequip)
1323 return !remove_ring(item_slot);
1326 mpr("You're already wearing that object!");
1331 if (item_slot == you.equip[EQ_WEAPON])
1333 mpr("You are wielding that object.");
1337 if (item.base_type != OBJ_JEWELLERY)
1339 mpr("You can only put on jewellery.");
1343 const bool is_amulet = jewellery_is_amulet(item);
1345 if (is_amulet && !you_can_wear(EQ_AMULET, true)
1346 || !is_amulet && !you_can_wear(EQ_RINGS, true))
1348 mpr("You can't wear that in your present form.");
1352 const vector<equipment_type> ring_types = _current_ring_types();
1354 if (!is_amulet) // i.e. it's a ring
1356 bool need_swap = true;
1357 for (auto eq : ring_types)
1359 if (!you.slot_item(eq, true))
1367 return _swap_rings(item_slot);
1369 else if (you.slot_item(EQ_AMULET, true))
1371 // Remove the previous one.
1372 if (!remove_ring(you.equip[EQ_AMULET], true))
1375 // Check for stat loss.
1376 if (!_safe_to_remove_or_wear(item, false))
1379 // Put on the new amulet.
1380 start_delay(DELAY_JEWELLERY_ON, 1, item_slot);
1382 // Assume it's going to succeed.
1386 // Check for stat loss.
1387 if (!_safe_to_remove_or_wear(item, false))
1390 equipment_type hand_used = EQ_NONE;
1393 hand_used = EQ_AMULET;
1394 else if (prompt_slot)
1396 // Prompt for a slot, even if we have empty ring slots.
1397 hand_used = _choose_ring_slot();
1399 if (hand_used == EQ_NONE)
1404 // Allow swapping out a ring.
1405 else if (you.slot_item(hand_used, true))
1407 if (!remove_ring(you.equip[hand_used], false))
1410 start_delay(DELAY_JEWELLERY_ON, 1, item_slot);
1416 for (auto eq : ring_types)
1418 if (!you.slot_item(eq, true))
1426 const unsigned int old_talents = your_talents(false).size();
1428 // Actually equip the item.
1429 equip_item(hand_used, item_slot);
1431 check_item_hint(you.inv[item_slot], old_talents);
1432 #ifdef USE_TILE_LOCAL
1433 if (your_talents(false).size() != old_talents)
1435 tiles.layout_statcol();
1440 // Putting on jewellery is fast.
1441 you.time_taken /= 2;
1442 you.turn_is_over = true;
1447 bool puton_ring(int slot, bool allow_prompt)
1451 if (inv_count() < 1)
1453 canned_msg(MSG_NOTHING_CARRIED);
1459 canned_msg(MSG_TOO_BERSERK);
1467 item_slot = prompt_invent_item("Put on which piece of jewellery?",
1468 MT_INVLIST, OBJ_JEWELLERY, true, true,
1469 true, 0, -1, nullptr, OPER_PUTON);
1472 if (prompt_failed(item_slot))
1475 bool prompt = allow_prompt ? Options.jewellery_prompt : false;
1477 return _puton_item(item_slot, prompt);
1480 bool remove_ring(int slot, bool announce)
1482 equipment_type hand_used = EQ_NONE;
1484 bool has_jewellery = false;
1485 bool has_melded = false;
1486 const vector<equipment_type> jewellery_slots = _current_jewellery_types();
1488 for (auto eq : jewellery_slots)
1490 if (you.slot_item(eq))
1492 if (has_jewellery || Options.jewellery_prompt)
1494 // At least one other piece, which means we'll have to ask
1495 hand_used = EQ_NONE;
1500 has_jewellery = true;
1502 else if (you.melded[eq])
1509 mpr("You aren't wearing any unmelded rings or amulets.");
1511 mpr("You aren't wearing any rings or amulets.");
1518 canned_msg(MSG_TOO_BERSERK);
1522 if (hand_used == EQ_NONE)
1525 (slot == -1)? prompt_invent_item("Remove which piece of jewellery?",
1527 OBJ_JEWELLERY, true, true, true,
1528 0, -1, nullptr, OPER_REMOVE,
1532 if (prompt_failed(equipn))
1535 hand_used = item_equip_slot(you.inv[equipn]);
1536 if (hand_used == EQ_NONE)
1538 mpr("You aren't wearing that.");
1541 else if (you.inv[equipn].base_type != OBJ_JEWELLERY)
1543 mpr("That isn't a piece of jewellery.");
1548 if (you.equip[hand_used] == -1)
1550 mpr("I don't think you really meant that.");
1553 else if (you.melded[hand_used])
1555 mpr("You can't take that off while it's melded.");
1558 else if (hand_used == EQ_AMULET
1559 && you.equip[EQ_RING_AMULET] != -1)
1561 // This can be removed in the future if more ring amulets are added.
1562 ASSERT(player_equip_unrand(UNRAND_FINGER_AMULET));
1564 mpr("The amulet cannot be taken off without first removing the ring!");
1568 if (!check_warning_inscriptions(you.inv[you.equip[hand_used]],
1575 if (you.inv[you.equip[hand_used]].cursed())
1579 mprf("%s is stuck to you!",
1580 you.inv[you.equip[hand_used]].name(DESC_YOUR).c_str());
1583 mpr("It's stuck to you!");
1585 set_ident_flags(you.inv[you.equip[hand_used]], ISFLAG_KNOW_CURSE);
1589 ring_wear_2 = you.equip[hand_used];
1592 if (!_safe_to_remove_or_wear(you.inv[ring_wear_2], true))
1595 mprf("You remove %s.", you.inv[ring_wear_2].name(DESC_YOUR).c_str());
1596 #ifdef USE_TILE_LOCAL
1597 const unsigned int old_talents = your_talents(false).size();
1599 unequip_item(hand_used);
1600 #ifdef USE_TILE_LOCAL
1601 if (your_talents(false).size() != old_talents)
1603 tiles.layout_statcol();
1608 you.time_taken /= 2;
1609 you.turn_is_over = true;
1614 void prompt_inscribe_item()
1616 if (inv_count() < 1)
1618 mpr("You don't have anything to inscribe.");
1622 int item_slot = prompt_invent_item("Inscribe which item?",
1623 MT_INVLIST, OSEL_ANY);
1625 if (prompt_failed(item_slot))
1628 inscribe_item(you.inv[item_slot]);
1631 static bool _check_blood_corpses_on_ground()
1633 for (stack_iterator si(you.pos(), true); si; ++si)
1635 if (si->is_type(OBJ_CORPSES, CORPSE_BODY)
1636 && mons_has_blood(si->mon_type))
1644 static void _vampire_corpse_help()
1646 if (you.species != SP_VAMPIRE)
1649 if (_check_blood_corpses_on_ground())
1650 mpr("Use <w>e</w> to drain blood from corpses.");
1653 void drink(int slot)
1655 if (you_foodless(true))
1657 mpr("You can't drink.");
1661 if (inv_count() == 0)
1663 canned_msg(MSG_NOTHING_CARRIED);
1664 _vampire_corpse_help();
1670 canned_msg(MSG_TOO_BERSERK);
1674 if (you.form == TRAN_BAT)
1676 canned_msg(MSG_PRESENT_FORM);
1677 _vampire_corpse_help();
1681 if (you.duration[DUR_NO_POTIONS])
1683 mpr("You cannot drink potions in your current state!");
1689 slot = prompt_invent_item("Drink which item?",
1690 MT_INVLIST, OBJ_POTIONS,
1691 true, true, true, 0, -1, nullptr,
1693 if (prompt_failed(slot))
1695 _vampire_corpse_help();
1700 item_def& potion = you.inv[slot];
1702 if (potion.base_type != OBJ_POTIONS)
1704 if (you.species == SP_VAMPIRE && potion.base_type == OBJ_CORPSES)
1707 mpr("You can't drink that!");
1711 const bool alreadyknown = item_type_known(potion);
1713 if (alreadyknown && is_bad_item(potion, true))
1715 canned_msg(MSG_UNTHINKING_ACT);
1719 // The "> 1" part is to reduce the amount of times that Xom is
1720 // stimulated when you are a low-level 1 trying your first unknown
1721 // potions on monsters.
1722 const bool dangerous = (player_in_a_dangerous_place()
1723 && you.experience_level > 1);
1724 potion_type pot_type = (potion_type)potion.sub_type;
1726 if (player_under_penance(GOD_GOZAG) && one_chance_in(3))
1728 simple_god_message(" petitions for your drink to fail.", GOD_GOZAG);
1729 you.turn_is_over = true;
1733 if (!quaff_potion(potion))
1736 if (!alreadyknown && dangerous)
1738 // Xom loves it when you drink an unknown potion and there is
1739 // a dangerous monster nearby...
1740 xom_is_stimulated(200);
1742 if (is_blood_potion(potion))
1744 // Always drink oldest potion.
1745 remove_oldest_perishable_item(potion);
1747 dec_inv_item_quantity(slot, 1);
1748 count_action(CACT_USE, OBJ_POTIONS);
1749 auto_assign_item_slot(potion);
1750 you.turn_is_over = true;
1751 // This got deferred from PotionExperience::effect to prevent SIGHUP abuse.
1752 if (pot_type == POT_EXPERIENCE)
1756 // XXX: there's probably a nicer way of doing this.
1757 bool god_hates_brand(const int brand)
1759 if (is_good_god(you.religion)
1760 && (brand == SPWPN_DRAINING
1761 || brand == SPWPN_VAMPIRISM
1762 || brand == SPWPN_CHAOS
1763 || brand == SPWPN_PAIN))
1768 if (you_worship(GOD_DITHMENOS)
1769 && (brand == SPWPN_FLAMING
1770 || brand == SPWPN_CHAOS))
1775 if (you_worship(GOD_SHINING_ONE) && brand == SPWPN_VENOM)
1778 if (you_worship(GOD_CHEIBRIADOS) && (brand == SPWPN_CHAOS
1779 || brand == SPWPN_SPEED))
1784 if (you_worship(GOD_YREDELEMNUL) && brand == SPWPN_HOLY_WRATH)
1790 static void _rebrand_weapon(item_def& wpn)
1792 if (&wpn == you.weapon() && you.duration[DUR_WEAPON_BRAND])
1793 end_weapon_brand(wpn);
1794 int old_brand = get_weapon_brand(wpn);
1795 int new_brand = old_brand;
1797 // now try and find an appropriate brand
1798 while (old_brand == new_brand || god_hates_brand(new_brand))
1800 if (is_range_weapon(wpn))
1802 new_brand = random_choose_weighted(
1808 5, SPWPN_ELECTROCUTION,
1814 new_brand = random_choose_weighted(
1820 15, SPWPN_ELECTROCUTION,
1821 12, SPWPN_PROTECTION,
1828 set_item_ego_type(wpn, OBJ_WEAPONS, new_brand);
1832 static void _brand_weapon(item_def &wpn)
1834 you.wield_change = true;
1836 const string itname = wpn.name(DESC_YOUR);
1838 _rebrand_weapon(wpn);
1840 bool success = true;
1841 colour_t flash_colour = BLACK;
1843 switch (get_weapon_brand(wpn))
1846 flash_colour = YELLOW;
1847 mprf("%s emits a brilliant flash of light!",itname.c_str());
1850 case SPWPN_PROTECTION:
1851 flash_colour = YELLOW;
1852 mprf("%s projects an invisible shield of force!",itname.c_str());
1856 flash_colour = YELLOW;
1857 mprf("%s emits a repelling force!",itname.c_str());
1862 mprf("%s is engulfed in flames!", itname.c_str());
1865 case SPWPN_FREEZING:
1866 flash_colour = LIGHTCYAN;
1867 mprf("%s is covered with a thin layer of ice!", itname.c_str());
1870 case SPWPN_DRAINING:
1871 flash_colour = DARKGREY;
1872 mprf("%s craves living souls!", itname.c_str());
1875 case SPWPN_VAMPIRISM:
1876 flash_colour = DARKGREY;
1877 mprf("%s thirsts for the lives of mortals!", itname.c_str());
1881 flash_colour = GREEN;
1882 mprf("%s drips with poison.", itname.c_str());
1885 case SPWPN_ELECTROCUTION:
1886 flash_colour = LIGHTCYAN;
1887 mprf("%s crackles with electricity.", itname.c_str());
1891 flash_colour = random_colour();
1892 mprf("%s erupts in a glittering mayhem of colour.", itname.c_str());
1902 item_set_appearance(wpn);
1903 // Message would spoil this even if we didn't identify.
1904 set_ident_flags(wpn, ISFLAG_KNOW_TYPE);
1905 mprf_nocap("%s", wpn.name(DESC_INVENTORY_EQUIP).c_str());
1906 // Might be rebranding to/from protection or evasion.
1907 you.redraw_armour_class = true;
1908 you.redraw_evasion = true;
1909 // Might be removing antimagic.
1911 flash_view_delay(UA_PLAYER, flash_colour, 300);
1916 static object_selector _enchant_selector(scroll_type scroll)
1918 if (scroll == SCR_BRAND_WEAPON)
1919 return OSEL_BRANDABLE_WEAPON;
1920 else if (scroll == SCR_ENCHANT_WEAPON)
1921 return OSEL_ENCHANTABLE_WEAPON;
1922 die("Invalid scroll type %d for _enchant_selector", (int)scroll);
1925 // Returns nullptr if no weapon was chosen.
1926 static item_def* _scroll_choose_weapon(bool alreadyknown, const string &pre_msg,
1930 const bool branding = scroll == SCR_BRAND_WEAPON;
1931 const object_selector selector = _enchant_selector(scroll);
1935 item_slot = prompt_invent_item(branding ? "Brand which weapon?"
1936 : "Enchant which weapon?",
1937 MT_INVLIST, selector,
1939 // The scroll is used up if we didn't know what it was originally.
1940 if (item_slot == PROMPT_NOTHING)
1943 if (item_slot == PROMPT_ABORT)
1946 || crawl_state.seen_hups
1947 || yesno("Really abort (and waste the scroll)?", false, 0))
1956 item_def* wpn = &you.inv[item_slot];
1957 if (!item_is_selected(*wpn, selector))
1959 mpr("Choose a valid weapon, or Esc to abort.");
1964 // Now we're definitely using up the scroll.
1971 // Returns true if the scroll is used up.
1972 static bool _handle_brand_weapon(bool alreadyknown, const string &pre_msg)
1974 item_def* weapon = _scroll_choose_weapon(alreadyknown, pre_msg,
1977 return !alreadyknown;
1979 _brand_weapon(*weapon);
1983 bool enchant_weapon(item_def &wpn, bool quiet)
1985 bool success = false;
1987 // Get item name now before changing enchantment.
1988 string iname = wpn.name(DESC_YOUR);
1991 && !is_artefact(wpn)
1992 && wpn.base_type == OBJ_WEAPONS
1993 && wpn.plus < MAX_WPN_ENCHANT)
1998 mprf("%s glows red for a moment.", iname.c_str());
2001 if (!success && !quiet)
2002 canned_msg(MSG_NOTHING_HAPPENS);
2005 you.wield_change = true;
2010 // Returns true if the scroll is used up.
2011 static bool _identify(bool alreadyknown, const string &pre_msg)
2016 if (item_slot == -1)
2018 item_slot = prompt_invent_item(
2019 "Identify which item? (\\ to view known items)",
2020 MT_INVLIST, OSEL_UNIDENT, true, true, false, 0,
2021 -1, nullptr, OPER_ANY, true);
2024 if (item_slot == PROMPT_NOTHING)
2025 return !alreadyknown;
2027 if (item_slot == PROMPT_ABORT)
2030 || crawl_state.seen_hups
2031 || yesno("Really abort (and waste the scroll)?", false, 0))
2034 return !alreadyknown;
2043 item_def& item(you.inv[item_slot]);
2044 if (fully_identified(item)
2045 && (!is_deck(item) || top_card_is_known(item)))
2047 mpr("Choose an unidentified item, or Esc to abort.");
2056 set_ident_type(item, true);
2057 set_ident_flags(item, ISFLAG_IDENT_MASK);
2059 if (is_deck(item) && !top_card_is_known(item))
2060 deck_identify_first(item_slot);
2062 // Output identified item.
2063 mprf_nocap("%s", item.name(DESC_INVENTORY_EQUIP).c_str());
2064 if (item_slot == you.equip[EQ_WEAPON])
2065 you.wield_change = true;
2067 if (item.is_type(OBJ_JEWELLERY, AMU_INACCURACY)
2068 && item_slot == you.equip[EQ_AMULET]
2069 && !item_known_cursed(item))
2071 learned_something_new(HINT_INACCURACY);
2074 auto_assign_item_slot(item);
2079 static bool _handle_enchant_weapon(bool alreadyknown, const string &pre_msg)
2081 item_def* weapon = _scroll_choose_weapon(alreadyknown, pre_msg,
2082 SCR_ENCHANT_WEAPON);
2084 return !alreadyknown;
2086 enchant_weapon(*weapon, false);
2090 bool enchant_armour(int &ac_change, bool quiet, item_def &arm)
2092 ASSERT(arm.defined());
2093 ASSERT(arm.base_type == OBJ_ARMOUR);
2097 // Cannot be enchanted.
2098 if (!is_enchantable_armour(arm))
2101 canned_msg(MSG_NOTHING_HAPPENS);
2105 // Turn hides into mails where applicable.
2106 // NOTE: It is assumed that armour which changes in this way does
2107 // not change into a form of armour with a different evasion modifier.
2108 if (armour_is_hide(arm, false))
2112 mprf("%s glows purple and changes!",
2113 arm.name(DESC_YOUR).c_str());
2116 ac_change = property(arm, PARM_AC);
2118 ac_change = property(arm, PARM_AC) - ac_change;
2120 // No additional enchantment.
2124 // Output message before changing enchantment and curse status.
2127 mprf("%s glows green for a moment.",
2128 arm.name(DESC_YOUR).c_str());
2137 static int _handle_enchant_armour(bool alreadyknown, const string &pre_msg)
2142 if (item_slot == -1)
2144 item_slot = prompt_invent_item("Enchant which item?", MT_INVLIST,
2145 OSEL_ENCH_ARM, true, true, false);
2148 if (item_slot == PROMPT_NOTHING)
2149 return alreadyknown ? -1 : 0;
2151 if (item_slot == PROMPT_ABORT)
2154 || crawl_state.seen_hups
2155 || yesno("Really abort (and waste the scroll)?", false, 0))
2158 return alreadyknown ? -1 : 0;
2167 item_def& arm(you.inv[item_slot]);
2169 if (!is_enchantable_armour(arm, true))
2171 mpr("Choose some type of armour to enchant, or Esc to abort.");
2178 // Okay, we may actually (attempt to) enchant something.
2183 bool result = enchant_armour(ac_change, false, arm);
2186 you.redraw_armour_class = true;
2188 return result ? 1 : 0;
2195 void random_uselessness()
2197 ASSERT(!crawl_state.game_is_arena());
2203 mprf("The dust glows %s!", weird_glowing_colour().c_str());
2209 mprf("%s glows %s for a moment.",
2210 you.weapon()->name(DESC_YOUR).c_str(),
2211 weird_glowing_colour().c_str());
2215 mpr(you.hands_act("glow", weird_glowing_colour()
2216 + " for a moment."));
2221 if (you.species == SP_MUMMY)
2222 mpr("Your bandages flutter.");
2223 else // if (you.can_smell())
2224 mprf("You smell %s.", weird_smell().c_str());
2228 mpr("You experience a momentary feeling of inescapable doom!");
2232 if (player_mutation_level(MUT_BEAK) || one_chance_in(3))
2233 mpr("Your brain hurts!");
2234 else if (you.species == SP_MUMMY || coinflip())
2235 mpr("Your ears itch!");
2237 mpr("Your nose twitches suddenly!");
2241 mprf(MSGCH_SOUND, "You hear the tinkle of a tiny bell.");
2242 noisy(2, you.pos());
2243 cast_summon_butterflies(100);
2247 mprf(MSGCH_SOUND, "You hear %s.", weird_sound().c_str());
2248 noisy(2, you.pos());
2253 static void _handle_read_book(int item_slot)
2257 canned_msg(MSG_TOO_BERSERK);
2261 if (you.duration[DUR_BRAINLESS])
2263 mpr("Reading books requires mental cohesion, which you lack.");
2267 item_def& book(you.inv[item_slot]);
2268 ASSERT(book.sub_type != BOOK_MANUAL);
2270 #if TAG_MAJOR_VERSION == 34
2271 if (book.sub_type == BOOK_BUGGY_DESTRUCTION)
2273 mpr("This item has been removed, sorry!");
2281 static void _vulnerability_scroll()
2283 mon_enchant lowered_mr(ENCH_LOWERED_MR, 1, &you, 400);
2285 // Go over all creatures in LOS.
2286 for (radius_iterator ri(you.pos(), LOS_NO_TRANS); ri; ++ri)
2288 if (monster* mon = monster_at(*ri))
2290 // If relevant, monsters have their MR halved.
2291 if (!mons_immune_magic(mon))
2292 mon->add_ench(lowered_mr);
2294 // Annoying but not enough to turn friendlies against you.
2295 if (!mon->wont_attack())
2296 behaviour_event(mon, ME_ANNOY, &you);
2300 you.set_duration(DUR_LOWERED_MR, 40, 0, "Magic quickly surges around you.");
2303 static bool _is_cancellable_scroll(scroll_type scroll)
2305 return scroll == SCR_IDENTIFY
2306 || scroll == SCR_BLINKING
2307 || scroll == SCR_RECHARGING
2308 || scroll == SCR_ENCHANT_ARMOUR
2309 || scroll == SCR_AMNESIA
2310 || scroll == SCR_REMOVE_CURSE
2311 #if TAG_MAJOR_VERSION == 34
2312 || scroll == SCR_CURSE_ARMOUR
2313 || scroll == SCR_CURSE_JEWELLERY
2315 || scroll == SCR_BRAND_WEAPON
2316 || scroll == SCR_ENCHANT_WEAPON
2317 || scroll == SCR_MAGIC_MAPPING;
2321 * Is the player currently able to use the 'r' command (to read books or
2322 * scrolls). Being too berserk, confused, or having no reading material will
2325 * Prints corresponding messages. (Thanks, canned_msg().)
2327 bool player_can_read()
2331 canned_msg(MSG_TOO_BERSERK);
2337 canned_msg(MSG_TOO_CONFUSED);
2341 if (inv_count() < 1)
2343 canned_msg(MSG_NOTHING_CARRIED);
2351 * If the player has no items matching the given selector, give an appropriate
2352 * response to print. Otherwise, if they do have such items, return the empty
2355 static string _no_items_reason(object_selector type)
2357 if (!any_items_of_type(type))
2358 return no_selectables_message(type);
2363 * If the player is unable to (r)ead the item in the given slot, return the
2364 * reason why. Otherwise (if they are able to read it), returns "", the empty
2367 string cannot_read_item_reason(const item_def &item)
2369 // can read books, except for manuals...
2370 if (item.base_type == OBJ_BOOKS)
2372 if (item.sub_type == BOOK_MANUAL)
2373 return "You can't read that!";
2377 // and scrolls - but nothing else.
2378 if (item.base_type != OBJ_SCROLLS)
2379 return "You can't read that!";
2381 // the below only applies to scrolls. (it's easier to read books, since
2382 // that's just a UI/strategic thing.)
2384 if (silenced(you.pos()))
2385 return "Magic scrolls do not work when you're silenced!";
2388 if (you.duration[DUR_WATER_HOLD] && !you.res_water_drowning())
2389 return "You cannot read scrolls while unable to breathe!";
2392 if (you.duration[DUR_NO_SCROLLS])
2393 return "You cannot read scrolls in your current state!";
2395 #if TAG_MAJOR_VERSION == 34
2396 // Prevent hot lava orcs reading scrolls
2397 if (you.species == SP_LAVA_ORC && temperature_effect(LORC_NO_SCROLLS))
2398 return "You'd burn any scroll you tried to read!";
2401 // don't waste the player's time reading known scrolls in situations where
2402 // they'd be useless
2404 if (!item_type_known(item))
2407 switch (item.sub_type)
2410 case SCR_TELEPORTATION:
2411 return you.no_tele_reason(false, item.sub_type == SCR_BLINKING);
2414 if (you.spell_no == 0)
2415 return "You have no spells to forget!";
2418 #if TAG_MAJOR_VERSION == 34
2419 case SCR_CURSE_WEAPON:
2421 return "This scroll only affects a wielded weapon!";
2423 // assumption: wielded weapons always have their curse & brand known
2424 if (you.weapon()->cursed())
2425 return "Your weapon is already cursed!";
2427 if (get_weapon_brand(*you.weapon()) == SPWPN_HOLY_WRATH)
2428 return "Holy weapons cannot be cursed!";
2432 case SCR_ENCHANT_ARMOUR:
2433 return _no_items_reason(OSEL_ENCH_ARM);
2435 case SCR_ENCHANT_WEAPON:
2436 return _no_items_reason(OSEL_ENCHANTABLE_WEAPON);
2439 return _no_items_reason(OSEL_UNIDENT);
2441 case SCR_RECHARGING:
2442 return _no_items_reason(OSEL_RECHARGE);
2444 case SCR_REMOVE_CURSE:
2445 return _no_items_reason(OSEL_CURSED_WORN);
2447 #if TAG_MAJOR_VERSION == 34
2448 case SCR_CURSE_ARMOUR:
2449 return _no_items_reason(OSEL_UNCURSED_WORN_ARMOUR);
2451 case SCR_CURSE_JEWELLERY:
2452 return _no_items_reason(OSEL_UNCURSED_WORN_JEWELLERY);
2461 * Check to see if the player can read the item in the given slot, and if so,
2462 * reads it. (Examining books, evoking the tome of destruction, & using
2465 * @param slot The slot of the item in the player's inventory. If -1, the
2466 * player is prompted to choose a slot.
2470 if (!player_can_read())
2473 int item_slot = (slot != -1) ? slot
2474 : prompt_invent_item("Read which item?",
2477 true, true, true, 0, -1,
2478 nullptr, OPER_READ);
2480 if (prompt_failed(item_slot))
2483 const item_def& scroll = you.inv[item_slot];
2484 const string failure_reason = cannot_read_item_reason(scroll);
2485 if (!failure_reason.empty())
2487 mprf(MSGCH_PROMPT, "%s", failure_reason.c_str());
2491 if (scroll.base_type == OBJ_BOOKS)
2493 _handle_read_book(item_slot);
2497 // need to handle this before we waste time (with e.g. blurryvis)
2498 if (scroll.sub_type == SCR_BLINKING && item_type_known(scroll)
2500 && !yesno("Your blink will be uncontrolled - continue anyway?",
2507 if (player_mutation_level(MUT_BLURRY_VISION)
2508 && !i_feel_safe(false, false, true)
2509 && !yesno("Really read with blurry vision while enemies are nearby?",
2516 // Ok - now we FINALLY get to read a scroll !!! {dlb}
2517 you.turn_is_over = true;
2519 if (you.duration[DUR_BRAINLESS] && !one_chance_in(5))
2521 mpr("You almost manage to decipher the scroll,"
2522 " but fail in this attempt.");
2526 // if we have blurry vision, we need to start a delay before the actual
2527 // scroll effect kicks in.
2528 if (player_mutation_level(MUT_BLURRY_VISION))
2530 // takes 0.5, 1, 2 extra turns
2531 const int turns = max(1, player_mutation_level(MUT_BLURRY_VISION) - 1);
2532 start_delay(DELAY_BLURRY_SCROLL, turns, item_slot);
2533 if (player_mutation_level(MUT_BLURRY_VISION) == 1)
2534 you.time_taken /= 2;
2537 read_scroll(item_slot);
2541 * Read the provided scroll.
2543 * Does NOT check whether the player can currently read, whether the scroll is
2544 * currently useless, etc. Likewise doesn't handle blurry vision, setting
2545 * you.turn_is_over, and other externals. DOES destroy one scroll, unless the
2546 * player chooses to cancel at the last moment.
2548 * @param slot The slot of the item in the player's inventory.
2550 void read_scroll(int item_slot)
2552 item_def& scroll = you.inv[item_slot];
2553 const scroll_type which_scroll = static_cast<scroll_type>(scroll.sub_type);
2554 const int prev_quantity = scroll.quantity;
2555 const bool alreadyknown = item_type_known(scroll);
2557 // For cancellable scrolls leave printing this message to their
2558 // respective functions.
2559 const string pre_succ_msg =
2560 make_stringf("As you read the %s, it crumbles to dust.",
2561 scroll.name(DESC_QUALNAME).c_str());
2562 if (!_is_cancellable_scroll(which_scroll))
2565 // Actual removal of scroll done afterwards. -- bwr
2568 const bool dangerous = player_in_a_dangerous_place();
2570 // ... but some scrolls may still be cancelled afterwards.
2571 bool cancel_scroll = false;
2572 bool bad_effect = false; // for Xom: result is bad (or at least dangerous)
2574 switch (which_scroll)
2576 case SCR_RANDOM_USELESSNESS:
2577 random_uselessness();
2582 const string reason = you.no_tele_reason(true, true);
2583 if (!reason.empty())
2590 const bool safely_cancellable
2591 = alreadyknown && !player_mutation_level(MUT_BLURRY_VISION);
2593 if (player_has_orb())
2595 mprf(MSGCH_ORB, "The Orb prevents control of your translocation!");
2596 uncontrolled_blink();
2600 cancel_scroll = (cast_controlled_blink(false, safely_cancellable)
2601 == SPRET_ABORT) && alreadyknown;
2605 mpr(pre_succ_msg); // ordering is iffy but w/e
2609 case SCR_TELEPORTATION:
2613 case SCR_REMOVE_CURSE:
2617 remove_curse(false);
2620 cancel_scroll = !remove_curse(true, pre_succ_msg);
2623 case SCR_ACQUIREMENT:
2624 mpr("This is a scroll of acquirement!");
2625 // included in default force_more_message
2626 // Identify it early in case the player checks the '\' screen.
2627 set_ident_type(scroll, true);
2628 run_uncancel(UNC_ACQUIREMENT, AQ_SCROLL);
2632 mpr("You assume a fearsome visage.");
2633 mass_enchantment(ENCH_FEAR, 1000);
2637 noisy(25, you.pos(), "You hear a loud clanging noise!");
2641 cast_shadow_creatures(MON_SUMM_SCROLL);
2645 mpr("The scroll dissolves into smoke.");
2646 big_cloud(random_smoke_type(), &you, you.pos(), 50, 8 + random2(8));
2649 case SCR_MAGIC_MAPPING:
2650 if (alreadyknown && !is_map_persistent())
2652 cancel_scroll = true;
2653 mpr("It would have no effect in this place.");
2657 magic_mapping(500, 100, false);
2661 torment(&you, TORMENT_SCROLL, you.pos());
2663 // This is only naughty if you know you're doing it.
2664 did_god_conduct(DID_NECROMANCY, 10, item_type_known(scroll));
2668 case SCR_IMMOLATION:
2670 // Dithmenos hates trying to play with fire, even if it does nothing.
2671 did_god_conduct(DID_FIRE, 2 + random2(3), item_type_known(scroll));
2673 bool had_effect = false;
2674 for (monster_near_iterator mi(you.pos(), LOS_NO_TRANS); mi; ++mi)
2676 if (mons_immune_magic(*mi) || mi->is_summoned())
2679 if (mi->add_ench(mon_enchant(ENCH_INNER_FLAME, 0, &you)))
2684 mpr("The creatures around you are filled with an inner flame!");
2686 mpr("The air around you briefly surges with heat, but it dissipates.");
2692 #if TAG_MAJOR_VERSION == 34
2693 case SCR_CURSE_WEAPON:
2695 // Not you.weapon() because we want to handle melded weapons too.
2696 item_def * const weapon = you.slot_item(EQ_WEAPON, true);
2697 if (!weapon || !is_weapon(*weapon) || weapon->cursed())
2699 bool plural = false;
2700 const string weapon_name =
2701 weapon ? weapon->name(DESC_YOUR)
2702 : "Your " + you.hand_name(true, &plural);
2703 mprf("%s very briefly gain%s a black sheen.",
2704 weapon_name.c_str(), plural ? "" : "s");
2708 // Also sets wield_change.
2709 do_curse_item(*weapon, false);
2710 learned_something_new(HINT_YOU_CURSED);
2717 case SCR_ENCHANT_WEAPON:
2721 mpr("It is a scroll of enchant weapon.");
2722 // included in default force_more_message (to show it before menu)
2725 cancel_scroll = !_handle_enchant_weapon(alreadyknown, pre_succ_msg);
2728 case SCR_BRAND_WEAPON:
2732 mpr("It is a scroll of brand weapon.");
2733 // included in default force_more_message (to show it before menu)
2736 cancel_scroll = !_handle_brand_weapon(alreadyknown, pre_succ_msg);
2743 mpr("It is a scroll of identify.");
2744 // included in default force_more_message (to show it before menu)
2745 // Do this here so it doesn't turn up in the ID menu.
2746 set_ident_type(scroll, true);
2748 cancel_scroll = !_identify(alreadyknown, pre_succ_msg);
2751 case SCR_RECHARGING:
2755 mpr("It is a scroll of recharging.");
2756 // included in default force_more_message (to show it before menu)
2758 cancel_scroll = (recharge_wand(alreadyknown, pre_succ_msg) == -1);
2761 case SCR_ENCHANT_ARMOUR:
2765 mpr("It is a scroll of enchant armour.");
2766 // included in default force_more_message (to show it before menu)
2769 (_handle_enchant_armour(alreadyknown, pre_succ_msg) == -1);
2772 #if TAG_MAJOR_VERSION == 34
2773 // Should always be identified by Ashenzari.
2774 case SCR_CURSE_ARMOUR:
2775 case SCR_CURSE_JEWELLERY:
2777 const bool armour = which_scroll == SCR_CURSE_ARMOUR;
2778 cancel_scroll = !curse_item(armour, pre_succ_msg);
2785 holy_word(100, HOLY_WORD_SCROLL, you.pos(), false, &you);
2787 // This is always naughty, even if you didn't affect anyone.
2788 // Don't speak those foul holy words even in jest!
2789 did_god_conduct(DID_HOLY, 10, item_type_known(scroll));
2797 case SCR_VULNERABILITY:
2798 _vulnerability_scroll();
2805 mpr("It is a scroll of amnesia.");
2806 // included in default force_more_message (to show it before menu)
2808 if (you.spell_no == 0)
2809 mpr("You feel forgetful for a moment.");
2810 else if (!alreadyknown)
2811 cast_selective_amnesia();
2813 cancel_scroll = (cast_selective_amnesia(pre_succ_msg) == -1);
2817 mpr("Read a buggy scroll, please report this.");
2822 you.turn_is_over = false;
2824 set_ident_type(scroll, true);
2825 set_ident_flags(scroll, ISFLAG_KNOW_TYPE); // for notes
2827 string scroll_name = scroll.name(DESC_QUALNAME).c_str();
2831 dec_inv_item_quantity(item_slot, 1);
2832 count_action(CACT_USE, OBJ_SCROLLS);
2836 && which_scroll != SCR_ACQUIREMENT
2837 && which_scroll != SCR_BRAND_WEAPON
2838 && which_scroll != SCR_ENCHANT_WEAPON
2839 && which_scroll != SCR_IDENTIFY
2840 && which_scroll != SCR_ENCHANT_ARMOUR
2841 && which_scroll != SCR_RECHARGING
2842 && which_scroll != SCR_AMNESIA)
2845 you.inv[item_slot].quantity < prev_quantity ? "was" : "is",
2846 scroll_name.c_str());
2849 if (!alreadyknown && dangerous)
2851 // Xom loves it when you read an unknown scroll and there is a
2852 // dangerous monster nearby... (though not as much as potions
2853 // since there are no *really* bad scrolls, merely useless ones).
2854 xom_is_stimulated(bad_effect ? 100 : 50);
2858 auto_assign_item_slot(scroll);
2862 bool check_stasis(const char *msg)
2864 bool blocked = you.species == SP_FORMICID;
2871 // Interactive menu for item drop/use.
2873 void tile_item_use_floor(int idx)
2875 if (mitm[idx].is_type(OBJ_CORPSES, CORPSE_BODY))
2876 butchery(&mitm[idx]);
2879 void tile_item_pickup(int idx, bool part)
2881 if (item_is_stationary(mitm[idx]))
2883 mpr("You can't pick that up.");
2892 pickup_single_item(idx, -1);
2895 void tile_item_drop(int idx, bool partdrop)
2897 int quantity = you.inv[idx].quantity;
2898 if (partdrop && quantity > 1)
2900 quantity = prompt_for_int("Drop how many? ", true);
2906 if (quantity > you.inv[idx].quantity)
2907 quantity = you.inv[idx].quantity;
2909 drop_item(idx, quantity);
2912 void tile_item_eat_floor(int idx)
2914 // XXX: refactor this
2915 if (mitm[idx].base_type == OBJ_CORPSES
2916 && you.species == SP_VAMPIRE
2917 || mitm[idx].base_type == OBJ_FOOD
2918 && you.undead_state() != US_UNDEAD && you.species != SP_VAMPIRE)
2920 if (can_eat(mitm[idx], false))
2921 eat_item(mitm[idx]);
2925 void tile_item_use_secondary(int idx)
2927 const item_def item = you.inv[idx];
2929 if (item.base_type == OBJ_WEAPONS && is_throwable(&you, item))
2931 if (check_warning_inscriptions(item, OPER_FIRE))
2932 fire_thing(idx); // fire weapons
2934 else if (you.equip[EQ_WEAPON] == idx)
2935 wield_weapon(true, SLOT_BARE_HANDS);
2936 else if (item_is_wieldable(item))
2938 // secondary wield for several spells and such
2939 wield_weapon(true, idx); // wield
2943 void tile_item_use(int idx)
2945 const item_def item = you.inv[idx];
2948 bool equipped = false;
2949 bool equipped_weapon = false;
2950 for (unsigned int i = 0; i < NUM_EQUIP; i++)
2952 if (you.equip[i] == idx)
2956 equipped_weapon = true;
2961 // Special case for folks who are wielding something
2962 // that they shouldn't be wielding.
2963 // Note that this is only a problem for equipables
2964 // (otherwise it would only waste a turn)
2965 if (you.equip[EQ_WEAPON] == idx
2966 && (item.base_type == OBJ_ARMOUR
2967 || item.base_type == OBJ_JEWELLERY))
2969 wield_weapon(true, SLOT_BARE_HANDS);
2973 const int type = item.base_type;
2981 case OBJ_MISCELLANY:
2983 // Wield any unwielded item of these types.
2984 if (!equipped && item_is_wieldable(item))
2986 wield_weapon(true, idx);
2989 // Evoke misc. items, rods, or wands.
2990 if (item_is_evokable(item, false))
2995 // Unwield wielded items.
2997 wield_weapon(true, SLOT_BARE_HANDS);
3001 if (check_warning_inscriptions(item, OPER_FIRE))
3006 if (!form_can_wear())
3008 mpr("You can't wear or remove anything in your present form.");
3011 if (equipped && !equipped_weapon)
3013 if (check_warning_inscriptions(item, OPER_TAKEOFF))
3014 takeoff_armour(idx);
3016 else if (check_warning_inscriptions(item, OPER_WEAR))
3021 if (you.species != SP_VAMPIRE
3022 || item.sub_type == CORPSE_SKELETON)
3026 // intentional fall-through for Vampires
3028 if (check_warning_inscriptions(item, OPER_EAT))
3033 if (item.sub_type == BOOK_MANUAL)
3035 if (!item_is_spellbook(item) || !you.skill(SK_SPELLCASTING))
3037 if (check_warning_inscriptions(item, OPER_READ))
3038 _handle_read_book(idx);
3039 } // else it's a spellbook
3040 else if (check_warning_inscriptions(item, OPER_MEMORISE))
3041 learn_spell(); // offers all spells, might not be what we want
3045 if (check_warning_inscriptions(item, OPER_READ))
3050 if (equipped && !equipped_weapon)
3052 else if (check_warning_inscriptions(item, OPER_PUTON))
3057 if (check_warning_inscriptions(item, OPER_QUAFF))