3 * @brief プレイヤーのアイテムに関するコマンドの実装2 / Spell/Prayer commands
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
11 * 2014 Deskull rearranged comment for Doxygen.\n
15 * This file includes code for eating food, drinking potions,
16 * reading scrolls, aiming wands, using staffs, zapping rods,
17 * and activating artifacts.
19 * In all cases, if the player becomes "aware" of the item's use
20 * by testing it, mark it as "aware" and reward some experience
21 * based on the object's level, always rounding up. If the player
22 * remains "unaware", mark that object "kind" as "tried".
24 * This code now correctly handles the unstacking of wands, staffs,
25 * and rods. Note the overly paranoid warning about potential pack
26 * overflow, which allows the player to use and drop a stacked item.
28 * In all "unstacking" scenarios, the "used" object is "carried" as if
29 * the player had just picked it up. In particular, this means that if
30 * the use of an item induces pack overflow, that item will be dropped.
32 * For simplicity, these routines induce a full "pack reorganization"
33 * which not only combines similar items, but also reorganizes various
34 * items to obey the current "sorting" method. This may require about
35 * 400 item comparisons, but only occasionally.
37 * There may be a BIG problem with any "effect" that can cause "changes"
38 * to the inventory. For example, a "scroll of recharging" can cause
39 * a wand/staff to "disappear", moving the inventory up. Luckily, the
40 * scrolls all appear BEFORE the staffs/wands, so this is not a problem.
41 * But, for example, a "staff of recharging" could cause MAJOR problems.
42 * In such a case, it will be best to either (1) "postpone" the effect
43 * until the end of the function, or (2) "change" the effect, say, into
44 * giving a staff "negative" charges, or "turning a staff into a stick".
45 * It seems as though a "rod of recharging" might in fact cause problems.
46 * The basic problem is that the act of recharging (and destroying) an
47 * item causes the inducer of that action to "move", causing "o_ptr" to
48 * no longer point at the correct item, with horrifying results.
50 * Note that food/potions/scrolls no longer use bit-flags for effects,
51 * but instead use the "sval" (which is also used to sort the objects).
57 #include "cmd-activate.h"
59 #include "cmd-quaff.h"
61 #include "cmd-usestaff.h"
67 * @param sval オブジェクトのsval
69 * @param powerful 強力発動上の処理ならばTRUE
70 * @param magic 魔道具術上の処理ならばTRUE
71 * @return 発動により効果内容が確定したならばTRUEを返す
73 static int wand_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool powerful, bool magic)
76 int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
77 int rad = powerful ? 3 : 2;
79 /* XXX Hack -- Wand of wonder can do anything before it */
80 if (sval == SV_WAND_WONDER)
82 int vir = virtue_number(V_CHANCE);
83 sval = (OBJECT_SUBTYPE_VALUE)randint0(SV_WAND_WONDER);
87 if (p_ptr->virtues[vir - 1] > 0)
89 while (randint1(300) < p_ptr->virtues[vir - 1]) sval++;
90 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
94 while (randint1(300) < (0-p_ptr->virtues[vir - 1])) sval--;
95 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
98 if (sval < SV_WAND_TELEPORT_AWAY)
99 chg_virtue(V_CHANCE, 1);
102 /* Analyze the wand */
105 case SV_WAND_HEAL_MONSTER:
107 HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
108 if (heal_monster(dir, dam)) ident = TRUE;
112 case SV_WAND_HASTE_MONSTER:
114 if (speed_monster(dir, lev)) ident = TRUE;
118 case SV_WAND_CLONE_MONSTER:
120 if (clone_monster(dir)) ident = TRUE;
124 case SV_WAND_TELEPORT_AWAY:
126 int distance = MAX_SIGHT * (powerful ? 8 : 5);
127 if (teleport_monster(dir, distance)) ident = TRUE;
131 case SV_WAND_DISARMING:
133 if (disarm_trap(dir)) ident = TRUE;
134 if (powerful && disarm_traps_touch()) ident = TRUE;
138 case SV_WAND_TRAP_DOOR_DEST:
140 if (destroy_door(dir)) ident = TRUE;
141 if (powerful && destroy_doors_touch()) ident = TRUE;
145 case SV_WAND_STONE_TO_MUD:
147 HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
148 if (wall_to_mud(dir, dam)) ident = TRUE;
154 HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
155 msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
156 (void)lite_line(dir, dam);
161 case SV_WAND_SLEEP_MONSTER:
163 if (sleep_monster(dir, lev)) ident = TRUE;
167 case SV_WAND_SLOW_MONSTER:
169 if (slow_monster(dir, lev)) ident = TRUE;
173 case SV_WAND_CONFUSE_MONSTER:
175 if (confuse_monster(dir, lev)) ident = TRUE;
179 case SV_WAND_FEAR_MONSTER:
181 if (fear_monster(dir, lev)) ident = TRUE;
185 case SV_WAND_HYPODYNAMIA:
187 if (hypodynamic_bolt(dir, 80 + lev)) ident = TRUE;
191 case SV_WAND_POLYMORPH:
193 if (poly_monster(dir, lev)) ident = TRUE;
197 case SV_WAND_STINKING_CLOUD:
199 fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
204 case SV_WAND_MAGIC_MISSILE:
206 fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
211 case SV_WAND_ACID_BOLT:
213 fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
218 case SV_WAND_CHARM_MONSTER:
220 if (charm_monster(dir, MAX(20, lev)))
225 case SV_WAND_FIRE_BOLT:
227 fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
232 case SV_WAND_COLD_BOLT:
234 fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
239 case SV_WAND_ACID_BALL:
241 fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
246 case SV_WAND_ELEC_BALL:
248 fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
253 case SV_WAND_FIRE_BALL:
255 fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
260 case SV_WAND_COLD_BALL:
262 fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
269 msg_print(_("おっと、謎の魔法棒を始動させた。", "Oops. Wand of wonder activated."));
273 case SV_WAND_DRAGON_FIRE:
275 fire_breath(GF_FIRE, dir, (powerful ? 300 : 200), 3);
280 case SV_WAND_DRAGON_COLD:
282 fire_breath(GF_COLD, dir, (powerful ? 270 : 180), 3);
287 case SV_WAND_DRAGON_BREATH:
316 if (powerful) dam = (dam * 3) / 2;
318 fire_ball(typ, dir, dam, -3);
324 case SV_WAND_DISINTEGRATE:
326 fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
331 case SV_WAND_ROCKETS:
333 msg_print(_("ロケットを発射した!", "You launch a rocket!"));
334 fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
339 case SV_WAND_STRIKING:
341 fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
346 case SV_WAND_GENOCIDE:
348 fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
357 * @brief 魔法棒を使うコマンドのサブルーチン /
358 * Aim a wand (from the pack or floor).
359 * @param item 使うオブジェクトの所持品ID
363 * Use a single charge from a single item.
364 * Handle "unstacking" in a logical manner.
365 * For simplicity, you cannot use a stack of items from the
366 * ground. This would require too much nasty code.
367 * There are no wands which can "destroy" themselves, in the inventory
368 * or on the ground, so we can ignore this possibility. Note that this
369 * required giving "wand of wonder" the ability to ignore destruction
371 * All wands can be "cancelled" at the "Direction?" prompt for free.
372 * Note that the basic "bolt" wands do slightly less damage than the
373 * basic "bolt" rods, but the basic "ball" wands do the same damage
374 * as the basic "ball" rods.
377 static void do_cmd_aim_wand_aux(int item)
379 int lev, ident, chance, dir;
381 bool old_target_pet = target_pet;
383 /* Get the item (in the pack) */
386 o_ptr = &inventory[item];
389 /* Get the item (on the floor) */
392 o_ptr = &o_list[0 - item];
395 /* Mega-Hack -- refuse to aim a pile from the ground */
396 if ((item < 0) && (o_ptr->number > 1))
398 msg_print(_("まずは魔法棒を拾わなければ。", "You must first pick up the wands."));
403 /* Allow direction to be cancelled for free */
404 if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
405 || o_ptr->sval == SV_WAND_HASTE_MONSTER))
407 if (!get_aim_dir(&dir))
409 target_pet = old_target_pet;
412 target_pet = old_target_pet;
415 p_ptr->energy_use = 100;
418 lev = k_info[o_ptr->k_idx].level;
419 if (lev > 50) lev = 50 + (lev - 50)/2;
421 /* Base chance of success */
422 chance = p_ptr->skill_dev;
424 /* Confusion hurts skill */
425 if (p_ptr->confused) chance = chance / 2;
427 /* Hight level objects are harder */
428 chance = chance - lev;
430 /* Give everyone a (slight) chance */
431 if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
438 if (flush_failure) flush();
439 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this wand is freezing too."));
445 if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (p_ptr->pclass == CLASS_BERSERKER))
447 if (flush_failure) flush();
448 msg_print(_("魔法棒をうまく使えなかった。", "You failed to use the wand properly."));
453 /* The wand is already empty! */
454 if (o_ptr->pval <= 0)
456 if (flush_failure) flush();
457 msg_print(_("この魔法棒にはもう魔力が残っていない。", "The wand has no charges left."));
458 o_ptr->ident |= (IDENT_EMPTY);
460 /* Combine / Reorder the pack (later) */
461 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
462 p_ptr->window |= (PW_INVEN);
470 ident = wand_effect(o_ptr->sval, dir, FALSE, FALSE);
472 /* Combine / Reorder the pack (later) */
473 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
475 if (!(object_is_aware(o_ptr)))
477 chg_virtue(V_PATIENCE, -1);
478 chg_virtue(V_CHANCE, 1);
479 chg_virtue(V_KNOWLEDGE, -1);
482 /* Mark it as tried */
485 /* Apply identification */
486 if (ident && !object_is_aware(o_ptr))
489 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
493 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
496 /* Use a single charge */
499 /* Describe the charges in the pack */
502 inven_item_charges(item);
505 /* Describe the charges on the floor */
508 floor_item_charges(0 - item);
513 * @brief 魔法棒を使うコマンドのメインルーチン /
516 void do_cmd_aim_wand(void)
521 /* Restrict choices to wands */
522 item_tester_tval = TV_WAND;
524 if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
526 set_action(ACTION_NONE);
530 q = _("どの魔法棒で狙いますか? ", "Aim which wand? ");
531 s = _("使える魔法棒がない。", "You have no wand to aim.");
533 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
536 do_cmd_aim_wand_aux(item);
541 * @param sval オブジェクトのsval
542 * @param dir 発動目標の方向ID
543 * @param use_charge チャージを消費したかどうかを返す参照ポインタ
544 * @param powerful 強力発動上の処理ならばTRUE
545 * @param magic 魔道具術上の処理ならばTRUE
546 * @return 発動により効果内容が確定したならばTRUEを返す
548 static int rod_effect(OBJECT_SUBTYPE_VALUE sval, int dir, bool *use_charge, bool powerful, bool magic)
551 int lev = powerful ? p_ptr->lev * 2 : p_ptr->lev;
552 int detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
553 int rad = powerful ? 3 : 2;
558 /* Analyze the rod */
561 case SV_ROD_DETECT_TRAP:
563 if (detect_traps(detect_rad, (bool)(dir ? FALSE : TRUE))) ident = TRUE;
567 case SV_ROD_DETECT_DOOR:
569 if (detect_doors(detect_rad)) ident = TRUE;
570 if (detect_stairs(detect_rad)) ident = TRUE;
574 case SV_ROD_IDENTIFY:
577 if (!identify_fully(FALSE)) *use_charge = FALSE;
579 if (!ident_spell(FALSE)) *use_charge = FALSE;
587 if (!word_of_recall()) *use_charge = FALSE;
592 case SV_ROD_ILLUMINATION:
594 if (lite_area(damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
600 map_area(powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
605 case SV_ROD_DETECTION:
607 detect_all(detect_rad);
621 if (set_blind(0)) ident = TRUE;
622 if (set_poisoned(0)) ident = TRUE;
623 if (set_confused(0)) ident = TRUE;
624 if (set_stun(0)) ident = TRUE;
625 if (set_cut(0)) ident = TRUE;
626 if (set_image(0)) ident = TRUE;
627 if (set_shero(0,TRUE)) ident = TRUE;
633 if (hp_player(powerful ? 750 : 500)) ident = TRUE;
634 if (set_stun(0)) ident = TRUE;
635 if (set_cut(0)) ident = TRUE;
636 if (set_shero(0,TRUE)) ident = TRUE;
640 case SV_ROD_RESTORATION:
642 if (restore_level()) ident = TRUE;
643 if (do_res_stat(A_STR)) ident = TRUE;
644 if (do_res_stat(A_INT)) ident = TRUE;
645 if (do_res_stat(A_WIS)) ident = TRUE;
646 if (do_res_stat(A_DEX)) ident = TRUE;
647 if (do_res_stat(A_CON)) ident = TRUE;
648 if (do_res_stat(A_CHR)) ident = TRUE;
654 if (set_fast(randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
658 case SV_ROD_PESTICIDE:
660 if (dispel_monsters(powerful ? 8 : 4)) ident = TRUE;
664 case SV_ROD_TELEPORT_AWAY:
666 int distance = MAX_SIGHT * (powerful ? 8 : 5);
667 if (teleport_monster(dir, distance)) ident = TRUE;
671 case SV_ROD_DISARMING:
673 if (disarm_trap(dir)) ident = TRUE;
674 if (powerful && disarm_traps_touch()) ident = TRUE;
680 HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
681 msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
682 (void)lite_line(dir, dam);
687 case SV_ROD_SLEEP_MONSTER:
689 if (sleep_monster(dir, lev)) ident = TRUE;
693 case SV_ROD_SLOW_MONSTER:
695 if (slow_monster(dir, lev)) ident = TRUE;
699 case SV_ROD_HYPODYNAMIA:
701 if (hypodynamic_bolt(dir, 70 + 3 * lev / 2)) ident = TRUE;
705 case SV_ROD_POLYMORPH:
707 if (poly_monster(dir, lev)) ident = TRUE;
711 case SV_ROD_ACID_BOLT:
713 fire_bolt_or_beam(10, GF_ACID, dir, damroll(6 + lev / 7, 8));
718 case SV_ROD_ELEC_BOLT:
720 fire_bolt_or_beam(10, GF_ELEC, dir, damroll(4 + lev / 9, 8));
725 case SV_ROD_FIRE_BOLT:
727 fire_bolt_or_beam(10, GF_FIRE, dir, damroll(7 + lev / 6, 8));
732 case SV_ROD_COLD_BOLT:
734 fire_bolt_or_beam(10, GF_COLD, dir, damroll(5 + lev / 8, 8));
739 case SV_ROD_ACID_BALL:
741 fire_ball(GF_ACID, dir, 60 + lev, rad);
746 case SV_ROD_ELEC_BALL:
748 fire_ball(GF_ELEC, dir, 40 + lev, rad);
753 case SV_ROD_FIRE_BALL:
755 fire_ball(GF_FIRE, dir, 70 + lev, rad);
760 case SV_ROD_COLD_BALL:
762 fire_ball(GF_COLD, dir, 50 + lev, rad);
774 case SV_ROD_STONE_TO_MUD:
776 HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
777 if (wall_to_mud(dir, dam)) ident = TRUE;
781 case SV_ROD_AGGRAVATE:
783 aggravate_monsters(0);
792 * @brief 魔法棒を使うコマンドのサブルーチン /
793 * Activate (zap) a Rod
794 * @param item 使うオブジェクトの所持品ID
798 * Unstack fully charged rods as needed.
799 * Hack -- rods of perception/genocide can be "cancelled"
800 * All rods can be cancelled at the "Direction?" prompt
801 * pvals are defined for each rod in k_info. -LM-
804 static void do_cmd_zap_rod_aux(int item)
806 int ident, chance, lev, fail;
811 /* Hack -- let perception get aborted */
812 bool use_charge = TRUE;
816 /* Get the item (in the pack) */
819 o_ptr = &inventory[item];
822 /* Get the item (on the floor) */
825 o_ptr = &o_list[0 - item];
829 /* Mega-Hack -- refuse to zap a pile from the ground */
830 if ((item < 0) && (o_ptr->number > 1))
832 msg_print(_("まずはロッドを拾わなければ。", "You must first pick up the rods."));
837 /* Get a direction (unless KNOWN not to need it) */
838 if (((o_ptr->sval >= SV_ROD_MIN_DIRECTION) && (o_ptr->sval != SV_ROD_HAVOC) && (o_ptr->sval != SV_ROD_AGGRAVATE) && (o_ptr->sval != SV_ROD_PESTICIDE)) ||
839 !object_is_aware(o_ptr))
841 /* Get a direction, allow cancel */
842 if (!get_aim_dir(&dir)) return;
847 p_ptr->energy_use = 100;
849 /* Extract the item level */
850 lev = k_info[o_ptr->k_idx].level;
852 /* Base chance of success */
853 chance = p_ptr->skill_dev;
855 /* Confusion hurts skill */
856 if (p_ptr->confused) chance = chance / 2;
859 if (chance > fail) fail -= (chance - fail)*2;
860 else chance -= (fail - chance)*2;
861 if (fail < USE_DEVICE) fail = USE_DEVICE;
862 if (chance < USE_DEVICE) chance = USE_DEVICE;
866 if (flush_failure) flush();
867 msg_print(_("止まった時の中ではうまく働かないようだ。", "Nothing happen. Maybe this rod is freezing too."));
872 if (p_ptr->pclass == CLASS_BERSERKER) success = FALSE;
873 else if (chance > fail)
875 if (randint0(chance*2) < fail) success = FALSE;
880 if (randint0(fail*2) < chance) success = TRUE;
881 else success = FALSE;
887 if (flush_failure) flush();
888 msg_print(_("うまくロッドを使えなかった。", "You failed to use the rod properly."));
893 k_ptr = &k_info[o_ptr->k_idx];
895 /* A single rod is still charging */
896 if ((o_ptr->number == 1) && (o_ptr->timeout))
898 if (flush_failure) flush();
899 msg_print(_("このロッドはまだ魔力を充填している最中だ。", "The rod is still charging."));
902 /* A stack of rods lacks enough energy. */
903 else if ((o_ptr->number > 1) && (o_ptr->timeout > k_ptr->pval * (o_ptr->number - 1)))
905 if (flush_failure) flush();
906 msg_print(_("そのロッドはまだ充填中です。", "The rods are all still charging."));
913 ident = rod_effect(o_ptr->sval, dir, &use_charge, FALSE, FALSE);
915 /* Increase the timeout by the rod kind's pval. -LM- */
916 if (use_charge) o_ptr->timeout += k_ptr->pval;
918 /* Combine / Reorder the pack (later) */
919 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
921 if (!(object_is_aware(o_ptr)))
923 chg_virtue(V_PATIENCE, -1);
924 chg_virtue(V_CHANCE, 1);
925 chg_virtue(V_KNOWLEDGE, -1);
928 /* Tried the object */
931 /* Successfully determined the object function */
932 if (ident && !object_is_aware(o_ptr))
935 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);
939 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
943 * @brief ロッドを使うコマンドのメインルーチン /
946 void do_cmd_zap_rod(void)
951 if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
953 set_action(ACTION_NONE);
956 /* Restrict choices to rods */
957 item_tester_tval = TV_ROD;
960 q = _("どのロッドを振りますか? ", "Zap which rod? ");
961 s = _("使えるロッドがない。", "You have no rod to zap.");
963 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
966 do_cmd_zap_rod_aux(item);
970 * @brief 『一つの指輪』の効果処理 /
971 * Hack -- activate the ring of power
975 void ring_of_power(int dir)
977 /* Pick a random effect */
978 switch (randint1(10))
984 msg_print(_("あなたは悪性のオーラに包み込まれた。", "You are surrounded by a malignant aura."));
987 /* Decrease all stats (permanently) */
988 (void)dec_stat(A_STR, 50, TRUE);
989 (void)dec_stat(A_INT, 50, TRUE);
990 (void)dec_stat(A_WIS, 50, TRUE);
991 (void)dec_stat(A_DEX, 50, TRUE);
992 (void)dec_stat(A_CON, 50, TRUE);
993 (void)dec_stat(A_CHR, 50, TRUE);
995 /* Lose some experience (permanently) */
996 p_ptr->exp -= (p_ptr->exp / 4);
997 p_ptr->max_exp -= (p_ptr->exp / 4);
1006 msg_print(_("あなたは強力なオーラに包み込まれた。", "You are surrounded by a powerful aura."));
1008 /* Dispel monsters */
1009 dispel_monsters(1000);
1019 fire_ball(GF_MANA, dir, 600, 3);
1030 fire_bolt(GF_MANA, dir, 500);
1038 * @brief オブジェクトをプレイヤーが簡易使用コマンドで利用できるかを判定する /
1039 * Hook to determine if an object is useable
1040 * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
1041 * @return 利用可能ならばTRUEを返す
1043 static bool item_tester_hook_use(object_type *o_ptr)
1045 u32b flgs[TR_FLAG_SIZE];
1048 if (o_ptr->tval == p_ptr->tval_ammo)
1051 /* Useable object */
1052 switch (o_ptr->tval)
1070 if (!object_is_known(o_ptr)) return (FALSE);
1072 /* HACK - only items from the equipment can be activated */
1073 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1075 if (&inventory[i] == o_ptr)
1077 /* Extract the flags */
1078 object_flags(o_ptr, flgs);
1080 /* Check activation flag */
1081 if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
1093 * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
1097 * XXX - Add actions for other item types
1099 void do_cmd_use(void)
1105 if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
1107 set_action(ACTION_NONE);
1110 item_tester_no_ryoute = TRUE;
1111 /* Prepare the hook */
1112 item_tester_hook = item_tester_hook_use;
1115 q = _("どれを使いますか?", "Use which item? ");
1116 s = _("使えるものがありません。", "You have nothing to use.");
1118 if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
1120 /* Get the item (in the pack) */
1123 o_ptr = &inventory[item];
1125 /* Get the item (on the floor) */
1128 o_ptr = &o_list[0 - item];
1131 switch (o_ptr->tval)
1143 do_cmd_eat_food_aux(item);
1150 do_cmd_aim_wand_aux(item);
1157 do_cmd_use_staff_aux(item);
1164 do_cmd_zap_rod_aux(item);
1168 /* Quaff a potion */
1171 do_cmd_quaff_potion_aux(item);
1178 /* Check some conditions */
1181 msg_print(_("目が見えない。", "You can't see anything."));
1186 msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
1189 if (p_ptr->confused)
1191 msg_print(_("混乱していて読めない!", "You are too confused!"));
1195 do_cmd_read_scroll_aux(item, TRUE);
1204 do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
1208 /* Activate an artifact */
1211 do_cmd_activate_aux(item);
1218 * @brief 魔道具術師の取り込んだ魔力一覧から選択/閲覧する /
1219 * @param only_browse 閲覧するだけならばTRUE
1220 * @return 選択した魔力のID、キャンセルならば-1を返す
1222 static OBJECT_SUBTYPE_VALUE select_magic_eater(bool only_browse)
1224 OBJECT_SUBTYPE_VALUE ext = 0;
1226 bool flag, request_list;
1227 OBJECT_TYPE_VALUE tval = 0;
1229 OBJECT_SUBTYPE_VALUE i = 0;
1232 int menu_line = (use_menu ? 1 : 0);
1236 if (repeat_pull(&sn))
1238 /* Verify the spell */
1239 if (sn >= EATER_EXT*2 && !(p_ptr->magic_num1[sn] > k_info[lookup_kind(TV_ROD, sn-EATER_EXT*2)].pval * (p_ptr->magic_num2[sn] - 1) * EATER_ROD_CHARGE))
1241 else if (sn < EATER_EXT*2 && !(p_ptr->magic_num1[sn] < EATER_CHARGE))
1245 #endif /* ALLOW_REPEAT */
1247 for (i = 0; i < 108; i++)
1249 if (p_ptr->magic_num2[i]) break;
1253 msg_print(_("魔法を覚えていない!", "You don't have any magic!"));
1264 prt(format(" %s 杖", (menu_line == 1) ? "》" : " "), 2, 14);
1265 prt(format(" %s 魔法棒", (menu_line == 2) ? "》" : " "), 3, 14);
1266 prt(format(" %s ロッド", (menu_line == 3) ? "》" : " "), 4, 14);
1268 prt(format(" %s staff", (menu_line == 1) ? "> " : " "), 2, 14);
1269 prt(format(" %s wand", (menu_line == 2) ? "> " : " "), 3, 14);
1270 prt(format(" %s rod", (menu_line == 3) ? "> " : " "), 4, 14);
1273 if (only_browse) prt(_("どの種類の魔法を見ますか?", "Which type of magic do you browse?"), 0, 0);
1274 else prt(_("どの種類の魔法を使いますか?", "Which type of magic do you use?"), 0, 0);
1297 ext = (menu_line-1)*EATER_EXT;
1298 if (menu_line == 1) tval = TV_STAFF;
1299 else if (menu_line == 2) tval = TV_WAND;
1303 if (menu_line > 3) menu_line -= 3;
1311 if (!get_com(_("[A] 杖, [B] 魔法棒, [C] ロッド:", "[A] staff, [B] wand, [C] rod:"), &choice, TRUE))
1315 if (choice == 'A' || choice == 'a')
1321 if (choice == 'B' || choice == 'b')
1327 if (choice == 'C' || choice == 'c')
1335 for (i = ext; i < ext + EATER_EXT; i++)
1337 if (p_ptr->magic_num2[i])
1339 if (use_menu) menu_line = i-ext+1;
1343 if (i == ext+EATER_EXT)
1345 msg_print(_("その種類の魔法は覚えていない!", "You don't have that type of magic!"));
1349 /* Nothing chosen yet */
1352 /* Build a prompt */
1353 if (only_browse) strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を見ますか?",
1354 "(*=List, ESC=exit) Browse which power? "));
1355 else strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を使いますか?",
1356 "(*=List, ESC=exit) Use which power? "));
1358 /* Save the screen */
1361 request_list = always_show_list;
1363 /* Get a spell from the user */
1367 if (request_list || use_menu)
1370 OBJECT_SUBTYPE_VALUE ctr;
1380 for (y = 1; y < 20; y++)
1385 /* Print header(s) */
1387 prt(format(" %s 失率 %s 失率", (tval == TV_ROD ? " 状態 " : "使用回数"), (tval == TV_ROD ? " 状態 " : "使用回数")), y++, x);
1389 prt(format(" %s Fail %s Fail", (tval == TV_ROD ? " Stat " : " Charges"), (tval == TV_ROD ? " Stat " : " Charges")), y++, x);
1393 for (ctr = 0; ctr < EATER_EXT; ctr++)
1395 if (!p_ptr->magic_num2[ctr+ext]) continue;
1397 k_idx = lookup_kind(tval, ctr);
1401 if (ctr == (menu_line-1))
1402 strcpy(dummy, _("》", "> "));
1406 /* letter/number for power selection */
1413 letter = '0' + ctr - 26;
1414 sprintf(dummy, "%c)",letter);
1416 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
1417 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
1418 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
1419 chance = level * 4 / 5 + 20;
1420 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
1422 if (p_ptr->lev > level)
1424 chance -= 3 * (p_ptr->lev - level);
1426 chance = mod_spell_chance_1(chance);
1427 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
1428 /* Stunning makes spells harder */
1429 if (p_ptr->stun > 50) chance += 25;
1430 else if (p_ptr->stun) chance += 15;
1432 if (chance > 95) chance = 95;
1434 chance = mod_spell_chance_2(chance);
1442 strcat(dummy, format(
1443 _(" %-22.22s 充填:%2d/%2d%3d%%", " %-22.22s (%2d/%2d) %3d%%"),
1444 k_name + k_info[k_idx].name,
1445 p_ptr->magic_num1[ctr+ext] ?
1446 (p_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0,
1447 p_ptr->magic_num2[ctr+ext], chance));
1448 if (p_ptr->magic_num1[ctr+ext] > k_info[k_idx].pval * (p_ptr->magic_num2[ctr+ext]-1) * EATER_ROD_CHARGE) col = TERM_RED;
1452 strcat(dummy, format(" %-22.22s %2d/%2d %3d%%", k_name + k_info[k_idx].name, (s16b)(p_ptr->magic_num1[ctr+ext]/EATER_CHARGE), p_ptr->magic_num2[ctr+ext], chance));
1453 if (p_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
1458 c_prt(col, dummy, y1, x1);
1462 if (!get_com(out_val, &choice, FALSE)) break;
1464 if (use_menu && choice != ' ')
1480 menu_line += EATER_EXT - 1;
1481 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
1482 } while(!p_ptr->magic_num2[menu_line+ext-1]);
1493 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
1494 } while(!p_ptr->magic_num2[menu_line+ext-1]);
1505 bool reverse = FALSE;
1506 if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
1507 if (menu_line > EATER_EXT/2)
1509 menu_line -= EATER_EXT/2;
1512 else menu_line+=EATER_EXT/2;
1513 while(!p_ptr->magic_num2[menu_line+ext-1])
1518 if (menu_line < 2) reverse = FALSE;
1523 if (menu_line > EATER_EXT-1) reverse = TRUE;
1540 /* Request redraw */
1541 if (use_menu && ask) continue;
1543 /* Request redraw */
1544 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
1550 request_list = FALSE;
1552 /* Restore the screen */
1557 request_list = TRUE;
1565 if (isalpha(choice))
1568 ask = (isupper(choice));
1571 if (ask) choice = (char)tolower(choice);
1573 /* Extract request */
1574 i = (islower(choice) ? A2I(choice) : -1);
1578 ask = FALSE; /* Can't uppercase digits */
1580 i = choice - '0' + 26;
1584 /* Totally Illegal */
1585 if ((i < 0) || (i > EATER_EXT) || !p_ptr->magic_num2[i+ext])
1599 (void) strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s?"), k_name + k_info[lookup_kind(tval ,i)].name);
1601 /* Belay that order */
1602 if (!get_check(tmp_val)) continue;
1606 if (p_ptr->magic_num1[ext+i] > k_info[lookup_kind(tval, i)].pval * (p_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
1608 msg_print(_("その魔法はまだ充填している最中だ。", "The magic are still charging."));
1610 if (use_menu) ask = TRUE;
1616 if (p_ptr->magic_num1[ext+i] < EATER_CHARGE)
1618 msg_print(_("その魔法は使用回数が切れている。", "The magic has no charges left."));
1620 if (use_menu) ask = TRUE;
1632 /* Clear lines, position cursor (really should use strlen here) */
1633 Term_erase(7, 23, 255);
1634 Term_erase(7, 22, 255);
1635 Term_erase(7, 21, 255);
1636 Term_erase(7, 20, 255);
1638 roff_to_buf(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
1639 for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
1641 prt(&temp[j], line, 10);
1652 /* Restore the screen */
1655 if (!flag) return -1;
1659 #endif /* ALLOW_REPEAT */
1665 * @brief 取り込んだ魔力を利用するコマンドのメインルーチン /
1666 * Use eaten rod, wand or staff
1667 * @param only_browse 閲覧するだけならばTRUE
1668 * @param powerful 強力発動中の処理ならばTRUE
1669 * @return 実際にコマンドを実行したならばTRUEを返す。
1671 bool do_cmd_magic_eater(bool only_browse, bool powerful)
1673 OBJECT_SUBTYPE_VALUE item;
1677 OBJECT_TYPE_VALUE tval;
1678 OBJECT_SUBTYPE_VALUE sval;
1679 bool use_charge = TRUE;
1681 /* Not when confused */
1682 if (!only_browse && p_ptr->confused)
1684 msg_print(_("混乱していて唱えられない!", "You are too confused!"));
1688 item = select_magic_eater(only_browse);
1691 p_ptr->energy_use = 0;
1694 if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
1695 else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
1696 else {tval = TV_STAFF; sval = item;}
1697 k_idx = lookup_kind(tval, sval);
1699 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
1700 chance = level * 4 / 5 + 20;
1701 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
1703 if (p_ptr->lev > level)
1705 chance -= 3 * (p_ptr->lev - level);
1707 chance = mod_spell_chance_1(chance);
1708 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
1709 /* Stunning makes spells harder */
1710 if (p_ptr->stun > 50) chance += 25;
1711 else if (p_ptr->stun) chance += 15;
1713 if (chance > 95) chance = 95;
1715 chance = mod_spell_chance_2(chance);
1717 if (randint0(100) < chance)
1719 if (flush_failure) flush();
1721 msg_print(_("呪文をうまく唱えられなかった!", "You failed to get the magic off!"));
1723 if (randint1(100) >= chance)
1724 chg_virtue(V_CHANCE,-1);
1725 p_ptr->energy_use = 100;
1735 if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
1736 if (!get_aim_dir(&dir)) return FALSE;
1737 rod_effect(sval, dir, &use_charge, powerful, TRUE);
1738 if (!use_charge) return FALSE;
1740 else if (tval == TV_WAND)
1742 if (!get_aim_dir(&dir)) return FALSE;
1743 wand_effect(sval, dir, powerful, TRUE);
1747 staff_effect(sval, &use_charge, powerful, TRUE, TRUE);
1748 if (!use_charge) return FALSE;
1750 if (randint1(100) < chance)
1751 chg_virtue(V_CHANCE,1);
1753 p_ptr->energy_use = 100;
1754 if (tval == TV_ROD) p_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
1755 else p_ptr->magic_num1[item] -= EATER_CHARGE;