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 TAG_MAJOR_VERSION == 34
617 if (is_unrandom_artefact(item, UNRAND_TALOS))
619 // adjust bad_size for the oversized plate armour
620 // negative means levels too small, positive means levels too large
621 bad_size = SIZE_LARGE - player_size;
629 mprf("This armour is too %s for you!",
630 (bad_size > 0) ? "big" : "small");
636 if (you.form == TRAN_APPENDAGE
638 && slot == beastly_slot(you.attribute[ATTR_APPENDAGE])
639 && you.mutation[you.attribute[ATTR_APPENDAGE]])
641 unwind_var<uint8_t> mutv(you.mutation[you.attribute[ATTR_APPENDAGE]], 0);
642 // disable the mutation then check again
643 return can_wear_armour(item, verbose, ignore_temporary);
646 if (sub_type == ARM_GLOVES)
648 if (you.has_claws(false) == 3)
652 mprf("You can't wear a glove with your huge claw%s!",
653 player_mutation_level(MUT_MISSING_HAND) ? "" : "s");
659 if (sub_type == ARM_BOOTS)
661 if (player_mutation_level(MUT_HOOVES, false) == 3)
664 mpr("You can't wear boots with hooves!");
668 if (you.has_talons(false) == 3)
671 mpr("Boots don't fit your talons!");
675 if (you.species == SP_NAGA
676 #if TAG_MAJOR_VERSION == 34
677 || you.species == SP_DJINNI
682 mpr("You have no legs!");
686 if (!ignore_temporary && you.fishtail)
689 mpr("You don't currently have feet!");
694 if (slot == EQ_HELMET)
696 // Horns 3 & Antennae 3 mutations disallow all headgear
697 if (player_mutation_level(MUT_HORNS, false) == 3)
700 mpr("You can't wear any headgear with your large horns!");
704 if (player_mutation_level(MUT_ANTENNAE, false) == 3)
707 mpr("You can't wear any headgear with your large antennae!");
711 // Soft helmets (caps and wizard hats) always fit, otherwise.
712 if (is_hard_helmet(item))
714 if (player_mutation_level(MUT_HORNS, false))
717 mpr("You can't wear that with your horns!");
721 if (player_mutation_level(MUT_BEAK, false))
724 mpr("You can't wear that with your beak!");
728 if (player_mutation_level(MUT_ANTENNAE, false))
731 mpr("You can't wear that with your antennae!");
735 if (species_is_draconian(you.species))
738 mpr("You can't wear that with your reptilian head.");
742 if (you.species == SP_OCTOPODE)
745 mpr("You can't wear that!");
751 // Can't just use Form::slot_available because of shroom caps.
752 if (!ignore_temporary && !get_form()->can_wear_item(item))
755 mpr("You can't wear that in your present form.");
762 bool do_wear_armour(int item, bool quiet)
764 const item_def &invitem = you.inv[item];
765 if (!invitem.defined())
768 mpr("You don't have any such object.");
772 if (!can_wear_armour(invitem, !quiet, false))
775 const equipment_type slot = get_armour_slot(invitem);
777 if (item == you.equip[EQ_WEAPON])
780 mpr("You are wielding that object!");
784 if (item_is_worn(item))
786 if (Options.equip_unequip)
787 return !takeoff_armour(item);
790 mpr("You're already wearing that object!");
795 bool swapping = false;
796 if ((slot == EQ_CLOAK
801 || slot == EQ_BODY_ARMOUR)
802 && you.equip[slot] != -1)
804 if (!takeoff_armour(you.equip[slot]))
809 you.turn_is_over = true;
811 if (!_safe_to_remove_or_wear(invitem, false))
814 const int delay = armour_equip_delay(invitem);
816 start_delay(DELAY_ARMOUR_ON, delay - (swapping ? 0 : 1), item);
821 bool takeoff_armour(int item)
823 const item_def& invitem = you.inv[item];
825 if (invitem.base_type != OBJ_ARMOUR)
827 mpr("You aren't wearing that!");
833 canned_msg(MSG_TOO_BERSERK);
837 const equipment_type slot = get_armour_slot(invitem);
838 if (item == you.equip[slot] && you.melded[slot])
840 mprf("%s is melded into your body!",
841 invitem.name(DESC_YOUR).c_str());
845 if (!item_is_worn(item))
847 if (Options.equip_unequip)
848 return do_wear_armour(item, true);
851 mpr("You aren't wearing that object!");
856 // If we get here, we're wearing the item.
857 if (invitem.cursed())
859 mprf("%s is stuck to your body!", invitem.name(DESC_YOUR).c_str());
863 if (!_safe_to_remove_or_wear(invitem, true))
875 if (item != you.equip[slot])
877 mpr("You aren't wearing that!");
886 you.turn_is_over = true;
888 const int delay = armour_equip_delay(invitem);
889 start_delay(DELAY_ARMOUR_OFF, delay - 1, item);
894 // Returns a list of possible ring slots.
895 static vector<equipment_type> _current_ring_types()
897 vector<equipment_type> ret;
898 if (you.species == SP_OCTOPODE)
900 for (int i = 0; i < 8; ++i)
902 const equipment_type slot = (equipment_type)(EQ_RING_ONE + i);
904 if (player_mutation_level(MUT_MISSING_HAND)
905 && slot == EQ_RING_EIGHT)
910 if (get_form()->slot_available(slot))
916 if (player_mutation_level(MUT_MISSING_HAND) == 0)
917 ret.push_back(EQ_LEFT_RING);
918 ret.push_back(EQ_RIGHT_RING);
920 if (player_equip_unrand(UNRAND_FINGER_AMULET))
921 ret.push_back(EQ_RING_AMULET);
925 static vector<equipment_type> _current_jewellery_types()
927 vector<equipment_type> ret = _current_ring_types();
928 ret.push_back(EQ_AMULET);
932 static const char _ring_slot_key(equipment_type slot)
936 case EQ_LEFT_RING: return '<';
937 case EQ_RIGHT_RING: return '>';
938 case EQ_RING_AMULET: return '^';
939 case EQ_RING_ONE: return '1';
940 case EQ_RING_TWO: return '2';
941 case EQ_RING_THREE: return '3';
942 case EQ_RING_FOUR: return '4';
943 case EQ_RING_FIVE: return '5';
944 case EQ_RING_SIX: return '6';
945 case EQ_RING_SEVEN: return '7';
946 case EQ_RING_EIGHT: return '8';
948 die("Invalid ring slot");
952 static int _prompt_ring_to_remove(int new_ring)
954 const vector<equipment_type> ring_types = _current_ring_types();
955 vector<char> slot_chars;
956 vector<item_def*> rings;
957 for (auto eq : ring_types)
959 rings.push_back(you.slot_item(eq, true));
960 ASSERT(rings.back());
961 slot_chars.push_back(index_to_letter(rings.back()->link));
967 "You're wearing all the rings you can. Remove which one?");
968 mprf(MSGCH_PROMPT, "(<w>?</w> for menu, <w>Esc</w> to cancel)");
970 // FIXME: Needs TOUCH_UI version
972 for (size_t i = 0; i < rings.size(); i++)
975 const char key = _ring_slot_key(ring_types[i]);
980 m += "</w> or " + rings[i]->name(DESC_INVENTORY);
981 mprf_nocap("%s", m.c_str());
983 flush_prev_message();
985 // Deactivate choice from tile inventory.
986 // FIXME: We need to be able to get the choice (item letter)n
987 // *without* the choice taking action by itself!
988 int eqslot = EQ_NONE;
990 mouse_control mc(MOUSE_MODE_PROMPT);
995 for (size_t i = 0; i < slot_chars.size(); i++)
997 if (c == slot_chars[i]
998 || c == _ring_slot_key(ring_types[i]))
1000 eqslot = ring_types[i];
1005 } while (!key_is_escape(c) && c != ' ' && c != '?');
1011 else if (key_is_escape(c) || eqslot == EQ_NONE)
1014 return you.equip[eqslot];
1017 // Checks whether a to-be-worn or to-be-removed item affects
1018 // character stats and whether wearing/removing it could be fatal.
1019 // If so, warns the player, or just returns false if quiet is true.
1020 static bool _safe_to_remove_or_wear(const item_def &item, bool remove, bool quiet)
1022 if (remove && !safe_to_remove(item, quiet))
1028 if (item.base_type == OBJ_JEWELLERY
1029 && item_ident(item, ISFLAG_KNOW_PLUSES))
1031 switch (item.sub_type)
1035 prop_str = item.plus;
1037 case RING_DEXTERITY:
1039 prop_dex = item.plus;
1041 case RING_INTELLIGENCE:
1043 prop_int = item.plus;
1049 else if (item.base_type == OBJ_ARMOUR && item_type_known(item))
1053 case SPARM_STRENGTH:
1056 case SPARM_INTELLIGENCE:
1059 case SPARM_DEXTERITY:
1067 if (is_artefact(item))
1069 prop_str += artefact_known_property(item, ARTP_STRENGTH);
1070 prop_int += artefact_known_property(item, ARTP_INTELLIGENCE);
1071 prop_dex += artefact_known_property(item, ARTP_DEXTERITY);
1080 stat_type red_stat = NUM_STATS;
1081 if (prop_str >= you.strength() && you.strength() > 0)
1082 red_stat = STAT_STR;
1083 else if (prop_int >= you.intel() && you.intel() > 0)
1084 red_stat = STAT_INT;
1085 else if (prop_dex >= you.dex() && you.dex() > 0)
1086 red_stat = STAT_DEX;
1088 if (red_stat == NUM_STATS)
1097 if (item.base_type == OBJ_WEAPONS)
1100 verb = "Remov"; // -ing, not a typo
1104 if (item.base_type == OBJ_WEAPONS)
1110 string prompt = make_stringf("%sing this item will reduce your %s to zero "
1111 "or below. Continue?", verb.c_str(),
1112 stat_desc(red_stat, SD_NAME));
1113 if (!yesno(prompt.c_str(), true, 'n', true, false))
1121 // Checks whether removing an item would cause flight to end and the
1122 // player to fall to their death.
1123 bool safe_to_remove(const item_def &item, bool quiet)
1125 item_info inf = get_item_info(item);
1127 const bool grants_flight =
1128 inf.is_type(OBJ_JEWELLERY, RING_FLIGHT)
1129 || inf.base_type == OBJ_ARMOUR && inf.brand == SPARM_FLYING
1131 && artefact_known_property(inf, ARTP_FLY);
1133 // assumes item can't grant flight twice
1134 const bool removing_ends_flight = you.airborne()
1135 && !you.racial_permanent_flight()
1136 && !you.attribute[ATTR_FLIGHT_UNCANCELLABLE]
1137 && (you.evokable_flight() == 1);
1139 const dungeon_feature_type feat = grd(you.pos());
1141 if (grants_flight && removing_ends_flight
1142 && is_feat_dangerous(feat, false, true))
1145 mpr("Losing flight right now would be fatal!");
1153 // you.inv[ring_slot] is a valid ring.
1154 // EQ_LEFT_RING and EQ_RIGHT_RING are both occupied, and ring_slot is not
1155 // one of the worn rings.
1157 // Does not do amulets.
1158 static bool _swap_rings(int ring_slot)
1160 vector<equipment_type> ring_types = _current_ring_types();
1161 const int num_rings = ring_types.size();
1163 int last_inscribed = 0;
1166 int melded = 0; // Both melded rings and unavailable slots.
1168 bool all_same = true;
1169 item_def* first_ring = nullptr;
1170 for (auto eq : ring_types)
1172 item_def* ring = you.slot_item(eq, true);
1173 if (!you_can_wear(eq, true) || you.melded[eq])
1175 else if (ring != nullptr)
1177 if (first_ring == nullptr)
1181 if (ring->sub_type != first_ring->sub_type
1182 || ring->plus != first_ring->plus
1183 || is_artefact(*ring) || is_artefact(*first_ring))
1191 else if (strstr(ring->inscription.c_str(), "=R"))
1194 last_inscribed = you.equip[eq];
1199 unwanted = you.equip[eq];
1204 // If the only swappable rings are inscribed =R, go ahead and use them.
1205 if (available == 0 && inscribed > 0)
1207 available += inscribed;
1208 unwanted = last_inscribed;
1211 // We can't put a ring on, because we're wearing all cursed ones.
1212 if (melded == num_rings)
1214 // Shouldn't happen, because hogs and bats can't put on jewellery at
1215 // all and thus won't get this far.
1216 mpr("You can't wear that in your present form.");
1219 else if (available == 0)
1221 mprf("You're already wearing %s cursed ring%s!%s",
1222 number_in_words(cursed).c_str(),
1223 (cursed == 1 ? "" : "s"),
1224 (cursed > 2 ? " Isn't that enough for you?" : ""));
1227 // The simple case - only one available ring.
1228 // If the jewellery_prompt option is true, always allow choosing the
1229 // ring slot (even if we still have empty slots).
1230 else if (available == 1 && !Options.jewellery_prompt)
1232 if (!remove_ring(unwanted, false))
1235 // We can't put a ring on without swapping - because we found
1236 // multiple available rings.
1239 // Don't prompt if all the rings are the same.
1240 if (!all_same || Options.jewellery_prompt)
1241 unwanted = _prompt_ring_to_remove(ring_slot);
1250 if (!remove_ring(unwanted, false))
1254 // Put on the new ring.
1255 start_delay(DELAY_JEWELLERY_ON, 1, ring_slot);
1260 static equipment_type _choose_ring_slot()
1265 "Put ring on which %s? (<w>Esc</w> to cancel)", you.hand_name(false).c_str());
1267 const vector<equipment_type> slots = _current_ring_types();
1268 for (auto eq : slots)
1271 const char key = _ring_slot_key(eq);
1276 item_def* ring = you.slot_item(eq, true);
1278 msg += "</w> or " + ring->name(DESC_INVENTORY);
1280 msg += "</w> - no ring";
1282 if (eq == EQ_LEFT_RING)
1284 else if (eq == EQ_RIGHT_RING)
1286 else if (eq == EQ_RING_AMULET)
1288 mprf_nocap("%s", msg.c_str());
1290 flush_prev_message();
1292 equipment_type eqslot = EQ_NONE;
1293 mouse_control mc(MOUSE_MODE_PROMPT);
1298 for (auto eq : slots)
1300 if (c == _ring_slot_key(eq)
1301 || (you.slot_item(eq, true)
1302 && c == index_to_letter(you.slot_item(eq, true)->link)))
1309 } while (!key_is_escape(c) && c != ' ');
1316 static bool _puton_item(int item_slot, bool prompt_slot)
1318 item_def& item = you.inv[item_slot];
1320 for (int eq = EQ_LEFT_RING; eq < NUM_EQUIP; eq++)
1321 if (item_slot == you.equip[eq])
1323 // "Putting on" an equipped item means taking it off.
1324 if (Options.equip_unequip)
1325 return !remove_ring(item_slot);
1328 mpr("You're already wearing that object!");
1333 if (item_slot == you.equip[EQ_WEAPON])
1335 mpr("You are wielding that object.");
1339 if (item.base_type != OBJ_JEWELLERY)
1341 mpr("You can only put on jewellery.");
1345 const bool is_amulet = jewellery_is_amulet(item);
1347 if (is_amulet && !you_can_wear(EQ_AMULET, true)
1348 || !is_amulet && !you_can_wear(EQ_RINGS, true))
1350 mpr("You can't wear that in your present form.");
1354 const vector<equipment_type> ring_types = _current_ring_types();
1356 if (!is_amulet) // i.e. it's a ring
1358 bool need_swap = true;
1359 for (auto eq : ring_types)
1361 if (!you.slot_item(eq, true))
1369 return _swap_rings(item_slot);
1371 else if (you.slot_item(EQ_AMULET, true))
1373 // Remove the previous one.
1374 if (!remove_ring(you.equip[EQ_AMULET], true))
1377 // Check for stat loss.
1378 if (!_safe_to_remove_or_wear(item, false))
1381 // Put on the new amulet.
1382 start_delay(DELAY_JEWELLERY_ON, 1, item_slot);
1384 // Assume it's going to succeed.
1388 // Check for stat loss.
1389 if (!_safe_to_remove_or_wear(item, false))
1392 equipment_type hand_used = EQ_NONE;
1395 hand_used = EQ_AMULET;
1396 else if (prompt_slot)
1398 // Prompt for a slot, even if we have empty ring slots.
1399 hand_used = _choose_ring_slot();
1401 if (hand_used == EQ_NONE)
1406 // Allow swapping out a ring.
1407 else if (you.slot_item(hand_used, true))
1409 if (!remove_ring(you.equip[hand_used], false))
1412 start_delay(DELAY_JEWELLERY_ON, 1, item_slot);
1418 for (auto eq : ring_types)
1420 if (!you.slot_item(eq, true))
1428 const unsigned int old_talents = your_talents(false).size();
1430 // Actually equip the item.
1431 equip_item(hand_used, item_slot);
1433 check_item_hint(you.inv[item_slot], old_talents);
1434 #ifdef USE_TILE_LOCAL
1435 if (your_talents(false).size() != old_talents)
1437 tiles.layout_statcol();
1442 // Putting on jewellery is fast.
1443 you.time_taken /= 2;
1444 you.turn_is_over = true;
1449 bool puton_ring(int slot, bool allow_prompt)
1453 if (inv_count() < 1)
1455 canned_msg(MSG_NOTHING_CARRIED);
1461 canned_msg(MSG_TOO_BERSERK);
1469 item_slot = prompt_invent_item("Put on which piece of jewellery?",
1470 MT_INVLIST, OBJ_JEWELLERY, true, true,
1471 true, 0, -1, nullptr, OPER_PUTON);
1474 if (prompt_failed(item_slot))
1477 bool prompt = allow_prompt ? Options.jewellery_prompt : false;
1479 return _puton_item(item_slot, prompt);
1482 bool remove_ring(int slot, bool announce)
1484 equipment_type hand_used = EQ_NONE;
1486 bool has_jewellery = false;
1487 bool has_melded = false;
1488 const vector<equipment_type> jewellery_slots = _current_jewellery_types();
1490 for (auto eq : jewellery_slots)
1492 if (you.slot_item(eq))
1494 if (has_jewellery || Options.jewellery_prompt)
1496 // At least one other piece, which means we'll have to ask
1497 hand_used = EQ_NONE;
1502 has_jewellery = true;
1504 else if (you.melded[eq])
1511 mpr("You aren't wearing any unmelded rings or amulets.");
1513 mpr("You aren't wearing any rings or amulets.");
1520 canned_msg(MSG_TOO_BERSERK);
1524 if (hand_used == EQ_NONE)
1527 (slot == -1)? prompt_invent_item("Remove which piece of jewellery?",
1529 OBJ_JEWELLERY, true, true, true,
1530 0, -1, nullptr, OPER_REMOVE,
1534 if (prompt_failed(equipn))
1537 hand_used = item_equip_slot(you.inv[equipn]);
1538 if (hand_used == EQ_NONE)
1540 mpr("You aren't wearing that.");
1543 else if (you.inv[equipn].base_type != OBJ_JEWELLERY)
1545 mpr("That isn't a piece of jewellery.");
1550 if (you.equip[hand_used] == -1)
1552 mpr("I don't think you really meant that.");
1555 else if (you.melded[hand_used])
1557 mpr("You can't take that off while it's melded.");
1560 else if (hand_used == EQ_AMULET
1561 && you.equip[EQ_RING_AMULET] != -1)
1563 // This can be removed in the future if more ring amulets are added.
1564 ASSERT(player_equip_unrand(UNRAND_FINGER_AMULET));
1566 mpr("The amulet cannot be taken off without first removing the ring!");
1570 if (!check_warning_inscriptions(you.inv[you.equip[hand_used]],
1577 if (you.inv[you.equip[hand_used]].cursed())
1581 mprf("%s is stuck to you!",
1582 you.inv[you.equip[hand_used]].name(DESC_YOUR).c_str());
1585 mpr("It's stuck to you!");
1587 set_ident_flags(you.inv[you.equip[hand_used]], ISFLAG_KNOW_CURSE);
1591 ring_wear_2 = you.equip[hand_used];
1594 if (!_safe_to_remove_or_wear(you.inv[ring_wear_2], true))
1597 mprf("You remove %s.", you.inv[ring_wear_2].name(DESC_YOUR).c_str());
1598 #ifdef USE_TILE_LOCAL
1599 const unsigned int old_talents = your_talents(false).size();
1601 unequip_item(hand_used);
1602 #ifdef USE_TILE_LOCAL
1603 if (your_talents(false).size() != old_talents)
1605 tiles.layout_statcol();
1610 you.time_taken /= 2;
1611 you.turn_is_over = true;
1616 void prompt_inscribe_item()
1618 if (inv_count() < 1)
1620 mpr("You don't have anything to inscribe.");
1624 int item_slot = prompt_invent_item("Inscribe which item?",
1625 MT_INVLIST, OSEL_ANY);
1627 if (prompt_failed(item_slot))
1630 inscribe_item(you.inv[item_slot]);
1633 static bool _check_blood_corpses_on_ground()
1635 for (stack_iterator si(you.pos(), true); si; ++si)
1637 if (si->is_type(OBJ_CORPSES, CORPSE_BODY)
1638 && mons_has_blood(si->mon_type))
1646 static void _vampire_corpse_help()
1648 if (you.species != SP_VAMPIRE)
1651 if (_check_blood_corpses_on_ground())
1652 mpr("Use <w>e</w> to drain blood from corpses.");
1655 void drink(int slot)
1657 if (you_foodless(true))
1659 mpr("You can't drink.");
1663 if (inv_count() == 0)
1665 canned_msg(MSG_NOTHING_CARRIED);
1666 _vampire_corpse_help();
1672 canned_msg(MSG_TOO_BERSERK);
1676 if (you.form == TRAN_BAT)
1678 canned_msg(MSG_PRESENT_FORM);
1679 _vampire_corpse_help();
1683 if (you.duration[DUR_NO_POTIONS])
1685 mpr("You cannot drink potions in your current state!");
1691 slot = prompt_invent_item("Drink which item?",
1692 MT_INVLIST, OBJ_POTIONS,
1693 true, true, true, 0, -1, nullptr,
1695 if (prompt_failed(slot))
1697 _vampire_corpse_help();
1702 item_def& potion = you.inv[slot];
1704 if (potion.base_type != OBJ_POTIONS)
1706 if (you.species == SP_VAMPIRE && potion.base_type == OBJ_CORPSES)
1709 mpr("You can't drink that!");
1713 const bool alreadyknown = item_type_known(potion);
1715 if (alreadyknown && is_bad_item(potion, true))
1717 canned_msg(MSG_UNTHINKING_ACT);
1721 // The "> 1" part is to reduce the amount of times that Xom is
1722 // stimulated when you are a low-level 1 trying your first unknown
1723 // potions on monsters.
1724 const bool dangerous = (player_in_a_dangerous_place()
1725 && you.experience_level > 1);
1726 potion_type pot_type = (potion_type)potion.sub_type;
1728 if (player_under_penance(GOD_GOZAG) && one_chance_in(3))
1730 simple_god_message(" petitions for your drink to fail.", GOD_GOZAG);
1731 you.turn_is_over = true;
1735 if (!quaff_potion(potion))
1738 if (!alreadyknown && dangerous)
1740 // Xom loves it when you drink an unknown potion and there is
1741 // a dangerous monster nearby...
1742 xom_is_stimulated(200);
1744 if (is_blood_potion(potion))
1746 // Always drink oldest potion.
1747 remove_oldest_perishable_item(potion);
1749 dec_inv_item_quantity(slot, 1);
1750 count_action(CACT_USE, OBJ_POTIONS);
1751 auto_assign_item_slot(potion);
1752 you.turn_is_over = true;
1753 // This got deferred from PotionExperience::effect to prevent SIGHUP abuse.
1754 if (pot_type == POT_EXPERIENCE)
1758 // XXX: there's probably a nicer way of doing this.
1759 bool god_hates_brand(const int brand)
1761 if (is_good_god(you.religion)
1762 && (brand == SPWPN_DRAINING
1763 || brand == SPWPN_VAMPIRISM
1764 || brand == SPWPN_CHAOS
1765 || brand == SPWPN_PAIN))
1770 if (you_worship(GOD_DITHMENOS)
1771 && (brand == SPWPN_FLAMING
1772 || brand == SPWPN_CHAOS))
1777 if (you_worship(GOD_SHINING_ONE) && brand == SPWPN_VENOM)
1780 if (you_worship(GOD_CHEIBRIADOS) && (brand == SPWPN_CHAOS
1781 || brand == SPWPN_SPEED))
1786 if (you_worship(GOD_YREDELEMNUL) && brand == SPWPN_HOLY_WRATH)
1792 static void _rebrand_weapon(item_def& wpn)
1794 if (&wpn == you.weapon() && you.duration[DUR_WEAPON_BRAND])
1795 end_weapon_brand(wpn);
1796 int old_brand = get_weapon_brand(wpn);
1797 int new_brand = old_brand;
1799 // now try and find an appropriate brand
1800 while (old_brand == new_brand || god_hates_brand(new_brand))
1802 if (is_range_weapon(wpn))
1804 new_brand = random_choose_weighted(
1810 5, SPWPN_ELECTROCUTION,
1816 new_brand = random_choose_weighted(
1822 15, SPWPN_ELECTROCUTION,
1823 12, SPWPN_PROTECTION,
1830 set_item_ego_type(wpn, OBJ_WEAPONS, new_brand);
1834 static void _brand_weapon(item_def &wpn)
1836 you.wield_change = true;
1838 const string itname = wpn.name(DESC_YOUR);
1840 _rebrand_weapon(wpn);
1842 bool success = true;
1843 colour_t flash_colour = BLACK;
1845 switch (get_weapon_brand(wpn))
1848 flash_colour = YELLOW;
1849 mprf("%s emits a brilliant flash of light!",itname.c_str());
1852 case SPWPN_PROTECTION:
1853 flash_colour = YELLOW;
1854 mprf("%s projects an invisible shield of force!",itname.c_str());
1858 flash_colour = YELLOW;
1859 mprf("%s emits a repelling force!",itname.c_str());
1864 mprf("%s is engulfed in flames!", itname.c_str());
1867 case SPWPN_FREEZING:
1868 flash_colour = LIGHTCYAN;
1869 mprf("%s is covered with a thin layer of ice!", itname.c_str());
1872 case SPWPN_DRAINING:
1873 flash_colour = DARKGREY;
1874 mprf("%s craves living souls!", itname.c_str());
1877 case SPWPN_VAMPIRISM:
1878 flash_colour = DARKGREY;
1879 mprf("%s thirsts for the lives of mortals!", itname.c_str());
1883 flash_colour = GREEN;
1884 mprf("%s drips with poison.", itname.c_str());
1887 case SPWPN_ELECTROCUTION:
1888 flash_colour = LIGHTCYAN;
1889 mprf("%s crackles with electricity.", itname.c_str());
1893 flash_colour = random_colour();
1894 mprf("%s erupts in a glittering mayhem of colour.", itname.c_str());
1904 item_set_appearance(wpn);
1905 // Message would spoil this even if we didn't identify.
1906 set_ident_flags(wpn, ISFLAG_KNOW_TYPE);
1907 mprf_nocap("%s", wpn.name(DESC_INVENTORY_EQUIP).c_str());
1908 // Might be rebranding to/from protection or evasion.
1909 you.redraw_armour_class = true;
1910 you.redraw_evasion = true;
1911 // Might be removing antimagic.
1913 flash_view_delay(UA_PLAYER, flash_colour, 300);
1918 static object_selector _enchant_selector(scroll_type scroll)
1920 if (scroll == SCR_BRAND_WEAPON)
1921 return OSEL_BRANDABLE_WEAPON;
1922 else if (scroll == SCR_ENCHANT_WEAPON)
1923 return OSEL_ENCHANTABLE_WEAPON;
1924 die("Invalid scroll type %d for _enchant_selector", (int)scroll);
1927 // Returns nullptr if no weapon was chosen.
1928 static item_def* _scroll_choose_weapon(bool alreadyknown, const string &pre_msg,
1932 const bool branding = scroll == SCR_BRAND_WEAPON;
1933 const object_selector selector = _enchant_selector(scroll);
1937 item_slot = prompt_invent_item(branding ? "Brand which weapon?"
1938 : "Enchant which weapon?",
1939 MT_INVLIST, selector,
1941 // The scroll is used up if we didn't know what it was originally.
1942 if (item_slot == PROMPT_NOTHING)
1945 if (item_slot == PROMPT_ABORT)
1948 || crawl_state.seen_hups
1949 || yesno("Really abort (and waste the scroll)?", false, 0))
1958 item_def* wpn = &you.inv[item_slot];
1959 if (!item_is_selected(*wpn, selector))
1961 mpr("Choose a valid weapon, or Esc to abort.");
1966 // Now we're definitely using up the scroll.
1973 // Returns true if the scroll is used up.
1974 static bool _handle_brand_weapon(bool alreadyknown, const string &pre_msg)
1976 item_def* weapon = _scroll_choose_weapon(alreadyknown, pre_msg,
1979 return !alreadyknown;
1981 _brand_weapon(*weapon);
1985 bool enchant_weapon(item_def &wpn, bool quiet)
1987 bool success = false;
1989 // Get item name now before changing enchantment.
1990 string iname = wpn.name(DESC_YOUR);
1993 && !is_artefact(wpn)
1994 && wpn.base_type == OBJ_WEAPONS
1995 && wpn.plus < MAX_WPN_ENCHANT)
2000 mprf("%s glows red for a moment.", iname.c_str());
2003 if (!success && !quiet)
2004 canned_msg(MSG_NOTHING_HAPPENS);
2007 you.wield_change = true;
2012 // Returns true if the scroll is used up.
2013 static bool _identify(bool alreadyknown, const string &pre_msg)
2018 if (item_slot == -1)
2020 item_slot = prompt_invent_item(
2021 "Identify which item? (\\ to view known items)",
2022 MT_INVLIST, OSEL_UNIDENT, true, true, false, 0,
2023 -1, nullptr, OPER_ANY, true);
2026 if (item_slot == PROMPT_NOTHING)
2027 return !alreadyknown;
2029 if (item_slot == PROMPT_ABORT)
2032 || crawl_state.seen_hups
2033 || yesno("Really abort (and waste the scroll)?", false, 0))
2036 return !alreadyknown;
2045 item_def& item(you.inv[item_slot]);
2046 if (fully_identified(item)
2047 && (!is_deck(item) || top_card_is_known(item)))
2049 mpr("Choose an unidentified item, or Esc to abort.");
2058 set_ident_type(item, true);
2059 set_ident_flags(item, ISFLAG_IDENT_MASK);
2061 if (is_deck(item) && !top_card_is_known(item))
2062 deck_identify_first(item_slot);
2064 // Output identified item.
2065 mprf_nocap("%s", item.name(DESC_INVENTORY_EQUIP).c_str());
2066 if (item_slot == you.equip[EQ_WEAPON])
2067 you.wield_change = true;
2069 if (item.is_type(OBJ_JEWELLERY, AMU_INACCURACY)
2070 && item_slot == you.equip[EQ_AMULET]
2071 && !item_known_cursed(item))
2073 learned_something_new(HINT_INACCURACY);
2076 auto_assign_item_slot(item);
2081 static bool _handle_enchant_weapon(bool alreadyknown, const string &pre_msg)
2083 item_def* weapon = _scroll_choose_weapon(alreadyknown, pre_msg,
2084 SCR_ENCHANT_WEAPON);
2086 return !alreadyknown;
2088 enchant_weapon(*weapon, false);
2092 bool enchant_armour(int &ac_change, bool quiet, item_def &arm)
2094 ASSERT(arm.defined());
2095 ASSERT(arm.base_type == OBJ_ARMOUR);
2099 // Cannot be enchanted.
2100 if (!is_enchantable_armour(arm))
2103 canned_msg(MSG_NOTHING_HAPPENS);
2107 // Turn hides into mails where applicable.
2108 // NOTE: It is assumed that armour which changes in this way does
2109 // not change into a form of armour with a different evasion modifier.
2110 if (armour_is_hide(arm, false))
2114 mprf("%s glows purple and changes!",
2115 arm.name(DESC_YOUR).c_str());
2118 ac_change = property(arm, PARM_AC);
2120 ac_change = property(arm, PARM_AC) - ac_change;
2122 // No additional enchantment.
2126 // Output message before changing enchantment and curse status.
2129 mprf("%s glows green for a moment.",
2130 arm.name(DESC_YOUR).c_str());
2139 static int _handle_enchant_armour(bool alreadyknown, const string &pre_msg)
2144 if (item_slot == -1)
2146 item_slot = prompt_invent_item("Enchant which item?", MT_INVLIST,
2147 OSEL_ENCH_ARM, true, true, false);
2150 if (item_slot == PROMPT_NOTHING)
2151 return alreadyknown ? -1 : 0;
2153 if (item_slot == PROMPT_ABORT)
2156 || crawl_state.seen_hups
2157 || yesno("Really abort (and waste the scroll)?", false, 0))
2160 return alreadyknown ? -1 : 0;
2169 item_def& arm(you.inv[item_slot]);
2171 if (!is_enchantable_armour(arm, true))
2173 mpr("Choose some type of armour to enchant, or Esc to abort.");
2180 // Okay, we may actually (attempt to) enchant something.
2185 bool result = enchant_armour(ac_change, false, arm);
2188 you.redraw_armour_class = true;
2190 return result ? 1 : 0;
2197 void random_uselessness()
2199 ASSERT(!crawl_state.game_is_arena());
2205 mprf("The dust glows %s!", weird_glowing_colour().c_str());
2211 mprf("%s glows %s for a moment.",
2212 you.weapon()->name(DESC_YOUR).c_str(),
2213 weird_glowing_colour().c_str());
2217 mpr(you.hands_act("glow", weird_glowing_colour()
2218 + " for a moment."));
2223 if (you.species == SP_MUMMY)
2224 mpr("Your bandages flutter.");
2225 else // if (you.can_smell())
2226 mprf("You smell %s.", weird_smell().c_str());
2230 mpr("You experience a momentary feeling of inescapable doom!");
2234 if (player_mutation_level(MUT_BEAK) || one_chance_in(3))
2235 mpr("Your brain hurts!");
2236 else if (you.species == SP_MUMMY || coinflip())
2237 mpr("Your ears itch!");
2239 mpr("Your nose twitches suddenly!");
2243 mprf(MSGCH_SOUND, "You hear the tinkle of a tiny bell.");
2244 noisy(2, you.pos());
2245 cast_summon_butterflies(100);
2249 mprf(MSGCH_SOUND, "You hear %s.", weird_sound().c_str());
2250 noisy(2, you.pos());
2255 static void _handle_read_book(int item_slot)
2259 canned_msg(MSG_TOO_BERSERK);
2263 if (you.duration[DUR_BRAINLESS])
2265 mpr("Reading books requires mental cohesion, which you lack.");
2269 item_def& book(you.inv[item_slot]);
2270 ASSERT(book.sub_type != BOOK_MANUAL);
2272 #if TAG_MAJOR_VERSION == 34
2273 if (book.sub_type == BOOK_BUGGY_DESTRUCTION)
2275 mpr("This item has been removed, sorry!");
2283 static void _vulnerability_scroll()
2285 mon_enchant lowered_mr(ENCH_LOWERED_MR, 1, &you, 400);
2287 // Go over all creatures in LOS.
2288 for (radius_iterator ri(you.pos(), LOS_NO_TRANS); ri; ++ri)
2290 if (monster* mon = monster_at(*ri))
2292 // If relevant, monsters have their MR halved.
2293 if (!mons_immune_magic(mon))
2294 mon->add_ench(lowered_mr);
2296 // Annoying but not enough to turn friendlies against you.
2297 if (!mon->wont_attack())
2298 behaviour_event(mon, ME_ANNOY, &you);
2302 you.set_duration(DUR_LOWERED_MR, 40, 0, "Magic quickly surges around you.");
2305 static bool _is_cancellable_scroll(scroll_type scroll)
2307 return scroll == SCR_IDENTIFY
2308 || scroll == SCR_BLINKING
2309 || scroll == SCR_RECHARGING
2310 || scroll == SCR_ENCHANT_ARMOUR
2311 || scroll == SCR_AMNESIA
2312 || scroll == SCR_REMOVE_CURSE
2313 #if TAG_MAJOR_VERSION == 34
2314 || scroll == SCR_CURSE_ARMOUR
2315 || scroll == SCR_CURSE_JEWELLERY
2317 || scroll == SCR_BRAND_WEAPON
2318 || scroll == SCR_ENCHANT_WEAPON
2319 || scroll == SCR_MAGIC_MAPPING;
2323 * Is the player currently able to use the 'r' command (to read books or
2324 * scrolls). Being too berserk, confused, or having no reading material will
2327 * Prints corresponding messages. (Thanks, canned_msg().)
2329 bool player_can_read()
2333 canned_msg(MSG_TOO_BERSERK);
2339 canned_msg(MSG_TOO_CONFUSED);
2343 if (inv_count() < 1)
2345 canned_msg(MSG_NOTHING_CARRIED);
2353 * If the player has no items matching the given selector, give an appropriate
2354 * response to print. Otherwise, if they do have such items, return the empty
2357 static string _no_items_reason(object_selector type)
2359 if (!any_items_of_type(type))
2360 return no_selectables_message(type);
2365 * If the player is unable to (r)ead the item in the given slot, return the
2366 * reason why. Otherwise (if they are able to read it), returns "", the empty
2369 string cannot_read_item_reason(const item_def &item)
2371 // can read books, except for manuals...
2372 if (item.base_type == OBJ_BOOKS)
2374 if (item.sub_type == BOOK_MANUAL)
2375 return "You can't read that!";
2379 // and scrolls - but nothing else.
2380 if (item.base_type != OBJ_SCROLLS)
2381 return "You can't read that!";
2383 // the below only applies to scrolls. (it's easier to read books, since
2384 // that's just a UI/strategic thing.)
2386 if (silenced(you.pos()))
2387 return "Magic scrolls do not work when you're silenced!";
2390 if (you.duration[DUR_WATER_HOLD] && !you.res_water_drowning())
2391 return "You cannot read scrolls while unable to breathe!";
2394 if (you.duration[DUR_NO_SCROLLS])
2395 return "You cannot read scrolls in your current state!";
2397 #if TAG_MAJOR_VERSION == 34
2398 // Prevent hot lava orcs reading scrolls
2399 if (you.species == SP_LAVA_ORC && temperature_effect(LORC_NO_SCROLLS))
2400 return "You'd burn any scroll you tried to read!";
2403 // don't waste the player's time reading known scrolls in situations where
2404 // they'd be useless
2406 if (!item_type_known(item))
2409 switch (item.sub_type)
2412 case SCR_TELEPORTATION:
2413 return you.no_tele_reason(false, item.sub_type == SCR_BLINKING);
2416 if (you.spell_no == 0)
2417 return "You have no spells to forget!";
2420 #if TAG_MAJOR_VERSION == 34
2421 case SCR_CURSE_WEAPON:
2423 return "This scroll only affects a wielded weapon!";
2425 // assumption: wielded weapons always have their curse & brand known
2426 if (you.weapon()->cursed())
2427 return "Your weapon is already cursed!";
2429 if (get_weapon_brand(*you.weapon()) == SPWPN_HOLY_WRATH)
2430 return "Holy weapons cannot be cursed!";
2434 case SCR_ENCHANT_ARMOUR:
2435 return _no_items_reason(OSEL_ENCH_ARM);
2437 case SCR_ENCHANT_WEAPON:
2438 return _no_items_reason(OSEL_ENCHANTABLE_WEAPON);
2441 return _no_items_reason(OSEL_UNIDENT);
2443 case SCR_RECHARGING:
2444 return _no_items_reason(OSEL_RECHARGE);
2446 case SCR_REMOVE_CURSE:
2447 return _no_items_reason(OSEL_CURSED_WORN);
2449 #if TAG_MAJOR_VERSION == 34
2450 case SCR_CURSE_ARMOUR:
2451 return _no_items_reason(OSEL_UNCURSED_WORN_ARMOUR);
2453 case SCR_CURSE_JEWELLERY:
2454 return _no_items_reason(OSEL_UNCURSED_WORN_JEWELLERY);
2463 * Check to see if the player can read the item in the given slot, and if so,
2464 * reads it. (Examining books, evoking the tome of destruction, & using
2467 * @param slot The slot of the item in the player's inventory. If -1, the
2468 * player is prompted to choose a slot.
2472 if (!player_can_read())
2475 int item_slot = (slot != -1) ? slot
2476 : prompt_invent_item("Read which item?",
2479 true, true, true, 0, -1,
2480 nullptr, OPER_READ);
2482 if (prompt_failed(item_slot))
2485 const item_def& scroll = you.inv[item_slot];
2486 const string failure_reason = cannot_read_item_reason(scroll);
2487 if (!failure_reason.empty())
2489 mprf(MSGCH_PROMPT, "%s", failure_reason.c_str());
2493 if (scroll.base_type == OBJ_BOOKS)
2495 _handle_read_book(item_slot);
2499 // need to handle this before we waste time (with e.g. blurryvis)
2500 if (scroll.sub_type == SCR_BLINKING && item_type_known(scroll)
2502 && !yesno("Your blink will be uncontrolled - continue anyway?",
2509 if (player_mutation_level(MUT_BLURRY_VISION)
2510 && !i_feel_safe(false, false, true)
2511 && !yesno("Really read with blurry vision while enemies are nearby?",
2518 // Ok - now we FINALLY get to read a scroll !!! {dlb}
2519 you.turn_is_over = true;
2521 if (you.duration[DUR_BRAINLESS] && !one_chance_in(5))
2523 mpr("You almost manage to decipher the scroll,"
2524 " but fail in this attempt.");
2528 // if we have blurry vision, we need to start a delay before the actual
2529 // scroll effect kicks in.
2530 if (player_mutation_level(MUT_BLURRY_VISION))
2532 // takes 0.5, 1, 2 extra turns
2533 const int turns = max(1, player_mutation_level(MUT_BLURRY_VISION) - 1);
2534 start_delay(DELAY_BLURRY_SCROLL, turns, item_slot);
2535 if (player_mutation_level(MUT_BLURRY_VISION) == 1)
2536 you.time_taken /= 2;
2539 read_scroll(item_slot);
2543 * Read the provided scroll.
2545 * Does NOT check whether the player can currently read, whether the scroll is
2546 * currently useless, etc. Likewise doesn't handle blurry vision, setting
2547 * you.turn_is_over, and other externals. DOES destroy one scroll, unless the
2548 * player chooses to cancel at the last moment.
2550 * @param slot The slot of the item in the player's inventory.
2552 void read_scroll(int item_slot)
2554 item_def& scroll = you.inv[item_slot];
2555 const scroll_type which_scroll = static_cast<scroll_type>(scroll.sub_type);
2556 const int prev_quantity = scroll.quantity;
2557 const bool alreadyknown = item_type_known(scroll);
2559 // For cancellable scrolls leave printing this message to their
2560 // respective functions.
2561 const string pre_succ_msg =
2562 make_stringf("As you read the %s, it crumbles to dust.",
2563 scroll.name(DESC_QUALNAME).c_str());
2564 if (!_is_cancellable_scroll(which_scroll))
2567 // Actual removal of scroll done afterwards. -- bwr
2570 const bool dangerous = player_in_a_dangerous_place();
2572 // ... but some scrolls may still be cancelled afterwards.
2573 bool cancel_scroll = false;
2574 bool bad_effect = false; // for Xom: result is bad (or at least dangerous)
2576 switch (which_scroll)
2578 case SCR_RANDOM_USELESSNESS:
2579 random_uselessness();
2584 const string reason = you.no_tele_reason(true, true);
2585 if (!reason.empty())
2592 const bool safely_cancellable
2593 = alreadyknown && !player_mutation_level(MUT_BLURRY_VISION);
2595 if (player_has_orb())
2597 mprf(MSGCH_ORB, "The Orb prevents control of your translocation!");
2598 uncontrolled_blink();
2602 cancel_scroll = (cast_controlled_blink(false, safely_cancellable)
2603 == SPRET_ABORT) && alreadyknown;
2607 mpr(pre_succ_msg); // ordering is iffy but w/e
2611 case SCR_TELEPORTATION:
2615 case SCR_REMOVE_CURSE:
2619 remove_curse(false);
2622 cancel_scroll = !remove_curse(true, pre_succ_msg);
2625 case SCR_ACQUIREMENT:
2626 mpr("This is a scroll of acquirement!");
2627 // included in default force_more_message
2628 // Identify it early in case the player checks the '\' screen.
2629 set_ident_type(scroll, true);
2630 run_uncancel(UNC_ACQUIREMENT, AQ_SCROLL);
2634 mpr("You assume a fearsome visage.");
2635 mass_enchantment(ENCH_FEAR, 1000);
2639 noisy(25, you.pos(), "You hear a loud clanging noise!");
2643 cast_shadow_creatures(MON_SUMM_SCROLL);
2647 mpr("The scroll dissolves into smoke.");
2648 big_cloud(random_smoke_type(), &you, you.pos(), 50, 8 + random2(8));
2651 case SCR_MAGIC_MAPPING:
2652 if (alreadyknown && !is_map_persistent())
2654 cancel_scroll = true;
2655 mpr("It would have no effect in this place.");
2659 magic_mapping(500, 100, false);
2663 torment(&you, TORMENT_SCROLL, you.pos());
2665 // This is only naughty if you know you're doing it.
2666 did_god_conduct(DID_NECROMANCY, 10, item_type_known(scroll));
2670 case SCR_IMMOLATION:
2672 // Dithmenos hates trying to play with fire, even if it does nothing.
2673 did_god_conduct(DID_FIRE, 2 + random2(3), item_type_known(scroll));
2675 bool had_effect = false;
2676 for (monster_near_iterator mi(you.pos(), LOS_NO_TRANS); mi; ++mi)
2678 if (mons_immune_magic(*mi) || mi->is_summoned())
2681 if (mi->add_ench(mon_enchant(ENCH_INNER_FLAME, 0, &you)))
2686 mpr("The creatures around you are filled with an inner flame!");
2688 mpr("The air around you briefly surges with heat, but it dissipates.");
2694 #if TAG_MAJOR_VERSION == 34
2695 case SCR_CURSE_WEAPON:
2697 // Not you.weapon() because we want to handle melded weapons too.
2698 item_def * const weapon = you.slot_item(EQ_WEAPON, true);
2699 if (!weapon || !is_weapon(*weapon) || weapon->cursed())
2701 bool plural = false;
2702 const string weapon_name =
2703 weapon ? weapon->name(DESC_YOUR)
2704 : "Your " + you.hand_name(true, &plural);
2705 mprf("%s very briefly gain%s a black sheen.",
2706 weapon_name.c_str(), plural ? "" : "s");
2710 // Also sets wield_change.
2711 do_curse_item(*weapon, false);
2712 learned_something_new(HINT_YOU_CURSED);
2719 case SCR_ENCHANT_WEAPON:
2723 mpr("It is a scroll of enchant weapon.");
2724 // included in default force_more_message (to show it before menu)
2727 cancel_scroll = !_handle_enchant_weapon(alreadyknown, pre_succ_msg);
2730 case SCR_BRAND_WEAPON:
2734 mpr("It is a scroll of brand weapon.");
2735 // included in default force_more_message (to show it before menu)
2738 cancel_scroll = !_handle_brand_weapon(alreadyknown, pre_succ_msg);
2745 mpr("It is a scroll of identify.");
2746 // included in default force_more_message (to show it before menu)
2747 // Do this here so it doesn't turn up in the ID menu.
2748 set_ident_type(scroll, true);
2750 cancel_scroll = !_identify(alreadyknown, pre_succ_msg);
2753 case SCR_RECHARGING:
2757 mpr("It is a scroll of recharging.");
2758 // included in default force_more_message (to show it before menu)
2760 cancel_scroll = (recharge_wand(alreadyknown, pre_succ_msg) == -1);
2763 case SCR_ENCHANT_ARMOUR:
2767 mpr("It is a scroll of enchant armour.");
2768 // included in default force_more_message (to show it before menu)
2771 (_handle_enchant_armour(alreadyknown, pre_succ_msg) == -1);
2774 #if TAG_MAJOR_VERSION == 34
2775 // Should always be identified by Ashenzari.
2776 case SCR_CURSE_ARMOUR:
2777 case SCR_CURSE_JEWELLERY:
2779 const bool armour = which_scroll == SCR_CURSE_ARMOUR;
2780 cancel_scroll = !curse_item(armour, pre_succ_msg);
2787 holy_word(100, HOLY_WORD_SCROLL, you.pos(), false, &you);
2789 // This is always naughty, even if you didn't affect anyone.
2790 // Don't speak those foul holy words even in jest!
2791 did_god_conduct(DID_HOLY, 10, item_type_known(scroll));
2799 case SCR_VULNERABILITY:
2800 _vulnerability_scroll();
2807 mpr("It is a scroll of amnesia.");
2808 // included in default force_more_message (to show it before menu)
2810 if (you.spell_no == 0)
2811 mpr("You feel forgetful for a moment.");
2812 else if (!alreadyknown)
2813 cast_selective_amnesia();
2815 cancel_scroll = (cast_selective_amnesia(pre_succ_msg) == -1);
2819 mpr("Read a buggy scroll, please report this.");
2824 you.turn_is_over = false;
2826 set_ident_type(scroll, true);
2827 set_ident_flags(scroll, ISFLAG_KNOW_TYPE); // for notes
2829 string scroll_name = scroll.name(DESC_QUALNAME).c_str();
2833 dec_inv_item_quantity(item_slot, 1);
2834 count_action(CACT_USE, OBJ_SCROLLS);
2838 && which_scroll != SCR_ACQUIREMENT
2839 && which_scroll != SCR_BRAND_WEAPON
2840 && which_scroll != SCR_ENCHANT_WEAPON
2841 && which_scroll != SCR_IDENTIFY
2842 && which_scroll != SCR_ENCHANT_ARMOUR
2843 && which_scroll != SCR_RECHARGING
2844 && which_scroll != SCR_AMNESIA)
2847 you.inv[item_slot].quantity < prev_quantity ? "was" : "is",
2848 scroll_name.c_str());
2851 if (!alreadyknown && dangerous)
2853 // Xom loves it when you read an unknown scroll and there is a
2854 // dangerous monster nearby... (though not as much as potions
2855 // since there are no *really* bad scrolls, merely useless ones).
2856 xom_is_stimulated(bad_effect ? 100 : 50);
2860 auto_assign_item_slot(scroll);
2864 bool check_stasis(const char *msg)
2866 bool blocked = you.species == SP_FORMICID;
2873 // Interactive menu for item drop/use.
2875 void tile_item_use_floor(int idx)
2877 if (mitm[idx].is_type(OBJ_CORPSES, CORPSE_BODY))
2878 butchery(&mitm[idx]);
2881 void tile_item_pickup(int idx, bool part)
2883 if (item_is_stationary(mitm[idx]))
2885 mpr("You can't pick that up.");
2894 pickup_single_item(idx, -1);
2897 void tile_item_drop(int idx, bool partdrop)
2899 int quantity = you.inv[idx].quantity;
2900 if (partdrop && quantity > 1)
2902 quantity = prompt_for_int("Drop how many? ", true);
2908 if (quantity > you.inv[idx].quantity)
2909 quantity = you.inv[idx].quantity;
2911 drop_item(idx, quantity);
2914 void tile_item_eat_floor(int idx)
2916 // XXX: refactor this
2917 if (mitm[idx].base_type == OBJ_CORPSES
2918 && you.species == SP_VAMPIRE
2919 || mitm[idx].base_type == OBJ_FOOD
2920 && you.undead_state() != US_UNDEAD && you.species != SP_VAMPIRE)
2922 if (can_eat(mitm[idx], false))
2923 eat_item(mitm[idx]);
2927 void tile_item_use_secondary(int idx)
2929 const item_def item = you.inv[idx];
2931 if (item.base_type == OBJ_WEAPONS && is_throwable(&you, item))
2933 if (check_warning_inscriptions(item, OPER_FIRE))
2934 fire_thing(idx); // fire weapons
2936 else if (you.equip[EQ_WEAPON] == idx)
2937 wield_weapon(true, SLOT_BARE_HANDS);
2938 else if (item_is_wieldable(item))
2940 // secondary wield for several spells and such
2941 wield_weapon(true, idx); // wield
2945 void tile_item_use(int idx)
2947 const item_def item = you.inv[idx];
2950 bool equipped = false;
2951 bool equipped_weapon = false;
2952 for (unsigned int i = 0; i < NUM_EQUIP; i++)
2954 if (you.equip[i] == idx)
2958 equipped_weapon = true;
2963 // Special case for folks who are wielding something
2964 // that they shouldn't be wielding.
2965 // Note that this is only a problem for equipables
2966 // (otherwise it would only waste a turn)
2967 if (you.equip[EQ_WEAPON] == idx
2968 && (item.base_type == OBJ_ARMOUR
2969 || item.base_type == OBJ_JEWELLERY))
2971 wield_weapon(true, SLOT_BARE_HANDS);
2975 const int type = item.base_type;
2983 case OBJ_MISCELLANY:
2985 // Wield any unwielded item of these types.
2986 if (!equipped && item_is_wieldable(item))
2988 wield_weapon(true, idx);
2991 // Evoke misc. items, rods, or wands.
2992 if (item_is_evokable(item, false))
2997 // Unwield wielded items.
2999 wield_weapon(true, SLOT_BARE_HANDS);
3003 if (check_warning_inscriptions(item, OPER_FIRE))
3008 if (!form_can_wear())
3010 mpr("You can't wear or remove anything in your present form.");
3013 if (equipped && !equipped_weapon)
3015 if (check_warning_inscriptions(item, OPER_TAKEOFF))
3016 takeoff_armour(idx);
3018 else if (check_warning_inscriptions(item, OPER_WEAR))
3023 if (you.species != SP_VAMPIRE
3024 || item.sub_type == CORPSE_SKELETON)
3028 // intentional fall-through for Vampires
3030 if (check_warning_inscriptions(item, OPER_EAT))
3035 if (item.sub_type == BOOK_MANUAL)
3037 if (!item_is_spellbook(item) || !you.skill(SK_SPELLCASTING))
3039 if (check_warning_inscriptions(item, OPER_READ))
3040 _handle_read_book(idx);
3041 } // else it's a spellbook
3042 else if (check_warning_inscriptions(item, OPER_MEMORISE))
3043 learn_spell(); // offers all spells, might not be what we want
3047 if (check_warning_inscriptions(item, OPER_READ))
3052 if (equipped && !equipped_weapon)
3054 else if (check_warning_inscriptions(item, OPER_PUTON))
3059 if (check_warning_inscriptions(item, OPER_QUAFF))