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).
56 #include "cmd-usestaff.h"
57 #include "cmd-zaprod.h"
58 #include "cmd-zapwand.h"
60 #include "player-status.h"
64 * @brief 魔道具術師の取り込んだ魔力一覧から選択/閲覧する /
65 * @param only_browse 閲覧するだけならばTRUE
66 * @return 選択した魔力のID、キャンセルならば-1を返す
68 static OBJECT_SUBTYPE_VALUE select_magic_eater(bool only_browse)
70 OBJECT_SUBTYPE_VALUE ext = 0;
72 bool flag, request_list;
73 OBJECT_TYPE_VALUE tval = 0;
75 OBJECT_SUBTYPE_VALUE i = 0;
78 int menu_line = (use_menu ? 1 : 0);
83 /* Verify the spell */
84 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))
86 else if (sn < EATER_EXT*2 && !(p_ptr->magic_num1[sn] < EATER_CHARGE))
90 for (i = 0; i < 108; i++)
92 if (p_ptr->magic_num2[i]) break;
96 msg_print(_("魔法を覚えていない!", "You don't have any magic!"));
107 prt(format(" %s 杖", (menu_line == 1) ? "》" : " "), 2, 14);
108 prt(format(" %s 魔法棒", (menu_line == 2) ? "》" : " "), 3, 14);
109 prt(format(" %s ロッド", (menu_line == 3) ? "》" : " "), 4, 14);
111 prt(format(" %s staff", (menu_line == 1) ? "> " : " "), 2, 14);
112 prt(format(" %s wand", (menu_line == 2) ? "> " : " "), 3, 14);
113 prt(format(" %s rod", (menu_line == 3) ? "> " : " "), 4, 14);
116 if (only_browse) prt(_("どの種類の魔法を見ますか?", "Which type of magic do you browse?"), 0, 0);
117 else prt(_("どの種類の魔法を使いますか?", "Which type of magic do you use?"), 0, 0);
140 ext = (menu_line-1)*EATER_EXT;
141 if (menu_line == 1) tval = TV_STAFF;
142 else if (menu_line == 2) tval = TV_WAND;
146 if (menu_line > 3) menu_line -= 3;
154 if (!get_com(_("[A] 杖, [B] 魔法棒, [C] ロッド:", "[A] staff, [B] wand, [C] rod:"), &choice, TRUE))
158 if (choice == 'A' || choice == 'a')
164 if (choice == 'B' || choice == 'b')
170 if (choice == 'C' || choice == 'c')
178 for (i = ext; i < ext + EATER_EXT; i++)
180 if (p_ptr->magic_num2[i])
182 if (use_menu) menu_line = i-ext+1;
186 if (i == ext+EATER_EXT)
188 msg_print(_("その種類の魔法は覚えていない!", "You don't have that type of magic!"));
192 /* Nothing chosen yet */
196 if (only_browse) strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を見ますか?",
197 "(*=List, ESC=exit) Browse which power? "));
198 else strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を使いますか?",
199 "(*=List, ESC=exit) Use which power? "));
202 request_list = always_show_list;
207 if (request_list || use_menu)
210 OBJECT_SUBTYPE_VALUE ctr;
212 KIND_OBJECT_IDX k_idx;
220 for (y = 1; y < 20; y++)
225 /* Print header(s) */
227 prt(format(" %s 失率 %s 失率", (tval == TV_ROD ? " 状態 " : "使用回数"), (tval == TV_ROD ? " 状態 " : "使用回数")), y++, x);
229 prt(format(" %s Fail %s Fail", (tval == TV_ROD ? " Stat " : " Charges"), (tval == TV_ROD ? " Stat " : " Charges")), y++, x);
233 for (ctr = 0; ctr < EATER_EXT; ctr++)
235 if (!p_ptr->magic_num2[ctr+ext]) continue;
237 k_idx = lookup_kind(tval, ctr);
241 if (ctr == (menu_line-1))
242 strcpy(dummy, _("》", "> "));
246 /* letter/number for power selection */
253 letter = '0' + ctr - 26;
254 sprintf(dummy, "%c)",letter);
256 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
257 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
258 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
259 chance = level * 4 / 5 + 20;
260 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
262 if (p_ptr->lev > level)
264 chance -= 3 * (p_ptr->lev - level);
266 chance = mod_spell_chance_1(chance);
267 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
268 /* Stunning makes spells harder */
269 if (p_ptr->stun > 50) chance += 25;
270 else if (p_ptr->stun) chance += 15;
272 if (chance > 95) chance = 95;
274 chance = mod_spell_chance_2(chance);
282 strcat(dummy, format(
283 _(" %-22.22s 充填:%2d/%2d%3d%%", " %-22.22s (%2d/%2d) %3d%%"),
284 k_name + k_info[k_idx].name,
285 p_ptr->magic_num1[ctr+ext] ?
286 (p_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0,
287 p_ptr->magic_num2[ctr+ext], chance));
288 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;
292 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));
293 if (p_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
298 c_prt(col, dummy, y1, x1);
302 if (!get_com(out_val, &choice, FALSE)) break;
304 if (use_menu && choice != ' ')
320 menu_line += EATER_EXT - 1;
321 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
322 } while(!p_ptr->magic_num2[menu_line+ext-1]);
333 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
334 } while(!p_ptr->magic_num2[menu_line+ext-1]);
345 bool reverse = FALSE;
346 if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
347 if (menu_line > EATER_EXT/2)
349 menu_line -= EATER_EXT/2;
352 else menu_line+=EATER_EXT/2;
353 while(!p_ptr->magic_num2[menu_line+ext-1])
358 if (menu_line < 2) reverse = FALSE;
363 if (menu_line > EATER_EXT-1) reverse = TRUE;
381 if (use_menu && ask) continue;
384 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
390 request_list = FALSE;
406 ask = (isupper(choice));
409 if (ask) choice = (char)tolower(choice);
411 /* Extract request */
412 i = (islower(choice) ? A2I(choice) : -1);
416 ask = FALSE; /* Can't uppercase digits */
418 i = choice - '0' + 26;
422 /* Totally Illegal */
423 if ((i < 0) || (i > EATER_EXT) || !p_ptr->magic_num2[i+ext])
437 (void) strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s?"), k_name + k_info[lookup_kind(tval ,i)].name);
439 /* Belay that order */
440 if (!get_check(tmp_val)) continue;
444 if (p_ptr->magic_num1[ext+i] > k_info[lookup_kind(tval, i)].pval * (p_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
446 msg_print(_("その魔法はまだ充填している最中だ。", "The magic are still charging."));
448 if (use_menu) ask = TRUE;
454 if (p_ptr->magic_num1[ext+i] < EATER_CHARGE)
456 msg_print(_("その魔法は使用回数が切れている。", "The magic has no charges left."));
458 if (use_menu) ask = TRUE;
470 /* Clear lines, position cursor (really should use strlen here) */
471 Term_erase(7, 23, 255);
472 Term_erase(7, 22, 255);
473 Term_erase(7, 21, 255);
474 Term_erase(7, 20, 255);
476 roff_to_buf(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
477 for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
479 prt(&temp[j], line, 10);
491 if (!flag) return -1;
499 * @brief 取り込んだ魔力を利用するコマンドのメインルーチン /
500 * Use eaten rod, wand or staff
501 * @param only_browse 閲覧するだけならばTRUE
502 * @param powerful 強力発動中の処理ならばTRUE
503 * @return 実際にコマンドを実行したならばTRUEを返す。
505 bool do_cmd_magic_eater(bool only_browse, bool powerful)
507 OBJECT_SUBTYPE_VALUE item;
510 KIND_OBJECT_IDX k_idx;
511 OBJECT_TYPE_VALUE tval;
512 OBJECT_SUBTYPE_VALUE sval;
513 bool use_charge = TRUE;
515 if (cmd_limit_confused(p_ptr)) return FALSE;
517 item = select_magic_eater(only_browse);
523 if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
524 else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
525 else {tval = TV_STAFF; sval = item;}
526 k_idx = lookup_kind(tval, sval);
528 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
529 chance = level * 4 / 5 + 20;
530 chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
532 if (p_ptr->lev > level)
534 chance -= 3 * (p_ptr->lev - level);
536 chance = mod_spell_chance_1(chance);
537 chance = MAX(chance, adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]]);
538 /* Stunning makes spells harder */
539 if (p_ptr->stun > 50) chance += 25;
540 else if (p_ptr->stun) chance += 15;
542 if (chance > 95) chance = 95;
544 chance = mod_spell_chance_2(chance);
546 if (randint0(100) < chance)
548 if (flush_failure) flush();
550 msg_print(_("呪文をうまく唱えられなかった!", "You failed to get the magic off!"));
552 if (randint1(100) >= chance)
553 chg_virtue(V_CHANCE,-1);
554 take_turn(p_ptr, 100);
564 if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
565 if (!get_aim_dir(&dir)) return FALSE;
566 rod_effect(sval, dir, &use_charge, powerful, TRUE);
567 if (!use_charge) return FALSE;
569 else if (tval == TV_WAND)
571 if (!get_aim_dir(&dir)) return FALSE;
572 wand_effect(sval, dir, powerful, TRUE);
576 staff_effect(sval, &use_charge, powerful, TRUE, TRUE);
577 if (!use_charge) return FALSE;
579 if (randint1(100) < chance)
580 chg_virtue(V_CHANCE,1);
582 take_turn(p_ptr, 100);
583 if (tval == TV_ROD) p_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
584 else p_ptr->magic_num1[item] -= EATER_CHARGE;