3 * @brief Functions for making use of inventory items.
24 #include "godconduct.h"
35 #include "mgen_data.h"
38 #include "mon-place.h"
41 #include "player-equip.h"
42 #include "player-stats.h"
48 #include "spl-clouds.h"
49 #include "spl-damage.h"
50 #include "spl-goditem.h"
51 #include "spl-miscast.h"
52 #include "spl-selfench.h"
53 #include "spl-summoning.h"
54 #include "spl-transloc.h"
59 #include "transform.h"
65 static bool _drink_fountain();
66 static int _handle_enchant_armour(int item_slot = -1,
67 string *pre_msg = NULL);
69 static bool _is_cancellable_scroll(scroll_type scroll);
70 static bool _safe_to_remove_or_wear(const item_def &item, bool remove,
73 // Rather messy - we've gathered all the can't-wield logic from wield_weapon()
75 bool can_wield(item_def *weapon, bool say_reason,
76 bool ignore_temporary_disability, bool unwield, bool only_known)
78 #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 for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_WORN; i++)
114 if (you.equip[i] != -1 && &you.inv[you.equip[i]] == weapon)
116 SAY(mpr("You are wearing that object!"));
121 if (you.species == SP_FELID && is_weapon(*weapon))
123 SAY(mpr("You can't use weapons."));
127 if (weapon->base_type == OBJ_ARMOUR)
129 SAY(mpr("You can't wield armour."));
133 if (weapon->base_type == OBJ_JEWELLERY)
135 SAY(mpr("You can't wield jewellery."));
139 // Only ogres and trolls can wield giant clubs (>= 30 aum)
140 // and large rocks (60 aum).
141 if (you.body_size() < SIZE_LARGE
142 && (item_mass(*weapon) >= 500
143 || weapon->base_type == OBJ_WEAPONS
144 && item_mass(*weapon) >= 300))
146 SAY(mpr("That's too large and heavy for you to wield."));
150 // All non-weapons only need a shield check.
151 if (weapon->base_type != OBJ_WEAPONS)
153 if (!ignore_temporary_disability && is_shield_incompatible(*weapon))
155 SAY(mpr("You can't wield that with a shield."));
162 // Small species wielding large weapons...
163 if (you.body_size(PSIZE_BODY) < SIZE_MEDIUM
164 && !check_weapon_wieldable_size(*weapon, you.body_size(PSIZE_BODY)))
166 SAY(mpr("That's too large for you to wield."));
170 if (you.undead_or_demonic() && is_holy_item(*weapon)
171 && (item_type_known(*weapon) || !only_known))
175 mpr("This weapon is holy and will not allow you to wield it.");
176 // If it's a standard weapon, you know its ego now.
177 if (!is_artefact(*weapon) && !is_blessed(*weapon)
178 && !item_type_known(*weapon))
180 set_ident_flags(*weapon, ISFLAG_KNOW_TYPE);
181 if (in_inventory(*weapon))
182 mpr_nocap(weapon->name(DESC_INVENTORY_EQUIP).c_str());
184 else if (is_artefact(*weapon) && !item_type_known(*weapon))
185 artefact_wpn_learn_prop(*weapon, ARTP_BRAND);
190 if (!ignore_temporary_disability
191 && you.hunger_state < HS_FULL
192 && get_weapon_brand(*weapon) == SPWPN_VAMPIRICISM
193 && !crawl_state.game_is_zotdef()
196 && (item_type_known(*weapon) || !only_known))
200 mpr("As you grasp it, you feel a great hunger. Being not satiated, you stop.");
201 // If it's a standard weapon, you know its ego now.
202 if (!is_artefact(*weapon) && !is_blessed(*weapon)
203 && !item_type_known(*weapon))
205 set_ident_flags(*weapon, ISFLAG_KNOW_TYPE);
206 if (in_inventory(*weapon))
207 mpr_nocap(weapon->name(DESC_INVENTORY_EQUIP).c_str());
209 else if (is_artefact(*weapon) && !item_type_known(*weapon))
210 artefact_wpn_learn_prop(*weapon, ARTP_BRAND);
215 if (!ignore_temporary_disability && is_shield_incompatible(*weapon))
217 SAY(mpr("You can't wield that with a shield."));
221 // We can wield this weapon. Phew!
227 static bool _valid_weapon_swap(const item_def &item)
230 return (you.species != SP_FELID);
232 // Some misc. items need to be wielded to be evoked.
233 if (is_deck(item) || item.base_type == OBJ_MISCELLANY
234 && item.sub_type == MISC_LANTERN_OF_SHADOWS)
239 if (item.base_type == OBJ_MISSILES
240 && (item.sub_type == MI_STONE || item.sub_type == MI_LARGE_ROCK))
242 return you.has_spell(SPELL_SANDBLAST);
245 // Snakable missiles; weapons were already handled above.
246 if (item_is_snakable(item) && you.has_spell(SPELL_STICKS_TO_SNAKES))
249 // Sublimation of Blood.
250 if (!you.has_spell(SPELL_SUBLIMATION_OF_BLOOD))
253 if (item.base_type == OBJ_FOOD)
254 return (item.sub_type == FOOD_CHUNK);
256 if (item.base_type == OBJ_POTIONS && item_type_known(item))
258 return (item.sub_type == POT_BLOOD
259 || item.sub_type == POT_BLOOD_COAGULATED);
266 * @param force If true, don't check weapon inscriptions.
267 * (Assuming the player was already prompted for that.)
269 bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages,
270 bool force, bool show_unwield_msg, bool show_wield_msg)
272 const bool was_barehanded = you.equip[EQ_WEAPON] == -1;
276 canned_msg(MSG_NOTHING_CARRIED);
280 // Look for conditions like berserking that could prevent wielding
282 if (!can_wield(NULL, true, false, slot == SLOT_BARE_HANDS))
285 int item_slot = 0; // default is 'a'
289 if (item_slot == you.equip[EQ_WEAPON]
290 || you.equip[EQ_WEAPON] == -1
291 && !_valid_weapon_swap(you.inv[item_slot]))
293 item_slot = 1; // backup is 'b'
296 if (slot != -1) // allow external override
300 // If the swap slot has a bad (but valid) item in it,
301 // the swap will be to bare hands.
302 const bool good_swap = (item_slot == SLOT_BARE_HANDS
303 || _valid_weapon_swap(you.inv[item_slot]));
305 // Prompt if not using the auto swap command, or if the swap slot
307 if (item_slot != SLOT_BARE_HANDS
308 && (!auto_wield || !you.inv[item_slot].defined() || !good_swap))
312 item_slot = prompt_invent_item(
313 "Wield which item (- for none, * to show all)?",
314 MT_INVLIST, OSEL_WIELD,
315 true, true, true, '-', -1, NULL, OPER_WIELD);
318 item_slot = SLOT_BARE_HANDS;
321 if (prompt_failed(item_slot))
323 else if (item_slot == you.equip[EQ_WEAPON])
325 mpr("You are already wielding that!");
329 // Now we really change weapons! (Most likely, at least...)
330 if (you.duration[DUR_SURE_BLADE])
332 mpr("The bond with your blade fades away.");
333 you.duration[DUR_SURE_BLADE] = 0;
335 // Reset the warning counter.
336 you.received_weapon_warning = false;
338 if (item_slot == SLOT_BARE_HANDS)
340 if (const item_def* wpn = you.weapon())
342 // Can we safely unwield this item?
343 if (needs_handle_warning(*wpn, OPER_WIELD))
345 const string prompt =
346 "Really unwield " + wpn->name(DESC_INVENTORY) + "?";
347 if (!yesno(prompt.c_str(), false, 'n'))
354 if (!unwield_item(show_weff_messages))
357 if (show_unwield_msg)
358 canned_msg(MSG_EMPTY_HANDED_NOW);
360 // Switching to bare hands is extra fast.
361 you.turn_is_over = true;
363 you.time_taken /= 10;
366 canned_msg(MSG_EMPTY_HANDED_ALREADY);
371 item_def& new_wpn(you.inv[item_slot]);
373 // Non-auto_wield cases are checked below.
374 if (auto_wield && !force
375 && !check_warning_inscriptions(new_wpn, OPER_WIELD))
380 // Ensure wieldable, stat loss non-fatal
381 if (!can_wield(&new_wpn, true) || !_safe_to_remove_or_wear(new_wpn, false))
384 // Unwield any old weapon.
387 if (unwield_item(show_weff_messages))
389 // Enable skills so they can be re-disabled later
396 // Really ensure wieldable, even unknown brand
397 if (!can_wield(&new_wpn, true, false, false, false))
401 canned_msg(MSG_EMPTY_HANDED_NOW);
403 // Switching to bare hands is extra fast.
404 you.turn_is_over = true;
406 you.time_taken /= 10;
412 const unsigned int old_talents = your_talents(false).size();
414 // Go ahead and wield the weapon.
415 equip_item(EQ_WEAPON, item_slot, show_weff_messages);
418 mpr_nocap(new_wpn.name(DESC_INVENTORY_EQUIP).c_str());
420 check_item_hint(new_wpn, old_talents);
422 // Time calculations.
425 you.wield_change = true;
426 you.m_quiver->on_weapon_changed();
427 you.turn_is_over = true;
432 static const char *shield_base_name(const item_def *shield)
434 return (shield->sub_type == ARM_BUCKLER? "buckler"
438 static const char *shield_impact_degree(int impact)
440 return (impact > 160 ? "severely " :
441 impact > 130 ? "significantly " :
446 static void _warn_launcher_shield_slowdown(const item_def &launcher)
448 const int slowspeed =
449 launcher_final_speed(launcher, you.shield()) * player_speed() / 100;
450 const int normspeed =
451 launcher_final_speed(launcher, NULL) * player_speed() / 100;
453 // Don't warn the player unless the slowdown is real.
454 if (slowspeed > normspeed)
456 const char *slow_degree =
457 shield_impact_degree(slowspeed * 100 / normspeed);
462 "Your %s %sslows your rate of fire.",
463 shield_base_name(you.shield()),
469 // Warn if your shield is greatly impacting the effectiveness of your weapon?
470 void warn_shield_penalties()
475 // Warnings are limited to launchers at the moment.
476 const item_def *weapon = you.weapon();
480 if (is_range_weapon(*weapon))
481 _warn_launcher_shield_slowdown(*weapon);
484 bool item_is_worn(int inv_slot)
486 for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_WORN; ++i)
487 if (inv_slot == you.equip[i])
493 //---------------------------------------------------------------
497 // Prompt the user for some armour. Returns true if the user picked
500 //---------------------------------------------------------------
501 bool armour_prompt(const string & mesg, int *index, operation_types oper)
503 ASSERT(index != NULL);
506 canned_msg(MSG_NOTHING_CARRIED);
507 else if (you.berserk())
508 canned_msg(MSG_TOO_BERSERK);
511 int selector = OBJ_ARMOUR;
512 if (oper == OPER_TAKEOFF && !Options.equip_unequip)
513 selector = OSEL_WORN_ARMOUR;
514 int slot = prompt_invent_item(mesg.c_str(), MT_INVLIST, selector,
515 true, true, true, 0, -1, NULL,
518 if (!prompt_failed(slot))
528 static bool cloak_is_being_removed(void)
530 if (current_delay_action() != DELAY_ARMOUR_OFF)
533 if (you.delay_queue.front().parm1 != you.equip[ EQ_CLOAK ])
539 //---------------------------------------------------------------
543 //---------------------------------------------------------------
544 void wear_armour(int slot) // slot is for tiles
546 if (you.species == SP_FELID)
548 mpr("You can't wear anything.");
552 if (!form_can_wear())
554 mpr("You can't wear anything in your present form.");
558 int armour_wear_2 = 0;
561 armour_wear_2 = slot;
562 else if (!armour_prompt("Wear which item?", &armour_wear_2, OPER_WEAR))
565 do_wear_armour(armour_wear_2, false);
568 static int armour_equip_delay(const item_def &item)
570 int delay = property(item, PARM_AC);
572 // Shields are comparatively easy to wear.
574 delay = delay / 2 + 1;
582 bool can_wear_armour(const item_def &item, bool verbose, bool ignore_temporary)
584 const object_class_type base_type = item.base_type;
585 if (base_type != OBJ_ARMOUR || you.species == SP_FELID)
588 mpr("You can't wear that.");
593 const int sub_type = item.sub_type;
594 const equipment_type slot = get_armour_slot(item);
596 if (you.species == SP_OCTOPODE && slot != EQ_HELMET && slot != EQ_SHIELD)
599 mpr("You can't wear that!");
603 if (player_genus(GENPC_DRACONIAN) && slot == EQ_BODY_ARMOUR)
607 mprf("Your wings%s won't fit in that.", you.mutation[MUT_BIG_WINGS]
608 ? "" : ", even vestigial as they are,");
613 if (sub_type == ARM_NAGA_BARDING || sub_type == ARM_CENTAUR_BARDING)
615 if (you.species == SP_NAGA && sub_type == ARM_NAGA_BARDING
616 || you.species == SP_CENTAUR && sub_type == ARM_CENTAUR_BARDING)
618 if (ignore_temporary || !player_is_shapechanged())
621 mpr("You can wear that only in your normal form.");
624 mpr("You can't wear that!");
628 // Lear's hauberk covers also head, hands and legs.
629 if (is_unrandom_artefact(item) && item.special == UNRAND_LEAR)
631 if (!player_has_feet(!ignore_temporary))
634 mpr("You have no feet.");
638 if (!ignore_temporary)
640 for (int s = EQ_HELMET; s <= EQ_BOOTS; s++)
642 // No strange race can wear this.
643 const char* parts[] = { "head", "hands", "feet" };
644 // Auto-disrobing would be nice.
645 if (you.equip[s] != -1)
648 mprf("You'd need your %s free.", parts[s - EQ_HELMET]);
652 if (!you_tran_can_wear(s, true))
656 mprf(you_tran_can_wear(s) ? "The hauberk won't fit your %s."
658 parts[s - EQ_HELMET]);
665 else if (slot >= EQ_HELMET && slot <= EQ_BOOTS
667 && player_equip_unrand(UNRAND_LEAR))
669 // The explanation is iffy for loose headgear, especially crowns:
670 // kings loved hooded hauberks, according to portraits.
672 mpr("You can't wear this over your hauberk.");
676 size_type player_size = you.body_size(PSIZE_TORSO, ignore_temporary);
677 int bad_size = fit_armour_size(item, player_size);
682 mprf("This armour is too %s for you!",
683 (bad_size > 0) ? "big" : "small");
688 if (you.form == TRAN_APPENDAGE
690 && slot == beastly_slot(you.attribute[ATTR_APPENDAGE])
691 && you.mutation[you.attribute[ATTR_APPENDAGE]])
693 unwind_var<uint8_t> mutv(you.mutation[you.attribute[ATTR_APPENDAGE]], 0);
694 // disable the mutation then check again
695 return can_wear_armour(item, verbose, ignore_temporary);
698 if (sub_type == ARM_GLOVES)
700 if (you.has_claws(false) == 3)
703 mpr("You can't wear gloves with your huge claws!");
708 if (sub_type == ARM_BOOTS)
710 if (player_mutation_level(MUT_HOOVES) == 3)
713 mpr("You can't wear boots with hooves!");
717 if (you.has_talons(false) == 3)
720 mpr("Boots don't fit your talons!");
724 if (you.species == SP_NAGA || you.species == SP_DJINNI)
727 mpr("You have no legs!");
731 if (!ignore_temporary && you.fishtail)
734 mpr("You don't currently have feet!");
739 if (slot == EQ_HELMET)
741 // Horns 3 & Antennae 3 mutations disallow all headgear
742 if (player_mutation_level(MUT_HORNS) == 3)
745 mpr("You can't wear any headgear with your large horns!");
749 if (player_mutation_level(MUT_ANTENNAE) == 3)
752 mpr("You can't wear any headgear with your large antennae!");
756 // Soft helmets (caps and wizard hats) always fit, otherwise.
757 if (is_hard_helmet(item))
759 if (player_mutation_level(MUT_HORNS))
762 mpr("You can't wear that with your horns!");
766 if (player_mutation_level(MUT_BEAK))
769 mpr("You can't wear that with your beak!");
773 if (player_mutation_level(MUT_ANTENNAE))
776 mpr("You can't wear that with your antennae!");
780 if (player_genus(GENPC_DRACONIAN))
783 mpr("You can't wear that with your reptilian head.");
787 if (you.species == SP_OCTOPODE)
790 mpr("You can't wear that!");
796 if (!ignore_temporary && !form_can_wear_item(item, you.form))
799 mpr("You can't wear that in your present form.");
806 bool do_wear_armour(int item, bool quiet)
808 const item_def &invitem = you.inv[item];
809 if (!invitem.defined())
812 mpr("You don't have any such object.");
816 if (!can_wear_armour(invitem, !quiet, false))
819 const equipment_type slot = get_armour_slot(invitem);
821 if (item == you.equip[EQ_WEAPON])
824 mpr("You are wielding that object!");
828 if (item_is_worn(item))
830 if (Options.equip_unequip)
831 return !takeoff_armour(item);
834 mpr("You're already wearing that object!");
839 // if you're wielding something,
841 // attempting to wear a shield,
842 && is_shield(invitem)
843 && is_shield_incompatible(*you.weapon(), &invitem))
847 if (you.species == SP_OCTOPODE)
848 mpr("You need the rest of your tentacles for walking.");
850 mprf("You'd need three %s to do that!", you.hand_name(true).c_str());
855 bool removed_cloak = false;
858 // Removing body armour requires removing the cloak first.
859 if (slot == EQ_BODY_ARMOUR
860 && you.equip[EQ_CLOAK] != -1 && !cloak_is_being_removed())
862 if (you.equip[EQ_BODY_ARMOUR] != -1
863 && you.inv[you.equip[EQ_BODY_ARMOUR]].cursed())
867 mprf("%s is stuck to your body!",
868 you.inv[you.equip[EQ_BODY_ARMOUR]].name(DESC_YOUR)
873 if (!you.inv[you.equip[EQ_CLOAK]].cursed())
875 cloak = you.equip[EQ_CLOAK];
876 if (!takeoff_armour(you.equip[EQ_CLOAK]))
879 removed_cloak = true;
884 mpr("Your cloak prevents you from wearing the armour.");
889 if ((slot == EQ_CLOAK
894 || slot == EQ_BODY_ARMOUR)
895 && you.equip[slot] != -1)
897 if (!takeoff_armour(you.equip[slot]))
901 you.turn_is_over = true;
903 if (!_safe_to_remove_or_wear(invitem, false))
906 const int delay = armour_equip_delay(invitem);
908 start_delay(DELAY_ARMOUR_ON, delay, item);
911 start_delay(DELAY_ARMOUR_ON, 1, cloak);
916 bool takeoff_armour(int item)
918 const item_def& invitem = you.inv[item];
920 if (invitem.base_type != OBJ_ARMOUR)
922 mpr("You aren't wearing that!");
928 canned_msg(MSG_TOO_BERSERK);
932 const equipment_type slot = get_armour_slot(invitem);
933 if (item == you.equip[slot] && you.melded[slot])
935 mprf("%s is melded into your body!",
936 invitem.name(DESC_YOUR).c_str());
940 if (!item_is_worn(item))
942 if (Options.equip_unequip)
943 return do_wear_armour(item, true);
946 mpr("You aren't wearing that object!");
951 // If we get here, we're wearing the item.
952 if (invitem.cursed())
954 mprf("%s is stuck to your body!", invitem.name(DESC_YOUR).c_str());
958 if (!_safe_to_remove_or_wear(invitem, true))
961 bool removed_cloak = false;
964 if (slot == EQ_BODY_ARMOUR)
966 if (you.equip[EQ_CLOAK] != -1 && !cloak_is_being_removed())
968 if (!you.inv[you.equip[EQ_CLOAK]].cursed())
970 cloak = you.equip[ EQ_CLOAK ];
971 if (!takeoff_armour(you.equip[EQ_CLOAK]))
974 removed_cloak = true;
978 mpr("Your cloak prevents you from removing the armour.");
992 if (item != you.equip[slot])
994 mpr("You aren't wearing that!");
1004 you.turn_is_over = true;
1006 const int delay = armour_equip_delay(invitem);
1007 start_delay(DELAY_ARMOUR_OFF, delay, item);
1010 start_delay(DELAY_ARMOUR_ON, 1, cloak);
1015 static int _prompt_ring_to_remove(int new_ring)
1017 const item_def *left = you.slot_item(EQ_LEFT_RING, true);
1018 const item_def *right = you.slot_item(EQ_RIGHT_RING, true);
1021 mprf("Wearing %s.", you.inv[new_ring].name(DESC_A).c_str());
1023 const char lslot = index_to_letter(left->link);
1024 const char rslot = index_to_letter(right->link);
1027 string prompt = "You're wearing two rings. Remove which one?";
1028 Popup *pop = new Popup(prompt);
1029 pop->push_entry(new MenuEntry(prompt, MEL_TITLE));
1030 InvEntry *me = new InvEntry(*left);
1031 pop->push_entry(me);
1032 me = new InvEntry(*right);
1033 pop->push_entry(me);
1038 while (c != lslot && c != rslot && c != '<' && c != '>'
1039 && !key_is_escape(c) && c != ' ');
1043 "You're wearing two rings. Remove which one? (%c/%c/<</>/Esc)",
1046 mprf(" << or %s", left->name(DESC_INVENTORY).c_str());
1047 mprf(" > or %s", right->name(DESC_INVENTORY).c_str());
1048 flush_prev_message();
1050 // Deactivate choice from tile inventory.
1051 // FIXME: We need to be able to get the choice (item letter)
1052 // *without* the choice taking action by itself!
1053 mouse_control mc(MOUSE_MODE_PROMPT);
1057 while (c != lslot && c != rslot && c != '<' && c != '>'
1058 && !key_is_escape(c) && c != ' ');
1063 if (key_is_escape(c) || c == ' ')
1066 const int eqslot = (c == lslot || c == '<') ? EQ_LEFT_RING
1068 return you.equip[eqslot];
1071 static int _prompt_ring_to_remove_octopode(int new_ring)
1073 const item_def *rings[8];
1076 const int num_rings = (form_keeps_mutations() || you.form == TRAN_SPIDER
1079 for (int i = 0; i < num_rings; i++)
1081 rings[i] = you.slot_item((equipment_type)(EQ_RING_ONE + i), true);
1083 slots[i] = index_to_letter(rings[i]->link);
1087 // mprf("Wearing %s.", you.inv[new_ring].name(DESC_A).c_str());
1090 "You're wearing all the rings you can. Remove which one?");
1091 //I think it looks better without the letters.
1092 // (%c/%c/%c/%c/%c/%c/%c/%c/Esc)",
1093 // one_slot, two_slot, three_slot, four_slot, five_slot, six_slot, seven_slot, eight_slot);
1094 mprf(MSGCH_PROMPT, "(<w>?</w> for menu, <w>Esc</w> to cancel)");
1096 for (int i = 0; i < num_rings; i++)
1097 mprf_nocap("%s", rings[i]->name(DESC_INVENTORY).c_str());
1098 flush_prev_message();
1100 // Deactivate choice from tile inventory.
1101 // FIXME: We need to be able to get the choice (item letter)
1102 // *without* the choice taking action by itself!
1103 int eqslot = EQ_NONE;
1105 mouse_control mc(MOUSE_MODE_PROMPT);
1110 for (int i = 0; i < num_rings; i++)
1113 eqslot = EQ_RING_ONE + i;
1117 } while (!key_is_escape(c) && c != ' ' && c != '?');
1123 else if (key_is_escape(c) || eqslot == EQ_NONE)
1126 return you.equip[eqslot];
1129 // Checks whether a to-be-worn or to-be-removed item affects
1130 // character stats and whether wearing/removing it could be fatal.
1131 // If so, warns the player, or just returns false if quiet is true.
1132 static bool _safe_to_remove_or_wear(const item_def &item, bool remove, bool quiet)
1134 if (remove && !safe_to_remove(item, quiet))
1140 if (item.base_type == OBJ_JEWELLERY
1141 && item_ident(item, ISFLAG_KNOW_PLUSES))
1143 switch (item.sub_type)
1147 prop_str = item.plus;
1149 case RING_DEXTERITY:
1151 prop_dex = item.plus;
1153 case RING_INTELLIGENCE:
1155 prop_int = item.plus;
1161 else if (item.base_type == OBJ_ARMOUR && item_type_known(item))
1163 switch (item.special)
1165 case SPARM_STRENGTH:
1168 case SPARM_INTELLIGENCE:
1171 case SPARM_DEXTERITY:
1179 if (is_artefact(item))
1181 prop_str += artefact_known_wpn_property(item, ARTP_STRENGTH);
1182 prop_int += artefact_known_wpn_property(item, ARTP_INTELLIGENCE);
1183 prop_dex += artefact_known_wpn_property(item, ARTP_DEXTERITY);
1192 stat_type red_stat = NUM_STATS;
1193 if (prop_str >= you.strength() && you.strength() > 0)
1194 red_stat = STAT_STR;
1195 else if (prop_int >= you.intel() && you.intel() > 0)
1196 red_stat = STAT_INT;
1197 else if (prop_dex >= you.dex() && you.dex() > 0)
1198 red_stat = STAT_DEX;
1200 if (red_stat == NUM_STATS)
1209 if (item.base_type == OBJ_WEAPONS)
1216 if (item.base_type == OBJ_WEAPONS)
1222 string prompt = make_stringf("%sing this item will reduce your %s to zero "
1223 "or below. Continue?", verb.c_str(),
1224 stat_desc(red_stat, SD_NAME));
1225 if (!yesno(prompt.c_str(), true, 'n', true, false))
1233 // Checks whether removing an item would cause flight to end and the
1234 // player to fall to their death.
1235 bool safe_to_remove(const item_def &item, bool quiet)
1237 item_info inf = get_item_info(item);
1239 const bool grants_flight =
1240 inf.base_type == OBJ_JEWELLERY && inf.sub_type == RING_FLIGHT
1241 || inf.base_type == OBJ_ARMOUR && inf.special == SPARM_FLYING
1243 && artefact_known_wpn_property(inf, ARTP_FLY);
1245 // assumes item can't grant flight twice
1246 const bool removing_ends_flight =
1248 && !you.attribute[ATTR_FLIGHT_UNCANCELLABLE]
1249 && (you.evokable_flight() == 1);
1251 const dungeon_feature_type feat = grd(you.pos());
1253 if (grants_flight && removing_ends_flight
1254 && (feat == DNGN_LAVA
1255 || feat == DNGN_DEEP_WATER && !player_likes_water()))
1261 string fname = (feat == DNGN_LAVA ? "lava" : "deep water");
1262 string prompt = "Really remove this item over " + fname + "?";
1263 return yesno(prompt.c_str(), false, 'n');
1271 // you.inv[ring_slot] is a valid ring.
1272 // EQ_LEFT_RING and EQ_RIGHT_RING are both occupied, and ring_slot is not
1273 // one of the worn rings.
1275 // Does not do amulets.
1276 static bool _swap_rings(int ring_slot)
1278 const item_def* lring = you.slot_item(EQ_LEFT_RING, true);
1279 const item_def* rring = you.slot_item(EQ_RIGHT_RING, true);
1281 // If ring slots were melded, we should have been prevented from
1282 // putting on the ring at all. If it becomes possible for just
1283 // one ring slot to be melded, the subsequent code will need to
1284 // be revisited, so prevent that, too.
1285 ASSERT(!you.melded[EQ_LEFT_RING]);
1286 ASSERT(!you.melded[EQ_RIGHT_RING]);
1288 if (lring->cursed() && rring->cursed())
1290 mprf("You're already wearing two cursed rings!");
1296 // Don't prompt if both rings are of the same type.
1297 if ((lring->sub_type == rring->sub_type
1298 && lring->plus == rring->plus
1299 && lring->plus2 == rring->plus2
1300 && !is_artefact(*lring) && !is_artefact(*rring)) ||
1301 lring->cursed() || rring->cursed())
1303 if (lring->cursed())
1304 unwanted = you.equip[EQ_RIGHT_RING];
1306 unwanted = you.equip[EQ_LEFT_RING];
1310 // Ask the player which existing ring is persona non grata.
1311 unwanted = _prompt_ring_to_remove(ring_slot);
1320 if (!remove_ring(unwanted, false))
1323 // Check for stat loss.
1324 if (!_safe_to_remove_or_wear(you.inv[ring_slot], false))
1327 // Put on the new ring.
1328 start_delay(DELAY_JEWELLERY_ON, 1, ring_slot);
1333 static bool _swap_rings_octopode(int ring_slot)
1335 const item_def* ring[8];
1336 for (int i = 0; i < 8; i++)
1337 ring[i] = you.slot_item((equipment_type)(EQ_RING_ONE + i), true);
1341 int melded = 0; // Both melded rings and unavailable slots.
1344 for (int slots = EQ_RING_ONE;
1345 slots < NUM_EQUIP && array < 8;
1348 if (!you_tran_can_wear(slots) || you.melded[slots])
1350 else if (ring[array] != NULL)
1352 if (ring[array]->cursed())
1357 unwanted = you.equip[slots];
1362 // We can't put a ring on, because we're wearing 8 cursed ones.
1365 // Shouldn't happen, because hogs and bats can't put on jewellery at
1366 // all and thus won't get this far.
1367 mpr("You can't wear that in your present form.");
1370 else if (available == 0)
1372 mprf("You're already wearing %s cursed rings!%s",
1373 number_in_words(cursed).c_str(),
1374 (cursed == 8 ? " Isn't that enough for you?" : ""));
1377 // The simple case - only one available ring.
1378 else if (available == 1)
1380 if (!remove_ring(unwanted, false))
1383 // We can't put a ring on without swapping - because we found
1384 // multiple available rings.
1385 else if (available > 1)
1387 unwanted = _prompt_ring_to_remove_octopode(ring_slot);
1396 if (!remove_ring(unwanted, false))
1401 // In case something goes wrong.
1409 // Put on the new ring.
1410 start_delay(DELAY_JEWELLERY_ON, 1, ring_slot);
1415 static bool _puton_item(int item_slot)
1417 item_def& item = you.inv[item_slot];
1419 for (int eq = EQ_LEFT_RING; eq < NUM_EQUIP; eq++)
1420 if (item_slot == you.equip[eq])
1422 // "Putting on" an equipped item means taking it off.
1423 if (Options.equip_unequip)
1424 return !remove_ring(item_slot);
1427 mpr("You're already wearing that object!");
1432 if (item_slot == you.equip[EQ_WEAPON])
1434 mpr("You are wielding that object.");
1438 if (item.base_type != OBJ_JEWELLERY)
1440 mpr("You can only put on jewellery.");
1444 const bool lring = you.slot_item(EQ_LEFT_RING, true);
1445 const bool rring = you.slot_item(EQ_RIGHT_RING, true);
1446 const bool is_amulet = jewellery_is_amulet(item);
1447 bool blinged_octopode = false;
1448 if (you.species == SP_OCTOPODE)
1450 blinged_octopode = true;
1451 for (int eq = EQ_RING_ONE; eq <= EQ_RING_EIGHT; eq++)
1453 // Skip unavailable slots.
1454 if (!you_tran_can_wear(eq))
1457 if (!you.slot_item((equipment_type)eq, true))
1459 blinged_octopode = false;
1465 if (!is_amulet) // i.e. it's a ring
1467 if (!you_tran_can_wear(item))
1469 mpr("You can't wear that in your present form.");
1473 const item_def* gloves = you.slot_item(EQ_GLOVES, false);
1474 // Cursed gloves cannot be removed.
1475 if (gloves && gloves->cursed())
1477 mpr("You can't take your gloves off to put on a ring!");
1481 if (blinged_octopode)
1482 return _swap_rings_octopode(item_slot);
1485 return _swap_rings(item_slot);
1487 else if (item_def* amulet = you.slot_item(EQ_AMULET, true))
1489 // Remove the previous one.
1490 if (!check_warning_inscriptions(*amulet, OPER_REMOVE)
1491 || !remove_ring(you.equip[EQ_AMULET], true))
1496 // Check for stat loss.
1497 if (!_safe_to_remove_or_wear(item, false))
1500 // Put on the new amulet.
1501 start_delay(DELAY_JEWELLERY_ON, 1, item_slot);
1503 // Assume it's going to succeed.
1507 // Check for stat loss.
1508 if (!_safe_to_remove_or_wear(item, false))
1511 equipment_type hand_used;
1514 hand_used = EQ_AMULET;
1515 else if (you.species == SP_OCTOPODE)
1517 for (hand_used = EQ_RING_ONE; hand_used <= EQ_RING_EIGHT;
1518 hand_used = (equipment_type)(hand_used + 1))
1520 // Skip unavailble slots.
1521 if (!you_tran_can_wear(hand_used))
1524 if (!you.slot_item(hand_used, true))
1527 ASSERT(hand_used <= EQ_RING_EIGHT);
1531 // First ring always goes on left hand.
1532 hand_used = EQ_LEFT_RING;
1534 // ... unless we're already wearing a ring on the left hand.
1535 if (lring && !rring)
1536 hand_used = EQ_RIGHT_RING;
1539 const unsigned int old_talents = your_talents(false).size();
1541 // Actually equip the item.
1542 equip_item(hand_used, item_slot);
1544 check_item_hint(you.inv[item_slot], old_talents);
1545 #ifdef USE_TILE_LOCAL
1546 if (your_talents(false).size() != old_talents)
1548 tiles.layout_statcol();
1553 // Putting on jewellery is as fast as wielding weapons.
1554 you.time_taken /= 2;
1555 you.turn_is_over = true;
1560 bool puton_ring(int slot)
1564 if (inv_count() < 1)
1566 canned_msg(MSG_NOTHING_CARRIED);
1572 canned_msg(MSG_TOO_BERSERK);
1580 item_slot = prompt_invent_item("Put on which piece of jewellery?",
1581 MT_INVLIST, OBJ_JEWELLERY, true, true,
1582 true, 0, -1, NULL, OPER_PUTON);
1585 if (prompt_failed(item_slot))
1588 return _puton_item(item_slot);
1591 bool remove_ring(int slot, bool announce)
1593 equipment_type hand_used = EQ_NONE;
1595 bool has_jewellery = false;
1596 bool has_melded = false;
1597 const equipment_type first = you.species == SP_OCTOPODE ? EQ_AMULET
1599 const equipment_type last = you.species == SP_OCTOPODE ? EQ_RING_EIGHT
1602 for (int eq = first; eq <= last; eq++)
1604 if (player_wearing_slot(eq))
1608 // At least one other piece, which means we'll have to ask
1609 hand_used = EQ_NONE;
1612 hand_used = (equipment_type) eq;
1614 has_jewellery = true;
1616 else if (you.melded[eq])
1623 mpr("You aren't wearing any unmelded rings or amulets.");
1625 mpr("You aren't wearing any rings or amulets.");
1632 canned_msg(MSG_TOO_BERSERK);
1636 const item_def* gloves = you.slot_item(EQ_GLOVES);
1637 const bool gloves_cursed = gloves && gloves->cursed();
1638 if (gloves_cursed && !player_wearing_slot(EQ_AMULET))
1640 mpr("You can't take your gloves off to remove any rings!");
1644 if (hand_used == EQ_NONE)
1647 (slot == -1)? prompt_invent_item("Remove which piece of jewellery?",
1649 OBJ_JEWELLERY, true, true, true,
1650 0, -1, NULL, OPER_REMOVE)
1653 if (prompt_failed(equipn))
1656 hand_used = item_equip_slot(you.inv[equipn]);
1657 if (hand_used == EQ_NONE)
1659 mpr("You aren't wearing that.");
1662 else if (you.inv[equipn].base_type != OBJ_JEWELLERY)
1664 mpr("That isn't a piece of jewellery.");
1669 if (you.equip[hand_used] == -1)
1671 mpr("I don't think you really meant that.");
1674 else if (you.melded[hand_used])
1676 mpr("You can't take that off while it's melded.");
1679 else if (gloves_cursed
1680 && (hand_used == EQ_LEFT_RING || hand_used == EQ_RIGHT_RING))
1682 mpr("You can't take your gloves off to remove any rings!");
1686 if (!check_warning_inscriptions(you.inv[you.equip[hand_used]],
1693 if (you.inv[you.equip[hand_used]].cursed())
1697 mprf("%s is stuck to you!",
1698 you.inv[you.equip[hand_used]].name(DESC_YOUR).c_str());
1701 mpr("It's stuck to you!");
1703 set_ident_flags(you.inv[you.equip[hand_used]], ISFLAG_KNOW_CURSE);
1707 ring_wear_2 = you.equip[hand_used];
1710 if (!_safe_to_remove_or_wear(you.inv[ring_wear_2], true))
1713 mprf("You remove %s.", you.inv[ring_wear_2].name(DESC_YOUR).c_str());
1714 #ifdef USE_TILE_LOCAL
1715 const unsigned int old_talents = your_talents(false).size();
1717 unequip_item(hand_used);
1718 #ifdef USE_TILE_LOCAL
1719 if (your_talents(false).size() != old_talents)
1721 tiles.layout_statcol();
1726 you.time_taken /= 2;
1727 you.turn_is_over = true;
1732 static int _wand_range(zap_type ztype)
1734 // FIXME: Eventually we should have sensible values here.
1738 static int _max_wand_range()
1743 static bool _dont_use_invis()
1748 if (you.haloed() || you.glows_naturally())
1750 mpr("You can't turn invisible.");
1753 else if (get_contamination_level() > 1
1754 && !yesno("Invisibility will do you no good right now; "
1755 "use anyway?", false, 'n'))
1764 static targetter *_wand_targetter(const item_def *wand)
1766 int range = _wand_range(wand->zap());
1767 const int power = 15 + you.skill(SK_EVOCATIONS, 5) / 2;
1769 switch (wand->sub_type)
1772 return new targetter_beam(&you, range, ZAP_FIREBALL, power, 1, 1);
1773 case WAND_LIGHTNING:
1774 return new targetter_beam(&you, range, ZAP_LIGHTNING_BOLT, power, 0, 0);
1776 return new targetter_beam(&you, range, ZAP_THROW_FLAME, power, 0, 0);
1778 return new targetter_beam(&you, range, ZAP_BOLT_OF_FIRE, power, 0, 0);
1780 return new targetter_beam(&you, range, ZAP_THROW_FROST, power, 0, 0);
1782 return new targetter_beam(&you, range, ZAP_BOLT_OF_COLD, power, 0, 0);
1788 void zap_wand(int slot)
1790 if (you.species == SP_FELID || !form_can_use_wand())
1792 mpr("You have no means to grasp a wand firmly enough.");
1800 // Unless the character knows the type of the wand, the targetting
1801 // system will default to enemies. -- [ds]
1802 targ_mode_type targ_mode = TARG_HOSTILE;
1804 beam.obvious_effect = false;
1805 beam.beam_source = MHITYOU;
1807 if (inv_count() < 1)
1809 canned_msg(MSG_NOTHING_CARRIED);
1815 canned_msg(MSG_TOO_BERSERK);
1823 item_slot = prompt_invent_item("Zap which item?",
1826 true, true, true, 0, -1, NULL,
1830 if (prompt_failed(item_slot))
1833 item_def& wand = you.inv[item_slot];
1834 if (wand.base_type != OBJ_WANDS)
1836 canned_msg(MSG_NOTHING_HAPPENS);
1840 // If you happen to be wielding the wand, its display might change.
1841 if (you.equip[EQ_WEAPON] == item_slot)
1842 you.wield_change = true;
1844 const zap_type type_zapped = wand.zap();
1846 bool has_charges = true;
1849 if (wand.plus2 == ZAPCOUNT_EMPTY)
1851 mpr("This wand has no charges.");
1854 has_charges = false;
1857 const bool alreadyknown = item_type_known(wand);
1858 const bool alreadytried = item_type_tried(wand);
1859 bool invis_enemy = false;
1860 const bool dangerous = player_in_a_dangerous_place(&invis_enemy);
1861 targetter *hitfunc = 0;
1864 beam.effect_known = false;
1867 switch (wand.sub_type)
1870 case WAND_TELEPORTATION:
1871 targ_mode = TARG_ANY;
1874 case WAND_HEAL_WOUNDS:
1875 if (you.religion == GOD_ELYVILON)
1877 targ_mode = TARG_ANY;
1880 // else intentional fall-through
1882 case WAND_INVISIBILITY:
1883 targ_mode = TARG_FRIEND;
1887 targ_mode = TARG_HOSTILE;
1891 hitfunc = _wand_targetter(&wand);
1894 const int tracer_range =
1895 (alreadyknown && wand.sub_type != WAND_RANDOM_EFFECTS) ?
1896 _wand_range(type_zapped) : _max_wand_range();
1897 const string zap_title =
1898 "Zapping: " + get_menu_colour_prefix_tags(wand, DESC_INVENTORY);
1899 direction_chooser_args args;
1900 args.mode = targ_mode;
1901 args.range = tracer_range;
1902 args.top_prompt = zap_title;
1903 args.hitfunc = hitfunc;
1904 direction(zap_wand, args);
1909 if (!zap_wand.isValid)
1911 if (zap_wand.isCancel)
1916 if (alreadyknown && zap_wand.target == you.pos())
1918 if (wand.sub_type == WAND_TELEPORTATION
1919 && you.no_tele(false, false))
1921 mpr("You cannot teleport right now.");
1924 else if (wand.sub_type == WAND_INVISIBILITY
1925 && _dont_use_invis())
1933 canned_msg(MSG_NOTHING_HAPPENS);
1934 // It's an empty wand; inscribe it that way.
1935 wand.plus2 = ZAPCOUNT_EMPTY;
1936 you.turn_is_over = true;
1941 zap_wand.confusion_fuzz();
1943 if (wand.sub_type == WAND_RANDOM_EFFECTS)
1944 beam.effect_known = false;
1946 beam.source = you.pos();
1947 beam.attitude = ATT_FRIENDLY;
1948 beam.set_target(zap_wand);
1950 const bool aimed_at_self = (beam.target == you.pos());
1951 const int power = 15 + you.skill(SK_EVOCATIONS, 5) / 2;
1953 // Check whether we may hit friends, use "safe" values for random effects
1954 // and unknown wands (highest possible range, and unresistable beam
1955 // flavour). Don't use the tracer if firing at self.
1958 beam.range = tracer_range;
1959 if (!player_tracer(beam.effect_known ? type_zapped
1960 : ZAP_DEBUGGING_RAY,
1961 power, beam, beam.effect_known ? 0 : 17))
1967 // Zapping the wand isn't risky if you aim it away from all monsters
1968 // and yourself, unless there's a nearby invisible enemy and you're
1969 // trying to hit it at random.
1970 const bool risky = dangerous && (beam.friend_info.count
1971 || beam.foe_info.count
1975 if (risky && alreadyknown && wand.sub_type == WAND_RANDOM_EFFECTS)
1977 // Xom loves it when you use a Wand of Random Effects and
1978 // there is a dangerous monster nearby...
1979 xom_is_stimulated(200);
1983 beam.range = _wand_range(type_zapped);
1988 string str = wand.inscription;
1989 int wiz_range = strip_number_tag(str, "range:");
1990 if (wiz_range != TAG_UNFOUND)
1991 beam.range = wiz_range;
1995 // zapping() updates beam.
1996 zapping(type_zapped, power, beam);
1998 // Take off a charge.
2001 // Zap counts count from the last recharge.
2002 if (wand.plus2 == ZAPCOUNT_RECHARGED)
2004 // Increment zap count.
2005 if (wand.plus2 >= 0)
2008 // Identify if necessary.
2009 if (!alreadyknown && (beam.obvious_effect || type_zapped == ZAP_FIREBALL))
2011 set_ident_type(wand, ID_KNOWN_TYPE);
2012 if (wand.sub_type == WAND_RANDOM_EFFECTS)
2013 mpr("You feel that this wand is rather unreliable.");
2015 mpr_nocap(wand.name(DESC_INVENTORY_EQUIP).c_str());
2018 set_ident_type(wand, ID_TRIED_TYPE);
2020 if (item_type_known(wand)
2021 && (item_ident(wand, ISFLAG_KNOW_PLUSES)
2022 || you.skill(SK_EVOCATIONS, 10) > 50 + random2(141)))
2024 if (!item_ident(wand, ISFLAG_KNOW_PLUSES))
2026 mpr("Your skill with magical items lets you calculate "
2027 "the power of this device...");
2030 mprf("This wand has %d charge%s left.",
2031 wand.plus, wand.plus == 1 ? "" : "s");
2033 set_ident_flags(wand, ISFLAG_KNOW_PLUSES);
2035 // Mark as empty if necessary.
2036 if (wand.plus == 0 && wand.flags & ISFLAG_KNOW_PLUSES)
2037 wand.plus2 = ZAPCOUNT_EMPTY;
2039 practise(EX_DID_ZAP_WAND);
2040 count_action(CACT_EVOKE, EVOC_WAND);
2041 alert_nearby_monsters();
2043 if (!alreadyknown && !alreadytried && risky)
2045 // Xom loves it when you use an unknown wand and there is a
2046 // dangerous monster nearby...
2047 xom_is_stimulated(200);
2050 you.turn_is_over = true;
2053 void prompt_inscribe_item()
2055 if (inv_count() < 1)
2057 mpr("You don't have anything to inscribe.");
2061 int item_slot = prompt_invent_item("Inscribe which item?",
2062 MT_INVLIST, OSEL_ANY);
2064 if (prompt_failed(item_slot))
2067 inscribe_item(you.inv[item_slot], true);
2070 static void _vampire_corpse_help()
2072 if (you.species != SP_VAMPIRE)
2075 if (check_blood_corpses_on_ground() || count_corpses_in_pack(true) > 0)
2076 mpr("If it's blood you're after, try <w>e</w>.");
2079 void drink(int slot)
2081 if (you_foodless(true))
2083 if (you.form == TRAN_TREE)
2084 mpr("It'd take too long for a potion to reach your roots.");
2086 mpr("You can't drink.");
2092 const dungeon_feature_type feat = grd(you.pos());
2093 if (feat >= DNGN_FOUNTAIN_BLUE && feat <= DNGN_FOUNTAIN_BLOOD)
2094 if (_drink_fountain())
2098 if (inv_count() == 0)
2100 canned_msg(MSG_NOTHING_CARRIED);
2101 _vampire_corpse_help();
2107 canned_msg(MSG_TOO_BERSERK);
2111 if (you.form == TRAN_BAT)
2113 canned_msg(MSG_PRESENT_FORM);
2114 _vampire_corpse_help();
2118 if (you.duration[DUR_RETCHING])
2120 mpr("You can't gag anything down in your present state!");
2126 slot = prompt_invent_item("Drink which item?",
2127 MT_INVLIST, OBJ_POTIONS,
2128 true, true, true, 0, -1, NULL,
2130 if (prompt_failed(slot))
2132 _vampire_corpse_help();
2137 item_def& potion = you.inv[slot];
2139 if (potion.base_type != OBJ_POTIONS)
2141 if (you.species == SP_VAMPIRE && potion.base_type == OBJ_CORPSES)
2144 mpr("You can't drink that!");
2148 const bool alreadyknown = item_type_known(potion);
2150 if (you.duration[DUR_FREEZING]
2152 && !(you.conservation() && !one_chance_in(10))
2153 && !(you.mutation[MUT_CONSERVE_POTIONS] && !one_chance_in(10)))
2155 const string item_name = quant_name(you.inv[slot], 1, DESC_THE);
2156 mprf("%s freezes and shatters!",
2158 dec_inv_item_quantity(slot, 1);
2159 count_action(CACT_USE, OBJ_POTIONS);
2160 you.turn_is_over = true;
2164 if (alreadyknown && you.hunger_state == HS_ENGORGED
2165 && (is_blood_potion(potion) || potion.sub_type == POT_PORRIDGE))
2167 mpr("You are much too full right now.");
2171 if (alreadyknown && potion.sub_type == POT_INVISIBILITY
2172 && _dont_use_invis())
2177 if (alreadyknown && potion.sub_type == POT_BERSERK_RAGE
2178 && (!berserk_check_wielded_weapon()
2179 || !you.can_go_berserk(true, true)))
2184 // The "> 1" part is to reduce the amount of times that Xom is
2185 // stimulated when you are a low-level 1 trying your first unknown
2186 // potions on monsters.
2187 const bool dangerous = (player_in_a_dangerous_place()
2188 && you.experience_level > 1);
2189 potion_type pot_type = (potion_type)potion.sub_type;
2191 // Identify item and type.
2192 if (potion_effect(static_cast<potion_type>(potion.sub_type),
2193 40, true, alreadyknown))
2195 set_ident_flags(potion, ISFLAG_IDENT_MASK);
2196 set_ident_type(potion, ID_KNOWN_TYPE);
2197 mpr("It was a " + potion.name(DESC_QUALNAME) + ".");
2199 else if (!alreadyknown)
2201 // Because all potions are identified upon quaffing we never come here.
2202 set_ident_type(potion, ID_TRIED_TYPE);
2205 if (!alreadyknown && dangerous)
2207 // Xom loves it when you drink an unknown potion and there is
2208 // a dangerous monster nearby...
2209 xom_is_stimulated(200);
2212 if (is_blood_potion(potion))
2214 // Always drink oldest potion.
2215 remove_oldest_blood_potion(potion);
2218 dec_inv_item_quantity(slot, 1);
2219 count_action(CACT_USE, OBJ_POTIONS);
2220 you.turn_is_over = true;
2222 if (you.species != SP_VAMPIRE)
2223 lessen_hunger(40, true);
2225 // This got deferred from the it_use2 switch to prevent SIGHUP abuse.
2226 if (pot_type == POT_EXPERIENCE)
2230 static bool _drink_fountain()
2232 const dungeon_feature_type feat = grd(you.pos());
2234 if (feat < DNGN_FOUNTAIN_BLUE || feat > DNGN_FOUNTAIN_BLOOD)
2239 canned_msg(MSG_TOO_BERSERK);
2243 potion_type fountain_effect = NUM_POTIONS;
2244 if (feat == DNGN_FOUNTAIN_BLUE)
2246 if (!yesno("Drink from the fountain?", true, 'n'))
2249 mpr("You drink the pure, clear water.");
2251 else if (feat == DNGN_FOUNTAIN_BLOOD)
2253 if (!yesno("Drink from the fountain of blood?", true, 'n'))
2256 mpr("You drink the blood.");
2257 fountain_effect = POT_BLOOD;
2261 if (!yesno("Drink from the sparkling fountain?", true, 'n'))
2264 mpr("You drink the sparkling water.");
2267 random_choose_weighted(467, NUM_POTIONS,
2271 40, POT_HEAL_WOUNDS,
2276 32, POT_DEGENERATION,
2282 27, POT_INVISIBILITY,
2284 20, POT_RESTORE_ABILITIES,
2286 20, POT_STRONG_POISON,
2287 20, POT_BERSERK_RAGE,
2288 12, POT_BENEFICIAL_MUTATION,
2292 if (fountain_effect != NUM_POTIONS && fountain_effect != POT_BLOOD)
2293 xom_is_stimulated(50);
2295 // Good gods do not punish for bad random effects. However, they do
2296 // punish drinking from a fountain of blood.
2297 potion_effect(fountain_effect, 100, true, feat != DNGN_FOUNTAIN_SPARKLING, true);
2299 bool gone_dry = false;
2300 if (feat == DNGN_FOUNTAIN_BLUE)
2302 if (one_chance_in(20))
2305 else if (feat == DNGN_FOUNTAIN_BLOOD)
2307 // High chance of drying up, to prevent abuse.
2308 if (one_chance_in(3))
2311 else // sparkling fountain
2313 if (one_chance_in(10))
2315 else if (random2(50) > 40)
2317 // Turn fountain into a normal fountain without any message
2318 // but the glyph colour gives it away (lightblue vs. blue).
2319 grd(you.pos()) = DNGN_FOUNTAIN_BLUE;
2320 set_terrain_changed(you.pos());
2326 mpr("The fountain dries up!");
2328 grd(you.pos()) = static_cast<dungeon_feature_type>(feat
2329 + DNGN_DRY_FOUNTAIN_BLUE - DNGN_FOUNTAIN_BLUE);
2331 set_terrain_changed(you.pos());
2333 crawl_state.cancel_cmd_repeat();
2336 you.turn_is_over = true;
2340 static void _explosion(coord_def where, actor *agent, beam_type flavour,
2341 string name, string cause)
2344 beam.is_explosion = true;
2345 beam.aux_source = cause;
2346 beam.source = where;
2347 beam.target = where;
2348 beam.set_agent(agent);
2350 beam.damage = dice_def(5, 8);
2352 beam.flavour = flavour;
2353 beam.hit = AUTOMATIC_HIT;
2356 beam.explode(true, false);
2359 // Returns true if a message has already been printed (which will identify
2361 static bool _vorpalise_weapon(bool already_known)
2366 // Check if you're wielding a brandable weapon.
2367 item_def& wpn = *you.weapon();
2368 if (wpn.base_type != OBJ_WEAPONS || wpn.sub_type == WPN_BLOWGUN
2369 || is_artefact(wpn))
2374 you.wield_change = true;
2376 // If there's no brand, make it vorpal.
2377 if (get_weapon_brand(wpn) == SPWPN_NORMAL)
2379 alert_nearby_monsters();
2380 mprf("%s emits a brilliant flash of light!",
2381 wpn.name(DESC_YOUR).c_str());
2382 set_item_ego_type(wpn, OBJ_WEAPONS, SPWPN_VORPAL);
2386 // If there's a permanent brand, fail.
2387 if (you.duration[DUR_WEAPON_BRAND] == 0)
2390 // There's a temporary brand, attempt to make it permanent.
2391 const string itname = wpn.name(DESC_YOUR);
2392 bool success = true;
2395 switch (get_weapon_brand(wpn))
2398 if (get_vorpal_type(wpn) != DVORP_CRUSHING)
2399 mprf("%s's sharpness seems more permanent.", itname.c_str());
2401 mprf("%s's heaviness feels very stable.", itname.c_str());
2406 mprf("%s is engulfed in an explosion of flames!", itname.c_str());
2407 immolation(10, IMMOLATION_AFFIX, you.pos(), already_known, &you);
2411 case SPWPN_FREEZING:
2412 if (cast_los_attack_spell(SPELL_OZOCUBUS_REFRIGERATION, 60,
2413 (already_known) ? &you : NULL, true)
2420 mprf("%s is covered with a thick layer of frost!", itname.c_str());
2423 case SPWPN_DRAINING:
2424 mprf("%s thirsts for the lives of mortals!", itname.c_str());
2425 drain_exp(true, NON_MONSTER, "draining affixation");
2429 if (cast_los_attack_spell(SPELL_OLGREBS_TOXIC_RADIANCE, 60,
2430 (already_known) ? &you : NULL, true)
2437 mprf("%s seems more permanently poisoned.", itname.c_str());
2440 case SPWPN_ELECTROCUTION:
2441 mprf("%s releases a massive orb of lightning.", itname.c_str());
2442 _explosion(you.pos(), &you, BEAM_ELECTRICITY, "electricity",
2443 "electrocution affixation");
2447 mprf("%s erupts in a glittering mayhem of all colours.", itname.c_str());
2448 // need to affix it immediately, otherwise transformation will break it
2449 you.duration[DUR_WEAPON_BRAND] = 0;
2450 xom_is_stimulated(200);
2451 // but the eruption _is_ guaranteed. What it will do is not.
2452 _explosion(you.pos(), &you, BEAM_CHAOS, "chaos eruption", "chaos affixation");
2453 switch (random2(coinflip() ? 2 : 4))
2456 if (transform(50, coinflip() ? TRAN_PIG :
2457 coinflip() ? TRAN_DRAGON :
2460 // after getting possibly banished, we don't want you to just
2461 // say "end transformation" immediately
2462 you.transform_uncancellable = true;
2466 if (you.can_safely_mutate())
2468 // not funny on the undead
2469 mutate(RANDOM_MUTATION, "chaos affixation");
2473 xom_acts(coinflip(), HALF_MAX_PIETY, 0); // ignore tension
2480 // Can't fix pain brand (balance)...you just get tormented.
2481 mprf("%s shrieks out in agony!", itname.c_str());
2483 torment_monsters(you.pos(), &you, TORMENT_GENERIC);
2486 // This is only naughty if you know you're doing it.
2487 // XXX: assumes this can only happen from Vorpalise Weapon scroll.
2488 did_god_conduct(DID_NECROMANCY, 10,
2489 get_ident_type(OBJ_SCROLLS, SCR_VORPALISE_WEAPON)
2493 case SPWPN_DISTORTION:
2494 // [dshaligram] Attempting to fix a distortion brand gets you a free
2495 // distortion effect, and no permabranding. Sorry, them's the breaks.
2496 mprf("%s twongs alarmingly.", itname.c_str());
2498 // from unwield_item
2499 MiscastEffect(&you, NON_MONSTER, SPTYP_TRANSLOCATION, 9, 90,
2500 "distortion affixation");
2504 case SPWPN_ANTIMAGIC:
2505 mprf("%s repels your magic.", itname.c_str());
2506 drain_mp(you.species == SP_DJINNI ? 100 : you.magic_points);
2510 case SPWPN_HOLY_WRATH:
2511 mprf("%s emits a blast of cleansing flame.", itname.c_str());
2512 _explosion(you.pos(), &you, BEAM_HOLY, "cleansing flame",
2513 "holy wrath affixation");
2525 you.duration[DUR_WEAPON_BRAND] = 0;
2526 item_set_appearance(wpn);
2531 bool enchant_weapon(item_def &wpn, int acc, int dam, const char *colour)
2533 bool success = false;
2535 // Get item name now before changing enchantment.
2536 string iname = wpn.name(DESC_YOUR);
2537 const char *s = wpn.quantity == 1 ? "s" : "";
2539 // Blowguns only have one stat.
2540 if (wpn.base_type == OBJ_WEAPONS && wpn.sub_type == WPN_BLOWGUN)
2548 if (!is_artefact(wpn) && wpn.base_type == OBJ_WEAPONS)
2552 if (wpn.plus < 4 || !x_chance_in_y(wpn.plus, MAX_WPN_ENCHANT))
2553 wpn.plus++, success = true;
2557 if (wpn.plus2 < 4 || !x_chance_in_y(wpn.plus2, MAX_WPN_ENCHANT))
2558 wpn.plus2++, success = true;
2560 if (success && colour)
2561 mprf("%s glow%s %s for a moment.", iname.c_str(), s, colour);
2565 if (!success && colour)
2567 if (const char *space = strchr(colour, ' '))
2569 mprf("%s glow%s silvery %s for a moment.", iname.c_str(), s, colour);
2571 do_uncurse_item(wpn, true, true);
2576 if (!success && colour)
2579 iname = "Your " + you.hand_name(true);
2580 mprf("%s very briefly gain%s a %s sheen.", iname.c_str(), s, colour);
2584 you.wield_change = true;
2589 static void _handle_enchant_weapon(int acc, int dam, const char *colour)
2591 item_def nothing, *weapon = you.weapon();
2594 enchant_weapon(*weapon, acc, dam, colour);
2597 bool enchant_armour(int &ac_change, bool quiet, item_def &arm)
2599 ASSERT(arm.defined() && arm.base_type == OBJ_ARMOUR);
2603 // Cannot be enchanted nor uncursed.
2604 if (!is_enchantable_armour(arm, true))
2607 canned_msg(MSG_NOTHING_HAPPENS);
2612 const bool is_cursed = arm.cursed();
2614 // Turn hides into mails where applicable.
2615 // NOTE: It is assumed that armour which changes in this way does
2616 // not change into a form of armour with a different evasion modifier.
2617 if (armour_is_hide(arm, false))
2621 mprf("%s glows purple and changes!",
2622 arm.name(DESC_YOUR).c_str());
2625 ac_change = property(arm, PARM_AC);
2627 ac_change = property(arm, PARM_AC) - ac_change;
2629 do_uncurse_item(arm, true, true);
2631 // No additional enchantment.
2635 // Even if not affected, it may be uncursed.
2636 if (!is_enchantable_armour(arm, false))
2642 mprf("%s glows silver for a moment.",
2643 arm.name(DESC_YOUR).c_str());
2646 do_uncurse_item(arm, true, true);
2652 canned_msg(MSG_NOTHING_HAPPENS);
2658 // Output message before changing enchantment and curse status.
2661 mprf("%s glows green for a moment.",
2662 arm.name(DESC_YOUR).c_str());
2667 do_uncurse_item(arm, true, true);
2672 static int _handle_enchant_armour(int item_slot, string *pre_msg)
2676 if (item_slot == -1)
2678 item_slot = prompt_invent_item("Enchant which item?", MT_INVLIST,
2679 OSEL_ENCH_ARM, true, true, false);
2681 if (prompt_failed(item_slot))
2684 item_def& arm(you.inv[item_slot]);
2686 if (!is_enchantable_armour(arm, true, true))
2688 mpr("Choose some type of armour to enchant, or Esc to abort.");
2689 if (Options.auto_list)
2696 // Okay, we may actually (attempt to) enchant something.
2698 mpr(pre_msg->c_str());
2701 bool result = enchant_armour(ac_change, false, arm);
2704 you.redraw_armour_class = true;
2706 return result ? 1 : 0;
2713 static void _handle_read_book(int item_slot)
2717 canned_msg(MSG_TOO_BERSERK);
2721 if (you.stat_zero[STAT_INT])
2723 mpr("Reading books requires mental cohesion, which you lack.");
2727 item_def& book(you.inv[item_slot]);
2728 ASSERT(book.sub_type != BOOK_MANUAL);
2730 if (book.sub_type == BOOK_DESTRUCTION)
2732 if (silenced(you.pos()))
2733 mpr("This book does not work if you cannot read it aloud!");
2735 tome_of_power(item_slot);
2742 const int ltr = read_book(book, RBOOK_READ_SPELL);
2744 if (ltr < 'a' || ltr > 'h') //jmf: was 'g', but 8=h
2750 const spell_type spell = which_spell_in_book(book,
2751 letter_to_index(ltr));
2752 if (spell == SPELL_NO_SPELL)
2758 describe_spell(spell, &book);
2760 // Player memorised spell which was being looked at.
2761 if (you.turn_is_over)
2766 // For unidentified scrolls of recharging, identify and enchant armour
2767 // offer full choice of inventory and only identify the scroll if you chose
2768 // something that is affected by the scroll. Once they're identified, you'll
2769 // get the limited inventory listing.
2770 // Returns true if the scroll had an obvious effect and should be identified.
2771 static bool _scroll_modify_item(item_def scroll)
2773 ASSERT(scroll.base_type == OBJ_SCROLLS);
2780 // Get the slot of the item the scroll is to be used on.
2781 // Ban the scroll's own slot from the prompt to avoid the stupid situation
2782 // where you use identify on itself.
2783 item_slot = prompt_invent_item("Use on which item? (\\ to view known items)",
2784 MT_INVLIST, OSEL_SCROLL_TARGET, true, true, false, 0,
2785 scroll.link, NULL, OPER_ANY, true);
2787 if (item_slot == PROMPT_NOTHING)
2790 if (item_slot == PROMPT_ABORT
2791 && yesno("Really abort (and waste the scroll)?"))
2797 while (item_slot < 0);
2799 item_def &item = you.inv[item_slot];
2801 if (item_is_melded(you.inv[item_slot]))
2803 mpr("This item is melded into your body!");
2804 if (Options.auto_list)
2809 bool show_msg = true;
2810 const char* id_prop = nullptr;
2812 switch (scroll.sub_type)
2815 if (!fully_identified(item) || is_deck(item) && !top_card_is_known(item))
2817 identify(-1, item_slot);
2824 case SCR_RECHARGING:
2825 if (item_is_rechargeable(item) && recharge_wand(item_slot, false))
2830 case SCR_ENCHANT_ARMOUR:
2831 if (is_enchantable_armour(item, true))
2833 // Might still fail because of already high enchantment.
2834 // (If so, already prints the "Nothing happens" message.)
2835 if (_handle_enchant_armour(item_slot) > 0)
2844 mprf("Buggy scroll %d can't modify item!", scroll.sub_type);
2849 you.type_id_props[id_prop] = item.name(DESC_PLAIN, false, false, false);
2851 // Oops, wrong item...
2853 canned_msg(MSG_NOTHING_HAPPENS);
2857 static void _vulnerability_scroll()
2859 // First cast antimagic on yourself.
2862 mon_enchant lowered_mr(ENCH_LOWERED_MR, 1, &you, 40);
2864 // Go over all creatures in LOS.
2865 for (radius_iterator ri(you.pos(), LOS_RADIUS); ri; ++ri)
2867 if (monster* mon = monster_at(*ri))
2869 debuff_monster(mon);
2871 // If relevant, monsters have their MR halved.
2872 if (!mons_immune_magic(mon))
2873 mon->add_ench(lowered_mr);
2875 // Annoying but not enough to turn friendlies against you.
2876 if (!mon->wont_attack())
2877 behaviour_event(mon, ME_ANNOY, &you);
2881 you.set_duration(DUR_LOWERED_MR, 40, 0,
2882 "Magic dampens, then quickly surges around you.");
2885 bool _is_cancellable_scroll(scroll_type scroll)
2887 return (scroll == SCR_IDENTIFY
2888 || scroll == SCR_BLINKING
2889 || scroll == SCR_RECHARGING
2890 || scroll == SCR_ENCHANT_ARMOUR
2891 || scroll == SCR_AMNESIA
2892 || scroll == SCR_REMOVE_CURSE
2893 || scroll == SCR_CURSE_ARMOUR
2894 || scroll == SCR_CURSE_JEWELLERY
2895 || scroll == SCR_VORPALISE_WEAPON);
2898 void read_scroll(int slot)
2902 canned_msg(MSG_TOO_BERSERK);
2908 canned_msg(MSG_TOO_CONFUSED);
2912 if (you.duration[DUR_WATER_HOLD] && !you.res_water_drowning())
2914 mpr("You cannot read scrolls while unable to breathe!");
2918 if (inv_count() < 1)
2920 canned_msg(MSG_NOTHING_CARRIED);
2924 int item_slot = (slot != -1) ? slot
2925 : prompt_invent_item("Read which item?",
2928 true, true, true, 0, -1,
2931 if (prompt_failed(item_slot))
2934 item_def& scroll = you.inv[item_slot];
2936 if ((scroll.base_type != OBJ_BOOKS || scroll.sub_type == BOOK_MANUAL)
2937 && scroll.base_type != OBJ_SCROLLS)
2939 mpr("You can't read that!");
2940 crawl_state.zero_turns_taken();
2944 // Here we try to read a book {dlb}:
2945 if (scroll.base_type == OBJ_BOOKS)
2947 _handle_read_book(item_slot);
2951 if (you.form == TRAN_WISP)
2953 crawl_state.zero_turns_taken();
2954 return mpr("You have no means to unroll scrolls.");
2957 if (silenced(you.pos()))
2959 mpr("Magic scrolls do not work when you're silenced!");
2960 crawl_state.zero_turns_taken();
2964 // Prevent hot lava orcs reading scrolls
2965 if (you.species == SP_LAVA_ORC && temperature_effect(LORC_NO_SCROLLS))
2967 crawl_state.zero_turns_taken();
2968 return mpr("You'd burn any scroll you tried to read!");
2971 if (you.duration[DUR_SMOLDERING]
2973 && !(you.conservation() && !one_chance_in(10))
2974 && !(you.mutation[MUT_CONSERVE_SCROLLS] && !one_chance_in(10)))
2976 const string item_name = quant_name(you.inv[item_slot], 1, DESC_THE);
2977 mprf("%s burns to ash!",
2979 dec_inv_item_quantity(item_slot, 1);
2980 count_action(CACT_USE, OBJ_POTIONS);
2981 you.turn_is_over = true;
2985 const scroll_type which_scroll = static_cast<scroll_type>(scroll.sub_type);
2986 const bool alreadyknown = item_type_known(scroll);
2990 switch (which_scroll)
2993 case SCR_TELEPORTATION:
2994 if (you.no_tele(false, false, which_scroll == SCR_BLINKING))