OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / spells3.c
1 /*!
2  * @file spells3.c
3  * @brief 魔法効果の実装/ Spell code (part 3)
4  * @date 2014/07/26
5  * @author
6  * <pre>
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  * </pre>
12  */
13
14 #include "angband.h"
15 #include "object-hook.h"
16
17 /*! テレポート先探索の試行数 / Maximum number of tries for teleporting */
18 #define MAX_TRIES 100
19
20
21 /*!
22  * @brief モンスターのテレポートアウェイ処理 /
23  * Teleport a monster, normally up to "dis" grids away.
24  * @param m_idx モンスターID
25  * @param dis テレポート距離
26  * @param mode オプション
27  * @return テレポートが実際に行われたらtrue
28  * @details
29  * Attempt to move the monster at least "dis/2" grids away.
30  * But allow variation to prevent infinite loops.
31  */
32 bool teleport_away(MONSTER_IDX m_idx, POSITION dis, BIT_FLAGS mode)
33 {
34         POSITION oy, ox, d, i, min;
35         int tries = 0;
36         POSITION ny = 0, nx = 0;
37
38         bool look = TRUE;
39
40         monster_type *m_ptr = &m_list[m_idx];
41
42         /* Paranoia */
43         if (!m_ptr->r_idx) return (FALSE);
44
45         /* Save the old location */
46         oy = m_ptr->fy;
47         ox = m_ptr->fx;
48
49         /* Minimum distance */
50         min = dis / 2;
51
52         if ((mode & TELEPORT_DEC_VALOUR) &&
53             (((p_ptr->chp * 10) / p_ptr->mhp) > 5) &&
54                 (4+randint1(5) < ((p_ptr->chp * 10) / p_ptr->mhp)))
55         {
56                 chg_virtue(V_VALOUR, -1);
57         }
58
59         /* Look until done */
60         while (look)
61         {
62                 tries++;
63
64                 /* Verify max distance */
65                 if (dis > 200) dis = 200;
66
67                 /* Try several locations */
68                 for (i = 0; i < 500; i++)
69                 {
70                         /* Pick a (possibly illegal) location */
71                         while (1)
72                         {
73                                 ny = rand_spread(oy, dis);
74                                 nx = rand_spread(ox, dis);
75                                 d = distance(oy, ox, ny, nx);
76                                 if ((d >= min) && (d <= dis)) break;
77                         }
78
79                         /* Ignore illegal locations */
80                         if (!in_bounds(ny, nx)) continue;
81
82                         if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
83
84                         /* No teleporting into vaults and such */
85                         if (!(p_ptr->inside_quest || p_ptr->inside_arena))
86                                 if (cave[ny][nx].info & CAVE_ICKY) continue;
87
88                         /* This grid looks good */
89                         look = FALSE;
90
91                         /* Stop looking */
92                         break;
93                 }
94
95                 /* Increase the maximum distance */
96                 dis = dis * 2;
97
98                 /* Decrease the minimum distance */
99                 min = min / 2;
100
101                 /* Stop after MAX_TRIES tries */
102                 if (tries > MAX_TRIES) return (FALSE);
103         }
104
105         sound(SOUND_TPOTHER);
106
107         /* Update the old location */
108         cave[oy][ox].m_idx = 0;
109
110         /* Update the new location */
111         cave[ny][nx].m_idx = m_idx;
112
113         /* Move the monster */
114         m_ptr->fy = ny;
115         m_ptr->fx = nx;
116
117         /* Forget the counter target */
118         reset_target(m_ptr);
119
120         /* Update the monster (new location) */
121         update_mon(m_idx, TRUE);
122
123         /* Redraw the old grid */
124         lite_spot(oy, ox);
125
126         /* Redraw the new grid */
127         lite_spot(ny, nx);
128
129         if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
130                 p_ptr->update |= (PU_MON_LITE);
131
132         return (TRUE);
133 }
134
135
136 /*!
137  * @brief モンスターを指定された座標付近にテレポートする /
138  * Teleport monster next to a grid near the given location
139  * @param m_idx モンスターID
140  * @param ty 目安Y座標
141  * @param tx 目安X座標
142  * @param power テレポート成功確率
143  * @param mode オプション
144  * @return なし
145  */
146 void teleport_monster_to(MONSTER_IDX m_idx, POSITION ty, POSITION tx, int power, BIT_FLAGS mode)
147 {
148         POSITION ny, nx, oy, ox;
149         int d, i, min;
150         int attempts = 500;
151         POSITION dis = 2;
152         bool look = TRUE;
153         monster_type *m_ptr = &m_list[m_idx];
154
155         /* Paranoia */
156         if(!m_ptr->r_idx) return;
157
158         /* "Skill" test */
159         if(randint1(100) > power) return;
160
161         ny = m_ptr->fy;
162         nx = m_ptr->fx;
163
164         /* Save the old location */
165         oy = m_ptr->fy;
166         ox = m_ptr->fx;
167
168         /* Minimum distance */
169         min = dis / 2;
170
171         /* Look until done */
172         while (look && --attempts)
173         {
174                 /* Verify max distance */
175                 if (dis > 200) dis = 200;
176
177                 /* Try several locations */
178                 for (i = 0; i < 500; i++)
179                 {
180                         /* Pick a (possibly illegal) location */
181                         while (1)
182                         {
183                                 ny = rand_spread(ty, dis);
184                                 nx = rand_spread(tx, dis);
185                                 d = distance(ty, tx, ny, nx);
186                                 if ((d >= min) && (d <= dis)) break;
187                         }
188
189                         /* Ignore illegal locations */
190                         if (!in_bounds(ny, nx)) continue;
191
192                         if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
193
194                         /* No teleporting into vaults and such */
195                         /* if (cave[ny][nx].info & (CAVE_ICKY)) continue; */
196
197                         /* This grid looks good */
198                         look = FALSE;
199
200                         /* Stop looking */
201                         break;
202                 }
203
204                 /* Increase the maximum distance */
205                 dis = dis * 2;
206
207                 /* Decrease the minimum distance */
208                 min = min / 2;
209         }
210
211         if (attempts < 1) return;
212
213         sound(SOUND_TPOTHER);
214
215         /* Update the old location */
216         cave[oy][ox].m_idx = 0;
217
218         /* Update the new location */
219         cave[ny][nx].m_idx = m_idx;
220
221         /* Move the monster */
222         m_ptr->fy = ny;
223         m_ptr->fx = nx;
224
225         /* Update the monster (new location) */
226         update_mon(m_idx, TRUE);
227
228         /* Redraw the old grid */
229         lite_spot(oy, ox);
230
231         /* Redraw the new grid */
232         lite_spot(ny, nx);
233
234         if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
235                 p_ptr->update |= (PU_MON_LITE);
236 }
237
238 /*!
239  * @brief プレイヤーのテレポート先選定と移動処理 /
240  * Teleport the player to a location up to "dis" grids away.
241  * @param dis 基本移動距離
242  * @param mode オプション
243  * @return 実際にテレポート処理が行われたらtrue
244  * @details
245  * <pre>
246  * If no such spaces are readily available, the distance may increase.
247  * Try very hard to move the player at least a quarter that distance.
248  *
249  * There was a nasty tendency for a long time; which was causing the
250  * player to "bounce" between two or three different spots because
251  * these are the only spots that are "far enough" way to satisfy the
252  * algorithm.
253  *
254  * But this tendency is now removed; in the new algorithm, a list of
255  * candidates is selected first, which includes at least 50% of all
256  * floor grids within the distance, and any single grid in this list
257  * of candidates has equal possibility to be choosen as a destination.
258  * </pre>
259  */
260
261 bool teleport_player_aux(POSITION dis, BIT_FLAGS mode)
262 {
263         int candidates_at[MAX_TELEPORT_DISTANCE + 1];
264         int total_candidates, cur_candidates;
265         POSITION y = 0, x = 0;
266         int min, pick, i;
267
268         int left = MAX(1, p_ptr->x - dis);
269         int right = MIN(cur_wid - 2, p_ptr->x + dis);
270         int top = MAX(1, p_ptr->y - dis);
271         int bottom = MIN(cur_hgt - 2, p_ptr->y + dis);
272
273         if (p_ptr->wild_mode) return FALSE;
274
275         if (p_ptr->anti_tele && !(mode & TELEPORT_NONMAGICAL))
276         {
277                 msg_print(_("不思議な力がテレポートを防いだ!", "A mysterious force prevents you from teleporting!"));
278                 return FALSE;
279         }
280
281         /* Initialize counters */
282         total_candidates = 0;
283         for (i = 0; i <= MAX_TELEPORT_DISTANCE; i++)
284                 candidates_at[i] = 0;
285
286         /* Limit the distance */
287         if (dis > MAX_TELEPORT_DISTANCE) dis = MAX_TELEPORT_DISTANCE;
288
289         /* Search valid locations */
290         for (y = top; y <= bottom; y++)
291         {
292                 for (x = left; x <= right; x++)
293                 {
294                         int d;
295
296                         /* Skip illegal locations */
297                         if (!cave_player_teleportable_bold(y, x, mode)) continue;
298
299                         /* Calculate distance */
300                         d = distance(p_ptr->y, p_ptr->x, y, x);
301
302                         /* Skip too far locations */
303                         if (d > dis) continue;
304
305                         /* Count the total number of candidates */
306                         total_candidates++;
307
308                         /* Count the number of candidates in this circumference */
309                         candidates_at[d]++;
310                 }
311         }
312
313         /* No valid location! */
314         if (0 == total_candidates) return FALSE;
315
316         /* Fix the minimum distance */
317         for (cur_candidates = 0, min = dis; min >= 0; min--)
318         {
319                 cur_candidates += candidates_at[min];
320
321                 /* 50% of all candidates will have an equal chance to be choosen. */
322                 if (cur_candidates && (cur_candidates >= total_candidates / 2)) break;
323         }
324
325         /* Pick up a single location randomly */
326         pick = randint1(cur_candidates);
327
328         /* Search again the choosen location */
329         for (y = top; y <= bottom; y++)
330         {
331                 for (x = left; x <= right; x++)
332                 {
333                         int d;
334
335                         /* Skip illegal locations */
336                         if (!cave_player_teleportable_bold(y, x, mode)) continue;
337
338                         /* Calculate distance */
339                         d = distance(p_ptr->y, p_ptr->x, y, x);
340
341                         /* Skip too far locations */
342                         if (d > dis) continue;
343
344                         /* Skip too close locations */
345                         if (d < min) continue;
346
347                         /* This grid was picked up? */
348                         pick--;
349                         if (!pick) break;
350                 }
351
352                 /* Exit the loop */
353                 if (!pick) break;
354         }
355
356         if (player_bold(y, x)) return FALSE;
357
358         sound(SOUND_TELEPORT);
359
360 #ifdef JP
361         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
362                 msg_format("『こっちだぁ、%s』", p_ptr->name);
363 #endif
364
365         /* Move the player */
366         (void)move_player_effect(y, x, MPE_FORGET_FLOW | MPE_HANDLE_STUFF | MPE_DONT_PICKUP);
367
368         return TRUE;
369 }
370
371 /*!
372  * @brief プレイヤーのテレポート処理メインルーチン
373  * @param dis 基本移動距離
374  * @param mode オプション
375  * @return なし
376  */
377 void teleport_player(POSITION dis, BIT_FLAGS mode)
378 {
379         POSITION yy, xx;
380
381         /* Save the old location */
382         POSITION oy = p_ptr->y;
383         POSITION ox = p_ptr->x;
384
385         if (!teleport_player_aux(dis, mode)) return;
386
387         /* Monsters with teleport ability may follow the player */
388         for (xx = -1; xx < 2; xx++)
389         {
390                 for (yy = -1; yy < 2; yy++)
391                 {
392                         MONSTER_IDX tmp_m_idx = cave[oy+yy][ox+xx].m_idx;
393
394                         /* A monster except your mount may follow */
395                         if (tmp_m_idx && (p_ptr->riding != tmp_m_idx))
396                         {
397                                 monster_type *m_ptr = &m_list[tmp_m_idx];
398                                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
399
400                                 /*
401                                  * The latter limitation is to avoid
402                                  * totally unkillable suckers...
403                                  */
404                                 if ((r_ptr->a_ability_flags2 & RF6_TPORT) &&
405                                     !(r_ptr->flagsr & RFR_RES_TELE))
406                                 {
407                                         if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, p_ptr->y, p_ptr->x, r_ptr->level, 0L);
408                                 }
409                         }
410                 }
411         }
412 }
413
414
415 /*!
416  * @brief プレイヤーのテレポートアウェイ処理 /
417  * @param m_idx アウェイを試みたプレイヤーID
418  * @param dis テレポート距離
419  * @return なし
420  */
421 void teleport_player_away(MONSTER_IDX m_idx, POSITION dis)
422 {
423         POSITION yy, xx;
424
425         /* Save the old location */
426         POSITION oy = p_ptr->y;
427         POSITION ox = p_ptr->x;
428
429         if (!teleport_player_aux(dis, TELEPORT_PASSIVE)) return;
430
431         /* Monsters with teleport ability may follow the player */
432         for (xx = -1; xx < 2; xx++)
433         {
434                 for (yy = -1; yy < 2; yy++)
435                 {
436                         IDX tmp_m_idx = cave[oy+yy][ox+xx].m_idx;
437
438                         /* A monster except your mount or caster may follow */
439                         if (tmp_m_idx && (p_ptr->riding != tmp_m_idx) && (m_idx != tmp_m_idx))
440                         {
441                                 monster_type *m_ptr = &m_list[tmp_m_idx];
442                                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
443
444                                 /*
445                                  * The latter limitation is to avoid
446                                  * totally unkillable suckers...
447                                  */
448                                 if ((r_ptr->a_ability_flags2 & RF6_TPORT) &&
449                                     !(r_ptr->flagsr & RFR_RES_TELE))
450                                 {
451                                         if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, p_ptr->y, p_ptr->x, r_ptr->level, 0L);
452                                 }
453                         }
454                 }
455         }
456 }
457
458
459 /*!
460  * @brief プレイヤーを指定位置近辺にテレポートさせる
461  * Teleport player to a grid near the given location
462  * @param ny 目標Y座標
463  * @param nx 目標X座標
464  * @param mode オプションフラグ
465  * @return なし
466  * @details
467  * <pre>
468  * This function is slightly obsessive about correctness.
469  * This function allows teleporting into vaults (!)
470  * </pre>
471  */
472 void teleport_player_to(POSITION ny, POSITION nx, BIT_FLAGS mode)
473 {
474         POSITION y, x;
475         POSITION dis = 0, ctr = 0;
476
477         if (p_ptr->anti_tele && !(mode & TELEPORT_NONMAGICAL))
478         {
479                 msg_print(_("不思議な力がテレポートを防いだ!", "A mysterious force prevents you from teleporting!"));
480                 return;
481         }
482
483         /* Find a usable location */
484         while (1)
485         {
486                 /* Pick a nearby legal location */
487                 while (1)
488                 {
489                         y = (POSITION)rand_spread(ny, dis);
490                         x = (POSITION)rand_spread(nx, dis);
491                         if (in_bounds(y, x)) break;
492                 }
493
494                 /* Accept any grid when wizard mode */
495                 if (p_ptr->wizard && !(mode & TELEPORT_PASSIVE) && (!cave[y][x].m_idx || (cave[y][x].m_idx == p_ptr->riding))) break;
496
497                 /* Accept teleportable floor grids */
498                 if (cave_player_teleportable_bold(y, x, mode)) break;
499
500                 /* Occasionally advance the distance */
501                 if (++ctr > (4 * dis * dis + 4 * dis + 1))
502                 {
503                         ctr = 0;
504                         dis++;
505                 }
506         }
507
508         sound(SOUND_TELEPORT);
509
510         /* Move the player */
511         (void)move_player_effect(y, x, MPE_FORGET_FLOW | MPE_HANDLE_STUFF | MPE_DONT_PICKUP);
512 }
513
514
515 void teleport_away_followable(MONSTER_IDX m_idx)
516 {
517         monster_type *m_ptr = &m_list[m_idx];
518         int          oldfy = m_ptr->fy;
519         int          oldfx = m_ptr->fx;
520         bool         old_ml = m_ptr->ml;
521         int          old_cdis = m_ptr->cdis;
522
523         teleport_away(m_idx, MAX_SIGHT * 2 + 5, 0L);
524
525         if (old_ml && (old_cdis <= MAX_SIGHT) && !world_monster && !p_ptr->inside_battle && los(p_ptr->y, p_ptr->x, oldfy, oldfx))
526         {
527                 bool follow = FALSE;
528
529                 if ((p_ptr->muta1 & MUT1_VTELEPORT) || (p_ptr->pclass == CLASS_IMITATOR)) follow = TRUE;
530                 else
531                 {
532                         BIT_FLAGS flgs[TR_FLAG_SIZE];
533                         object_type *o_ptr;
534                         int i;
535
536                         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
537                         {
538                                 o_ptr = &inventory[i];
539                                 if (o_ptr->k_idx && !object_is_cursed(o_ptr))
540                                 {
541                                         object_flags(o_ptr, flgs);
542                                         if (have_flag(flgs, TR_TELEPORT))
543                                         {
544                                                 follow = TRUE;
545                                                 break;
546                                         }
547                                 }
548                         }
549                 }
550
551                 if (follow)
552                 {
553                         if (get_check_strict(_("ついていきますか?", "Do you follow it? "), CHECK_OKAY_CANCEL))
554                         {
555                                 if (one_in_(3))
556                                 {
557                                         teleport_player(200, TELEPORT_PASSIVE);
558                                         msg_print(_("失敗!", "Failed!"));
559                                 }
560                                 else teleport_player_to(m_ptr->fy, m_ptr->fx, 0L);
561                                 p_ptr->energy_need += ENERGY_NEED();
562                         }
563                 }
564         }
565 }
566
567
568 /*!
569  * @brief プレイヤー及びモンスターをレベルテレポートさせる /
570  * Teleport the player one level up or down (random when legal)
571  * @param m_idx テレポートの対象となるモンスターID(0ならばプレイヤー) / If m_idx <= 0, target is player.
572  * @return なし
573  */
574 void teleport_level(MONSTER_IDX m_idx)
575 {
576         bool         go_up;
577         char         m_name[160];
578         bool         see_m = TRUE;
579
580         if (m_idx <= 0) /* To player */
581         {
582                 strcpy(m_name, _("あなた", "you"));
583         }
584         else /* To monster */
585         {
586                 monster_type *m_ptr = &m_list[m_idx];
587
588                 /* Get the monster name (or "it") */
589                 monster_desc(m_name, m_ptr, 0);
590
591                 see_m = is_seen(m_ptr);
592         }
593
594         /* No effect in some case */
595         if (TELE_LEVEL_IS_INEFF(m_idx))
596         {
597                 if (see_m) msg_print(_("効果がなかった。", "There is no effect."));
598                 return;
599         }
600
601         if ((m_idx <= 0) && p_ptr->anti_tele) /* To player */
602         {
603                 msg_print(_("不思議な力がテレポートを防いだ!", "A mysterious force prevents you from teleporting!"));
604                 return;
605         }
606
607         /* Choose up or down */
608         if (randint0(100) < 50) go_up = TRUE;
609         else go_up = FALSE;
610
611         if ((m_idx <= 0) && p_ptr->wizard)
612         {
613                 if (get_check("Force to go up? ")) go_up = TRUE;
614                 else if (get_check("Force to go down? ")) go_up = FALSE;
615         }
616
617         /* Down only */ 
618         if ((ironman_downward && (m_idx <= 0)) || (dun_level <= d_info[dungeon_type].mindepth))
619         {
620 #ifdef JP
621                 if (see_m) msg_format("%^sは床を突き破って沈んでいく。", m_name);
622 #else
623                 if (see_m) msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
624 #endif
625                 if (m_idx <= 0) /* To player */
626                 {
627                         if (!dun_level)
628                         {
629                                 dungeon_type = ironman_downward ? DUNGEON_ANGBAND : p_ptr->recall_dungeon;
630                                 p_ptr->oldpy = p_ptr->y;
631                                 p_ptr->oldpx = p_ptr->x;
632                         }
633
634                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
635
636                         if (autosave_l) do_cmd_save_game(TRUE);
637
638                         if (!dun_level)
639                         {
640                                 dun_level = d_info[dungeon_type].mindepth;
641                                 prepare_change_floor_mode(CFM_RAND_PLACE);
642                         }
643                         else
644                         {
645                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
646                         }
647
648                         /* Leaving */
649                         p_ptr->leaving = TRUE;
650                 }
651         }
652
653         /* Up only */
654         else if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth))
655         {
656 #ifdef JP
657                 if (see_m) msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
658 #else
659                 if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
660 #endif
661
662
663                 if (m_idx <= 0) /* To player */
664                 {
665                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
666
667                         if (autosave_l) do_cmd_save_game(TRUE);
668
669                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
670
671                         leave_quest_check();
672
673                         /* Leaving */
674                         p_ptr->inside_quest = 0;
675                         p_ptr->leaving = TRUE;
676                 }
677         }
678         else if (go_up)
679         {
680 #ifdef JP
681                 if (see_m) msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
682 #else
683                 if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
684 #endif
685
686
687                 if (m_idx <= 0) /* To player */
688                 {
689                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
690
691                         if (autosave_l) do_cmd_save_game(TRUE);
692
693                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
694
695                         /* Leaving */
696                         p_ptr->leaving = TRUE;
697                 }
698         }
699         else
700         {
701 #ifdef JP
702                 if (see_m) msg_format("%^sは床を突き破って沈んでいく。", m_name);
703 #else
704                 if (see_m) msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
705 #endif
706
707                 if (m_idx <= 0) /* To player */
708                 {
709                         /* Never reach this code on the surface */
710                         /* if (!dun_level) dungeon_type = p_ptr->recall_dungeon; */
711
712                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
713
714                         if (autosave_l) do_cmd_save_game(TRUE);
715
716                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
717
718                         /* Leaving */
719                         p_ptr->leaving = TRUE;
720                 }
721         }
722
723         /* Monster level teleportation is simple deleting now */
724         if (m_idx > 0)
725         {
726                 monster_type *m_ptr = &m_list[m_idx];
727
728                 /* Check for quest completion */
729                 check_quest_completion(m_ptr);
730
731                 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
732                 {
733                         char m2_name[80];
734
735                         monster_desc(m2_name, m_ptr, MD_INDEF_VISIBLE);
736                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_TELE_LEVEL, m2_name);
737                 }
738
739                 delete_monster_idx(m_idx);
740         }
741
742         sound(SOUND_TPLEVEL);
743 }
744
745
746 /*!
747  * @brief これまでに入ったダンジョンの一覧を表示し、選択させる。
748  * @param note ダンジョンに施す処理記述
749  * @param y コンソールY座標
750  * @param x コンソールX座標
751  * @return 選択されたダンジョンID
752  */
753 DUNGEON_IDX choose_dungeon(cptr note, POSITION y, POSITION x)
754 {
755         DUNGEON_IDX select_dungeon;
756         DUNGEON_IDX i;
757         int num = 0;
758         DUNGEON_IDX *dun;
759
760         /* Hack -- No need to choose dungeon in some case */
761         if (lite_town || vanilla_town || ironman_downward)
762         {
763                 if (max_dlv[DUNGEON_ANGBAND]) return DUNGEON_ANGBAND;
764                 else
765                 {
766                         msg_format(_("まだ%sに入ったことはない。", "You haven't entered %s yet."), d_name + d_info[DUNGEON_ANGBAND].name);
767                         msg_print(NULL);
768                         return 0;
769                 }
770         }
771
772         /* Allocate the "dun" array */
773         C_MAKE(dun, max_d_idx, s16b);
774
775         screen_save();
776         for(i = 1; i < max_d_idx; i++)
777         {
778                 char buf[80];
779                 bool seiha = FALSE;
780
781                 if (!d_info[i].maxdepth) continue;
782                 if (!max_dlv[i]) continue;
783                 if (d_info[i].final_guardian)
784                 {
785                         if (!r_info[d_info[i].final_guardian].max_num) seiha = TRUE;
786                 }
787                 else if (max_dlv[i] == d_info[i].maxdepth) seiha = TRUE;
788
789                 sprintf(buf,_("      %c) %c%-12s : 最大 %d 階", "      %c) %c%-16s : Max level %d"), 
790                                         'a'+num, seiha ? '!' : ' ', d_name + d_info[i].name, (int)max_dlv[i]);
791                 prt(buf, y + num, x);
792                 dun[num++] = i;
793         }
794
795         if (!num)
796         {
797                 prt(_("      選べるダンジョンがない。", "      No dungeon is available."), y, x);
798         }
799
800         prt(format(_("どのダンジョン%sしますか:", "Which dungeon do you %s?: "), note), 0, 0);
801         while(1)
802         {
803                 i = inkey();
804                 if ((i == ESCAPE) || !num)
805                 {
806                         /* Free the "dun" array */
807                         C_KILL(dun, max_d_idx, s16b);
808
809                         screen_load();
810                         return 0;
811                 }
812                 if (i >= 'a' && i <('a'+num))
813                 {
814                         select_dungeon = dun[i-'a'];
815                         break;
816                 }
817                 else bell();
818         }
819         screen_load();
820
821         /* Free the "dun" array */
822         C_KILL(dun, max_d_idx, s16b);
823
824         return select_dungeon;
825 }
826
827
828 /*!
829  * @brief プレイヤーの帰還発動及び中止処理 /
830  * Recall the player to town or dungeon
831  * @param turns 発動までのターン数
832  * @return 常にTRUEを返す
833  */
834 bool recall_player(TIME_EFFECT turns)
835 {
836         /*
837          * TODO: Recall the player to the last
838          * visited town when in the wilderness
839          */
840
841         /* Ironman option */
842         if (p_ptr->inside_arena || ironman_downward)
843         {
844                 msg_print(_("何も起こらなかった。", "Nothing happens."));
845                 return TRUE;
846         }
847
848         if (dun_level && (max_dlv[dungeon_type] > dun_level) && !p_ptr->inside_quest && !p_ptr->word_recall)
849         {
850                 if (get_check(_("ここは最深到達階より浅い階です。この階に戻って来ますか? ", "Reset recall depth? ")))
851                 {
852                         max_dlv[dungeon_type] = dun_level;
853                         if (record_maxdepth)
854                                 do_cmd_write_nikki(NIKKI_TRUMP, dungeon_type, _("帰還のときに", "when recall from dungeon"));
855                 }
856
857         }
858         if (!p_ptr->word_recall)
859         {
860                 if (!dun_level)
861                 {
862                         DUNGEON_IDX select_dungeon;
863                         select_dungeon = choose_dungeon(_("に帰還", "recall"), 2, 14);
864                         if (!select_dungeon) return FALSE;
865                         p_ptr->recall_dungeon = select_dungeon;
866                 }
867                 p_ptr->word_recall = turns;
868                 msg_print(_("回りの大気が張りつめてきた...", "The air about you becomes charged..."));
869                 p_ptr->redraw |= (PR_STATUS);
870         }
871         else
872         {
873                 p_ptr->word_recall = 0;
874                 msg_print(_("張りつめた大気が流れ去った...", "A tension leaves the air around you..."));
875                 p_ptr->redraw |= (PR_STATUS);
876         }
877         return TRUE;
878 }
879
880 /*!
881  * @brief 帰還用メインルーチン
882  * @return 常にTRUEを返す
883  */
884 bool word_of_recall(void)
885 {
886         return(recall_player(randint0(21) + 15));
887 }
888
889 /*!
890  * @brief フロア・リセット処理
891  * @return リセット処理が実際に行われたらTRUEを返す
892  */
893 bool reset_recall(void)
894 {
895         int select_dungeon, dummy = 0;
896         char ppp[80];
897         char tmp_val[160];
898
899         select_dungeon = choose_dungeon(_("をセット", "reset"), 2, 14);
900
901         /* Ironman option */
902         if (ironman_downward)
903         {
904                 msg_print(_("何も起こらなかった。", "Nothing happens."));
905                 return TRUE;
906         }
907
908         if (!select_dungeon) return FALSE;
909         /* Prompt */
910         sprintf(ppp, _("何階にセットしますか (%d-%d):", "Reset to which level (%d-%d): "),
911                 (int)d_info[select_dungeon].mindepth, (int)max_dlv[select_dungeon]);
912
913         /* Default */
914         sprintf(tmp_val, "%d", (int)MAX(dun_level, 1));
915
916         /* Ask for a level */
917         if (get_string(ppp, tmp_val, 10))
918         {
919                 /* Extract request */
920                 dummy = atoi(tmp_val);
921
922                 /* Paranoia */
923                 if (dummy < 1) dummy = 1;
924
925                 /* Paranoia */
926                 if (dummy > max_dlv[select_dungeon]) dummy = max_dlv[select_dungeon];
927                 if (dummy < d_info[select_dungeon].mindepth) dummy = d_info[select_dungeon].mindepth;
928
929                 max_dlv[select_dungeon] = dummy;
930
931                 if (record_maxdepth)
932                         do_cmd_write_nikki(NIKKI_TRUMP, select_dungeon, _("フロア・リセットで", "using a scroll of reset recall"));
933                                         /* Accept request */
934 #ifdef JP
935 msg_format("%sの帰還レベルを %d 階にセット。", d_name+d_info[select_dungeon].name, dummy, dummy * 50);
936 #else
937                 msg_format("Recall depth set to level %d (%d').", dummy, dummy * 50);
938 #endif
939
940         }
941         else
942         {
943                 return FALSE;
944         }
945         return TRUE;
946 }
947
948
949 /*!
950  * @brief プレイヤーの装備劣化処理 /
951  * Apply disenchantment to the player's stuff
952  * @param mode 最下位ビットが1ならば劣化処理が若干低減される
953  * @return 劣化処理に関するメッセージが発せられた場合はTRUEを返す /
954  * Return "TRUE" if the player notices anything
955  */
956 bool apply_disenchant(BIT_FLAGS mode)
957 {
958         int             t = 0;
959         object_type     *o_ptr;
960         char            o_name[MAX_NLEN];
961         int to_h, to_d, to_a, pval;
962
963         /* Pick a random slot */
964         switch (randint1(8))
965         {
966                 case 1: t = INVEN_RARM; break;
967                 case 2: t = INVEN_LARM; break;
968                 case 3: t = INVEN_BOW; break;
969                 case 4: t = INVEN_BODY; break;
970                 case 5: t = INVEN_OUTER; break;
971                 case 6: t = INVEN_HEAD; break;
972                 case 7: t = INVEN_HANDS; break;
973                 case 8: t = INVEN_FEET; break;
974         }
975
976         o_ptr = &inventory[t];
977
978         /* No item, nothing happens */
979         if (!o_ptr->k_idx) return (FALSE);
980
981         /* Disenchant equipments only -- No disenchant on monster ball */
982         if (!object_is_weapon_armour_ammo(o_ptr))
983                 return FALSE;
984
985         /* Nothing to disenchant */
986         if ((o_ptr->to_h <= 0) && (o_ptr->to_d <= 0) && (o_ptr->to_a <= 0) && (o_ptr->pval <= 1))
987         {
988                 /* Nothing to notice */
989                 return (FALSE);
990         }
991
992
993         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
994
995
996         /* Artifacts have 71% chance to resist */
997         if (object_is_artifact(o_ptr) && (randint0(100) < 71))
998         {
999 #ifdef JP
1000 msg_format("%s(%c)は劣化を跳ね返した!",o_name, index_to_label(t) );
1001 #else
1002                 msg_format("Your %s (%c) resist%s disenchantment!",
1003                            o_name, index_to_label(t),
1004                            ((o_ptr->number != 1) ? "" : "s"));
1005 #endif
1006
1007
1008                 return (TRUE);
1009         }
1010
1011
1012         /* Memorize old value */
1013         to_h = o_ptr->to_h;
1014         to_d = o_ptr->to_d;
1015         to_a = o_ptr->to_a;
1016         pval = o_ptr->pval;
1017
1018         /* Disenchant tohit */
1019         if (o_ptr->to_h > 0) o_ptr->to_h--;
1020         if ((o_ptr->to_h > 5) && (randint0(100) < 20)) o_ptr->to_h--;
1021
1022         /* Disenchant todam */
1023         if (o_ptr->to_d > 0) o_ptr->to_d--;
1024         if ((o_ptr->to_d > 5) && (randint0(100) < 20)) o_ptr->to_d--;
1025
1026         /* Disenchant toac */
1027         if (o_ptr->to_a > 0) o_ptr->to_a--;
1028         if ((o_ptr->to_a > 5) && (randint0(100) < 20)) o_ptr->to_a--;
1029
1030         /* Disenchant pval (occasionally) */
1031         /* Unless called from wild_magic() */
1032         if ((o_ptr->pval > 1) && one_in_(13) && !(mode & 0x01)) o_ptr->pval--;
1033
1034         if ((to_h != o_ptr->to_h) || (to_d != o_ptr->to_d) ||
1035             (to_a != o_ptr->to_a) || (pval != o_ptr->pval))
1036         {
1037 #ifdef JP
1038                 msg_format("%s(%c)は劣化してしまった!",
1039                            o_name, index_to_label(t) );
1040 #else
1041                 msg_format("Your %s (%c) %s disenchanted!",
1042                            o_name, index_to_label(t),
1043                            ((o_ptr->number != 1) ? "were" : "was"));
1044 #endif
1045
1046                 chg_virtue(V_HARMONY, 1);
1047                 chg_virtue(V_ENCHANT, -2);
1048
1049                 /* Recalculate bonuses */
1050                 p_ptr->update |= (PU_BONUS);
1051
1052                 p_ptr->window |= (PW_EQUIP | PW_PLAYER);
1053
1054                 calc_android_exp();
1055         }
1056
1057         return (TRUE);
1058 }
1059
1060 /*!
1061  * @brief プレイヤーの突然変異処理
1062  * @return なし
1063  */
1064 void mutate_player(void)
1065 {
1066         BASE_STATUS max1, cur1, max2, cur2;
1067         int ii, jj, i;
1068
1069         /* Pick a pair of stats */
1070         ii = randint0(6);
1071         for (jj = ii; jj == ii; jj = randint0(6)) /* loop */;
1072
1073         max1 = p_ptr->stat_max[ii];
1074         cur1 = p_ptr->stat_cur[ii];
1075         max2 = p_ptr->stat_max[jj];
1076         cur2 = p_ptr->stat_cur[jj];
1077
1078         p_ptr->stat_max[ii] = max2;
1079         p_ptr->stat_cur[ii] = cur2;
1080         p_ptr->stat_max[jj] = max1;
1081         p_ptr->stat_cur[jj] = cur1;
1082
1083         for (i=0;i<6;i++)
1084         {
1085                 if(p_ptr->stat_max[i] > p_ptr->stat_max_max[i]) p_ptr->stat_max[i] = p_ptr->stat_max_max[i];
1086                 if(p_ptr->stat_cur[i] > p_ptr->stat_max_max[i]) p_ptr->stat_cur[i] = p_ptr->stat_max_max[i];
1087         }
1088
1089         p_ptr->update |= (PU_BONUS);
1090 }
1091
1092
1093 /*!
1094  * @brief プレイヤーの因果混乱処理 / Apply Nexus
1095  * @param m_ptr 因果混乱をプレイヤーに与えたモンスターの情報参照ポインタ
1096  * @return なし
1097  */
1098 void apply_nexus(monster_type *m_ptr)
1099 {
1100         switch (randint1(7))
1101         {
1102                 case 1: case 2: case 3:
1103                 {
1104                         teleport_player(200, TELEPORT_PASSIVE);
1105                         break;
1106                 }
1107
1108                 case 4: case 5:
1109                 {
1110                         teleport_player_to(m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
1111                         break;
1112                 }
1113
1114                 case 6:
1115                 {
1116                         if (randint0(100) < p_ptr->skill_sav)
1117                         {
1118                                 msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
1119                                 break;
1120                         }
1121
1122                         /* Teleport Level */
1123                         teleport_level(0);
1124                         break;
1125                 }
1126
1127                 case 7:
1128                 {
1129                         if (randint0(100) < p_ptr->skill_sav)
1130                         {
1131                                 msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
1132                                 break;
1133                         }
1134
1135                         msg_print(_("体がねじれ始めた...", "Your body starts to scramble..."));
1136                         mutate_player();
1137                         break;
1138                 }
1139         }
1140 }
1141
1142
1143 /*!
1144  * @brief 寿命つき光源の燃素追加処理 /
1145  * Charge a lite (torch or latern)
1146  * @return なし
1147  */
1148 void phlogiston(void)
1149 {
1150         GAME_TURN max_flog = 0;
1151         object_type * o_ptr = &inventory[INVEN_LITE];
1152
1153         /* It's a lamp */
1154         if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_LANTERN))
1155         {
1156                 max_flog = FUEL_LAMP;
1157         }
1158
1159         /* It's a torch */
1160         else if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
1161         {
1162                 max_flog = FUEL_TORCH;
1163         }
1164
1165         /* No torch to refill */
1166         else
1167         {
1168                 msg_print(_("燃素を消費するアイテムを装備していません。", "You are not wielding anything which uses phlogiston."));
1169                 return;
1170         }
1171
1172         if (o_ptr->xtra4 >= max_flog)
1173         {
1174                 msg_print(_("このアイテムにはこれ以上燃素を補充できません。", "No more phlogiston can be put in this item."));
1175                 return;
1176         }
1177
1178         /* Refuel */
1179         o_ptr->xtra4 += (XTRA16)(max_flog / 2);
1180
1181         msg_print(_("照明用アイテムに燃素を補充した。", "You add phlogiston to your light item."));
1182
1183         if (o_ptr->xtra4 >= max_flog)
1184         {
1185                 o_ptr->xtra4 = (XTRA16)max_flog;
1186                 msg_print(_("照明用アイテムは満タンになった。", "Your light item is full."));
1187         }
1188
1189         /* Recalculate torch */
1190         p_ptr->update |= (PU_TORCH);
1191 }
1192
1193
1194 /*!
1195  * @brief 武器へのエゴ付加処理 /
1196  * Brand the current weapon
1197  * @param brand_type エゴ化ID(e_info.txtとは連動していない)
1198  * @return なし
1199  */
1200 void brand_weapon(int brand_type)
1201 {
1202         OBJECT_IDX item;
1203         object_type *o_ptr;
1204         cptr        q, s;
1205
1206
1207         /* Assume enchant weapon */
1208         item_tester_hook = object_allow_enchant_melee_weapon;
1209         item_tester_no_ryoute = TRUE;
1210
1211         q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
1212         s = _("強化できる武器がない。", "You have nothing to enchant.");
1213
1214         if (!get_item(&item, q, s, (USE_EQUIP))) return;
1215
1216         /* Get the item (in the pack) */
1217         if (item >= 0)
1218         {
1219                 o_ptr = &inventory[item];
1220         }
1221
1222         /* Get the item (on the floor) */
1223         else
1224         {
1225                 o_ptr = &o_list[0 - item];
1226         }
1227
1228
1229         /* you can never modify artifacts / ego-items */
1230         /* you can never modify cursed items */
1231         /* TY: You _can_ modify broken items (if you're silly enough) */
1232         if (o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) &&
1233             !object_is_cursed(o_ptr) &&
1234             !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) &&
1235             !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE)) &&
1236             !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)))
1237         {
1238                 cptr act = NULL;
1239
1240                 /* Let's get the name before it is changed... */
1241                 char o_name[MAX_NLEN];
1242                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1243
1244                 switch (brand_type)
1245                 {
1246                 case 17:
1247                         if (o_ptr->tval == TV_SWORD)
1248                         {
1249                                 act = _("は鋭さを増した!", "becomes very sharp!");
1250
1251                                 o_ptr->name2 = EGO_SHARPNESS;
1252                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, dun_level) + 1;
1253
1254                                 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
1255                                         o_ptr->pval = 2;
1256                         }
1257                         else
1258                         {
1259                                 act = _("は破壊力を増した!", "seems very powerful.");
1260                                 o_ptr->name2 = EGO_EARTHQUAKES;
1261                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, dun_level);
1262                         }
1263                         break;
1264                 case 16:
1265                         act = _("は人間の血を求めている!", "seems to be looking for humans!");
1266                         o_ptr->name2 = EGO_KILL_HUMAN;
1267                         break;
1268                 case 15:
1269                         act = _("は電撃に覆われた!", "covered with lightning!");
1270                         o_ptr->name2 = EGO_BRAND_ELEC;
1271                         break;
1272                 case 14:
1273                         act = _("は酸に覆われた!", "coated with acid!");
1274                         o_ptr->name2 = EGO_BRAND_ACID;
1275                         break;
1276                 case 13:
1277                         act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
1278                         o_ptr->name2 = EGO_KILL_EVIL;
1279                         break;
1280                 case 12:
1281                         act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
1282                         o_ptr->name2 = EGO_KILL_DEMON;
1283                         break;
1284                 case 11:
1285                         act = _("は屍を求めている!", "seems to be looking for undead!");
1286                         o_ptr->name2 = EGO_KILL_UNDEAD;
1287                         break;
1288                 case 10:
1289                         act = _("は動物の血を求めている!", "seems to be looking for animals!");
1290                         o_ptr->name2 = EGO_KILL_ANIMAL;
1291                         break;
1292                 case 9:
1293                         act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
1294                         o_ptr->name2 = EGO_KILL_DRAGON;
1295                         break;
1296                 case 8:
1297                         act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
1298                         o_ptr->name2 = EGO_KILL_TROLL;
1299                         break;
1300                 case 7:
1301                         act = _("はオークの血を求めている!", "seems to be looking for orcs!");
1302                         o_ptr->name2 = EGO_KILL_ORC;
1303                         break;
1304                 case 6:
1305                         act = _("は巨人の血を求めている!", "seems to be looking for giants!");
1306                         o_ptr->name2 = EGO_KILL_GIANT;
1307                         break;
1308                 case 5:
1309                         act = _("は非常に不安定になったようだ。", "seems very unstable now.");
1310                         o_ptr->name2 = EGO_TRUMP;
1311                         o_ptr->pval = randint1(2);
1312                         break;
1313                 case 4:
1314                         act = _("は血を求めている!", "thirsts for blood!");
1315                         o_ptr->name2 = EGO_VAMPIRIC;
1316                         break;
1317                 case 3:
1318                         act = _("は毒に覆われた。", "is coated with poison.");
1319                         o_ptr->name2 = EGO_BRAND_POIS;
1320                         break;
1321                 case 2:
1322                         act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
1323                         o_ptr->name2 = EGO_CHAOTIC;
1324                         break;
1325                 case 1:
1326                         act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
1327                         o_ptr->name2 = EGO_BRAND_FIRE;
1328                         break;
1329                 default:
1330                         act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
1331                         o_ptr->name2 = EGO_BRAND_COLD;
1332                         break;
1333                 }
1334
1335                 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
1336                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
1337
1338                 o_ptr->discount = 99;
1339                 chg_virtue(V_ENCHANT, 2);
1340         }
1341         else
1342         {
1343                 if (flush_failure) flush();
1344
1345                 msg_print(_("属性付加に失敗した。", "The Branding failed."));
1346                 chg_virtue(V_ENCHANT, -2);
1347         }
1348         calc_android_exp();
1349 }
1350
1351
1352 /*!
1353  * @brief 虚無招来によるフロア中の全壁除去処理 /
1354  * Vanish all walls in this floor
1355  * @return 実際に処理が反映された場合TRUE
1356  */
1357 static bool vanish_dungeon(void)
1358 {
1359         POSITION y, x;
1360         cave_type *c_ptr;
1361         feature_type *f_ptr;
1362         monster_type *m_ptr;
1363         char m_name[80];
1364
1365         /* Prevent vasishing of quest levels and town */
1366         if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !dun_level)
1367         {
1368                 return FALSE;
1369         }
1370
1371         /* Scan all normal grids */
1372         for (y = 1; y < cur_hgt - 1; y++)
1373         {
1374                 for (x = 1; x < cur_wid - 1; x++)
1375                 {
1376                         c_ptr = &cave[y][x];
1377
1378                         /* Seeing true feature code (ignore mimic) */
1379                         f_ptr = &f_info[c_ptr->feat];
1380
1381                         /* Lose room and vault */
1382                         c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1383
1384                         m_ptr = &m_list[c_ptr->m_idx];
1385
1386                         /* Awake monster */
1387                         if (c_ptr->m_idx && MON_CSLEEP(m_ptr))
1388                         {
1389                                 /* Reset sleep counter */
1390                                 (void)set_monster_csleep(c_ptr->m_idx, 0);
1391
1392                                 /* Notice the "waking up" */
1393                                 if (m_ptr->ml)
1394                                 {
1395                                         /* Acquire the monster name */
1396                                         monster_desc(m_name, m_ptr, 0);
1397
1398                                         /* Dump a message */
1399                                         msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1400                                 }
1401                         }
1402
1403                         /* Process all walls, doors and patterns */
1404                         if (have_flag(f_ptr->flags, FF_HURT_DISI)) cave_alter_feat(y, x, FF_HURT_DISI);
1405                 }
1406         }
1407
1408         /* Special boundary walls -- Top and bottom */
1409         for (x = 0; x < cur_wid; x++)
1410         {
1411                 c_ptr = &cave[0][x];
1412                 f_ptr = &f_info[c_ptr->mimic];
1413
1414                 /* Lose room and vault */
1415                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1416
1417                 /* Set boundary mimic if needed */
1418                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1419                 {
1420                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1421
1422                         /* Check for change to boring grid */
1423                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1424                 }
1425
1426                 c_ptr = &cave[cur_hgt - 1][x];
1427                 f_ptr = &f_info[c_ptr->mimic];
1428
1429                 /* Lose room and vault */
1430                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1431
1432                 /* Set boundary mimic if needed */
1433                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1434                 {
1435                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1436
1437                         /* Check for change to boring grid */
1438                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1439                 }
1440         }
1441
1442         /* Special boundary walls -- Left and right */
1443         for (y = 1; y < (cur_hgt - 1); y++)
1444         {
1445                 c_ptr = &cave[y][0];
1446                 f_ptr = &f_info[c_ptr->mimic];
1447
1448                 /* Lose room and vault */
1449                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1450
1451                 /* Set boundary mimic if needed */
1452                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1453                 {
1454                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1455
1456                         /* Check for change to boring grid */
1457                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1458                 }
1459
1460                 c_ptr = &cave[y][cur_wid - 1];
1461                 f_ptr = &f_info[c_ptr->mimic];
1462
1463                 /* Lose room and vault */
1464                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1465
1466                 /* Set boundary mimic if needed */
1467                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1468                 {
1469                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1470
1471                         /* Check for change to boring grid */
1472                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1473                 }
1474         }
1475
1476         /* Mega-Hack -- Forget the view and lite */
1477         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1478
1479         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
1480
1481         /* Update the monsters */
1482         p_ptr->update |= (PU_MONSTERS);
1483
1484         /* Redraw map */
1485         p_ptr->redraw |= (PR_MAP);
1486
1487         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1488
1489         return TRUE;
1490 }
1491
1492 /*!
1493  * @brief 虚無招来処理 /
1494  * @return なし
1495  */
1496 void call_the_(void)
1497 {
1498         int i;
1499         cave_type *c_ptr;
1500         bool do_call = TRUE;
1501
1502         for (i = 0; i < 9; i++)
1503         {
1504                 c_ptr = &cave[p_ptr->y + ddy_ddd[i]][p_ptr->x + ddx_ddd[i]];
1505
1506                 if (!cave_have_flag_grid(c_ptr, FF_PROJECT))
1507                 {
1508                         if (!c_ptr->mimic || !have_flag(f_info[c_ptr->mimic].flags, FF_PROJECT) ||
1509                             !permanent_wall(&f_info[c_ptr->feat]))
1510                         {
1511                                 do_call = FALSE;
1512                                 break;
1513                         }
1514                 }
1515         }
1516
1517         if (do_call)
1518         {
1519                 for (i = 1; i < 10; i++)
1520                 {
1521                         if (i - 5) fire_ball(GF_ROCKET, i, 175, 2);
1522                 }
1523
1524                 for (i = 1; i < 10; i++)
1525                 {
1526                         if (i - 5) fire_ball(GF_MANA, i, 175, 3);
1527                 }
1528
1529                 for (i = 1; i < 10; i++)
1530                 {
1531                         if (i - 5) fire_ball(GF_NUKE, i, 175, 4);
1532                 }
1533         }
1534
1535         /* Prevent destruction of quest levels and town */
1536         else if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !dun_level)
1537         {
1538                 msg_print(_("地面が揺れた。", "The ground trembles."));
1539         }
1540
1541         else
1542         {
1543 #ifdef JP
1544                 msg_format("あなたは%sを壁に近すぎる場所で唱えてしまった!",
1545                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "祈り" : "呪文"));
1546                 msg_print("大きな爆発音があった!");
1547 #else
1548                 msg_format("You %s the %s too close to a wall!",
1549                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1550                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "prayer" : "spell"));
1551                 msg_print("There is a loud explosion!");
1552 #endif
1553
1554                 if (one_in_(666))
1555                 {
1556                         if (!vanish_dungeon()) msg_print(_("ダンジョンは一瞬静まり返った。", "The dungeon silences a moment."));
1557                 }
1558                 else
1559                 {
1560                         if (destroy_area(p_ptr->y, p_ptr->x, 15 + p_ptr->lev + randint0(11), FALSE))
1561                                 msg_print(_("ダンジョンが崩壊した...", "The dungeon collapses..."));
1562                         else
1563                                 msg_print(_("ダンジョンは大きく揺れた。", "The dungeon trembles."));
1564                 }
1565
1566                 take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), _("自殺的な虚無招来", "a suicidal Call the Void"), -1);
1567         }
1568 }
1569
1570
1571 /*!
1572  * @brief アイテム引き寄せ処理 /
1573  * Fetch an item (teleport it right underneath the caster)
1574  * @param dir 魔法の発動方向
1575  * @param wgt 許容重量
1576  * @param require_los 射線の通りを要求するならばTRUE
1577  * @return なし
1578  */
1579 void fetch(DIRECTION dir, WEIGHT wgt, bool require_los)
1580 {
1581         POSITION ty, tx;
1582         OBJECT_IDX i;
1583         cave_type *c_ptr;
1584         object_type *o_ptr;
1585         char o_name[MAX_NLEN];
1586
1587         /* Check to see if an object is already there */
1588         if (cave[p_ptr->y][p_ptr->x].o_idx)
1589         {
1590                 msg_print(_("自分の足の下にある物は取れません。", "You can't fetch when you're already standing on something."));
1591                 return;
1592         }
1593
1594         /* Use a target */
1595         if (dir == 5 && target_okay())
1596         {
1597                 tx = target_col;
1598                 ty = target_row;
1599
1600                 if (distance(p_ptr->y, p_ptr->x, ty, tx) > MAX_RANGE)
1601                 {
1602                         msg_print(_("そんなに遠くにある物は取れません!", "You can't fetch something that far away!"));
1603                         return;
1604                 }
1605
1606                 c_ptr = &cave[ty][tx];
1607
1608                 /* We need an item to fetch */
1609                 if (!c_ptr->o_idx)
1610                 {
1611                         msg_print(_("そこには何もありません。", "There is no object at this place."));
1612                         return;
1613                 }
1614
1615                 /* No fetching from vault */
1616                 if (c_ptr->info & CAVE_ICKY)
1617                 {
1618                         msg_print(_("アイテムがコントロールを外れて落ちた。", "The item slips from your control."));
1619                         return;
1620                 }
1621
1622                 /* We need to see the item */
1623                 if (require_los)
1624                 {
1625                         if (!player_has_los_bold(ty, tx))
1626                         {
1627                                 msg_print(_("そこはあなたの視界に入っていません。", "You have no direct line of sight to that location."));
1628                                 return;
1629                         }
1630                         else if (!projectable(p_ptr->y, p_ptr->x, ty, tx))
1631                         {
1632                                 msg_print(_("そこは壁の向こうです。", "You have no direct line of sight to that location."));
1633                                 return;
1634                         }
1635                 }
1636         }
1637         else
1638         {
1639                 /* Use a direction */
1640                 ty = p_ptr->y; /* Where to drop the item */
1641                 tx = p_ptr->x;
1642
1643                 do
1644                 {
1645                         ty += ddy[dir];
1646                         tx += ddx[dir];
1647                         c_ptr = &cave[ty][tx];
1648
1649                         if ((distance(p_ptr->y, p_ptr->x, ty, tx) > MAX_RANGE) ||
1650                                 !cave_have_flag_bold(ty, tx, FF_PROJECT)) return;
1651                 }
1652                 while (!c_ptr->o_idx);
1653         }
1654
1655         o_ptr = &o_list[c_ptr->o_idx];
1656
1657         if (o_ptr->weight > wgt)
1658         {
1659                 /* Too heavy to 'fetch' */
1660                 msg_print(_("そのアイテムは重過ぎます。", "The object is too heavy."));
1661                 return;
1662         }
1663
1664         i = c_ptr->o_idx;
1665         c_ptr->o_idx = o_ptr->next_o_idx;
1666         cave[p_ptr->y][p_ptr->x].o_idx = i; /* 'move' it */
1667
1668         o_ptr->next_o_idx = 0;
1669         o_ptr->iy = (byte)p_ptr->y;
1670         o_ptr->ix = (byte)p_ptr->x;
1671
1672         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1673         msg_format(_("%^sがあなたの足元に飛んできた。", "%^s flies through the air to your feet."), o_name);
1674
1675         note_spot(p_ptr->y, p_ptr->x);
1676         p_ptr->redraw |= PR_MAP;
1677 }
1678
1679 /*!
1680  * @brief 現実変容処理
1681  * @return なし
1682  */
1683 void alter_reality(void)
1684 {
1685         /* Ironman option */
1686         if (p_ptr->inside_arena || ironman_downward)
1687         {
1688                 msg_print(_("何も起こらなかった。", "Nothing happens."));
1689                 return;
1690         }
1691
1692         if (!p_ptr->alter_reality)
1693         {
1694                 TIME_EFFECT turns = randint0(21) + 15;
1695
1696                 p_ptr->alter_reality = turns;
1697                 msg_print(_("回りの景色が変わり始めた...", "The view around you begins to change..."));
1698
1699                 p_ptr->redraw |= (PR_STATUS);
1700         }
1701         else
1702         {
1703                 p_ptr->alter_reality = 0;
1704                 msg_print(_("景色が元に戻った...", "The view around you got back..."));
1705                 p_ptr->redraw |= (PR_STATUS);
1706         }
1707         return;
1708 }
1709
1710
1711 /*!
1712  * @brief 守りのルーン設置処理 /
1713  * Leave a "glyph of warding" which prevents monster movement
1714  * @return 実際に設置が行われた場合TRUEを返す
1715  */
1716 bool warding_glyph(void)
1717 {
1718         if (!cave_clean_bold(p_ptr->y, p_ptr->x))
1719         {
1720                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1721                 return FALSE;
1722         }
1723
1724         /* Create a glyph */
1725         cave[p_ptr->y][p_ptr->x].info |= CAVE_OBJECT;
1726         cave[p_ptr->y][p_ptr->x].mimic = feat_glyph;
1727
1728         note_spot(p_ptr->y, p_ptr->x);
1729
1730         /* Redraw */
1731         lite_spot(p_ptr->y, p_ptr->x);
1732
1733         return TRUE;
1734 }
1735
1736 /*!
1737  * @brief 鏡設置処理
1738  * @return 実際に設置が行われた場合TRUEを返す
1739  */
1740 bool place_mirror(void)
1741 {
1742         if (!cave_clean_bold(p_ptr->y, p_ptr->x))
1743         {
1744                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1745                 return FALSE;
1746         }
1747
1748         /* Create a mirror */
1749         cave[p_ptr->y][p_ptr->x].info |= CAVE_OBJECT;
1750         cave[p_ptr->y][p_ptr->x].mimic = feat_mirror;
1751
1752         /* Turn on the light */
1753         cave[p_ptr->y][p_ptr->x].info |= CAVE_GLOW;
1754
1755         note_spot(p_ptr->y, p_ptr->x);
1756
1757         /* Redraw */
1758         lite_spot(p_ptr->y, p_ptr->x);
1759
1760         update_local_illumination(p_ptr->y, p_ptr->x);
1761
1762         return TRUE;
1763 }
1764
1765
1766 /*!
1767  * @brief 爆発のルーン設置処理 /
1768  * Leave an "explosive rune" which prevents monster movement
1769  * @return 実際に設置が行われた場合TRUEを返す
1770  */
1771 bool explosive_rune(void)
1772 {
1773         if (!cave_clean_bold(p_ptr->y, p_ptr->x))
1774         {
1775                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1776                 return FALSE;
1777         }
1778
1779         /* Create a glyph */
1780         cave[p_ptr->y][p_ptr->x].info |= CAVE_OBJECT;
1781         cave[p_ptr->y][p_ptr->x].mimic = feat_explosive_rune;
1782
1783         note_spot(p_ptr->y, p_ptr->x);
1784         
1785         /* Redraw */
1786         lite_spot(p_ptr->y, p_ptr->x);
1787
1788         return TRUE;
1789 }
1790
1791
1792 /*!
1793  * @brief 全所持アイテム鑑定処理 /
1794  * Identify everything being carried.
1795  * Done by a potion of "self knowledge".
1796  * @return なし
1797  */
1798 void identify_pack(void)
1799 {
1800         INVENTORY_IDX i;
1801
1802         /* Simply identify and know every item */
1803         for (i = 0; i < INVEN_TOTAL; i++)
1804         {
1805                 object_type *o_ptr = &inventory[i];
1806
1807                 /* Skip non-objects */
1808                 if (!o_ptr->k_idx) continue;
1809
1810                 /* Identify it */
1811                 identify_item(o_ptr);
1812
1813                 /* Auto-inscription */
1814                 autopick_alter_item(i, FALSE);
1815         }
1816 }
1817
1818
1819 /*!
1820  * @brief 装備強化処理の失敗率定数(千分率) /
1821  * Used by the "enchant" function (chance of failure)
1822  * (modified for Zangband, we need better stuff there...) -- TY
1823  * @return なし
1824  */
1825 static int enchant_table[16] =
1826 {
1827         0, 10,  50, 100, 200,
1828         300, 400, 500, 650, 800,
1829         950, 987, 993, 995, 998,
1830         1000
1831 };
1832
1833
1834 /*!
1835  * @brief 装備の解呪処理 /
1836  * Removes curses from items in inventory
1837  * @param all 軽い呪いまでの解除ならば0
1838  * @return 解呪されたアイテムの数
1839  * @details
1840  * <pre>
1841  * Note that Items which are "Perma-Cursed" (The One Ring,
1842  * The Crown of Morgoth) can NEVER be uncursed.
1843  *
1844  * Note that if "all" is FALSE, then Items which are
1845  * "Heavy-Cursed" (Mormegil, Calris, and Weapons of Morgul)
1846  * will not be uncursed.
1847  * </pre>
1848  */
1849 static int remove_curse_aux(int all)
1850 {
1851         int i, cnt = 0;
1852
1853         /* Attempt to uncurse items being worn */
1854         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1855         {
1856                 object_type *o_ptr = &inventory[i];
1857
1858                 /* Skip non-objects */
1859                 if (!o_ptr->k_idx) continue;
1860
1861                 /* Uncursed already */
1862                 if (!object_is_cursed(o_ptr)) continue;
1863
1864                 /* Heavily Cursed Items need a special spell */
1865                 if (!all && (o_ptr->curse_flags & TRC_HEAVY_CURSE)) continue;
1866
1867                 /* Perma-Cursed Items can NEVER be uncursed */
1868                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
1869                 {
1870                         /* Uncurse it */
1871                         o_ptr->curse_flags &= (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE);
1872                         continue;
1873                 }
1874
1875                 /* Uncurse it */
1876                 o_ptr->curse_flags = 0L;
1877
1878                 /* Hack -- Assume felt */
1879                 o_ptr->ident |= (IDENT_SENSE);
1880
1881                 /* Take note */
1882                 o_ptr->feeling = FEEL_NONE;
1883
1884                 /* Recalculate the bonuses */
1885                 p_ptr->update |= (PU_BONUS);
1886
1887                 p_ptr->window |= (PW_EQUIP);
1888
1889                 /* Count the uncursings */
1890                 cnt++;
1891         }
1892
1893         if (cnt)
1894         {
1895                 msg_print(_("誰かに見守られているような気がする。", "You feel as if someone is watching over you."));
1896         }
1897         /* Return "something uncursed" */
1898         return (cnt);
1899 }
1900
1901
1902 /*!
1903  * @brief 装備の軽い呪い解呪処理 /
1904  * Remove most curses
1905  * @return 解呪に成功した装備数
1906  */
1907 int remove_curse(void)
1908 {
1909         return (remove_curse_aux(FALSE));
1910 }
1911
1912 /*!
1913  * @brief 装備の重い呪い解呪処理 /
1914  * Remove all curses
1915  * @return 解呪に成功した装備数
1916  */
1917 int remove_all_curse(void)
1918 {
1919         return (remove_curse_aux(TRUE));
1920 }
1921
1922
1923 /*!
1924  * @brief アイテムの価値に応じた錬金術処理 /
1925  * Turns an object into gold, gain some of its value in a shop
1926  * @return 処理が実際に行われたらTRUEを返す
1927  */
1928 bool alchemy(void)
1929 {
1930         OBJECT_IDX item;
1931         int amt = 1;
1932         ITEM_NUMBER old_number;
1933         PRICE price;
1934         bool force = FALSE;
1935         object_type *o_ptr;
1936         char o_name[MAX_NLEN];
1937         char out_val[MAX_NLEN+40];
1938
1939         cptr q, s;
1940
1941         /* Hack -- force destruction */
1942         if (command_arg > 0) force = TRUE;
1943
1944         q = _("どのアイテムを金に変えますか?", "Turn which item to gold? ");
1945         s = _("金に変えられる物がありません。", "You have nothing to turn to gold.");
1946
1947         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
1948
1949         /* Get the item (in the pack) */
1950         if (item >= 0)
1951         {
1952                 o_ptr = &inventory[item];
1953         }
1954
1955         /* Get the item (on the floor) */
1956         else
1957         {
1958                 o_ptr = &o_list[0 - item];
1959         }
1960
1961
1962         /* See how many items */
1963         if (o_ptr->number > 1)
1964         {
1965                 /* Get a quantity */
1966                 amt = get_quantity(NULL, o_ptr->number);
1967
1968                 /* Allow user abort */
1969                 if (amt <= 0) return FALSE;
1970         }
1971
1972
1973         old_number = o_ptr->number;
1974         o_ptr->number = amt;
1975         object_desc(o_name, o_ptr, 0);
1976         o_ptr->number = old_number;
1977
1978         /* Verify unless quantity given */
1979         if (!force)
1980         {
1981                 if (confirm_destroy || (object_value(o_ptr) > 0))
1982                 {
1983                         /* Make a verification */
1984                         sprintf(out_val, _("本当に%sを金に変えますか?", "Really turn %s to gold? "), o_name);
1985                         if (!get_check(out_val)) return FALSE;
1986                 }
1987         }
1988
1989         /* Artifacts cannot be destroyed */
1990         if (!can_player_destroy_object(o_ptr))
1991         {
1992                 msg_format(_("%sを金に変えることに失敗した。", "You fail to turn %s to gold!"), o_name);
1993
1994                 return FALSE;
1995         }
1996
1997         price = object_value_real(o_ptr);
1998
1999         if (price <= 0)
2000         {
2001                 msg_format(_("%sをニセの金に変えた。", "You turn %s to fool's gold."), o_name);
2002         }
2003         else
2004         {
2005                 price /= 3;
2006
2007                 if (amt > 1) price *= amt;
2008
2009                 if (price > 30000) price = 30000;
2010                 msg_format(_("%sを$%d の金に変えた。", "You turn %s to %ld coins worth of gold."), o_name, price);
2011
2012                 p_ptr->au += price;
2013
2014                 /* Redraw gold */
2015                 p_ptr->redraw |= (PR_GOLD);
2016
2017                 p_ptr->window |= (PW_PLAYER);
2018
2019         }
2020
2021         /* Eliminate the item (from the pack) */
2022         if (item >= 0)
2023         {
2024                 inven_item_increase(item, -amt);
2025                 inven_item_describe(item);
2026                 inven_item_optimize(item);
2027         }
2028
2029         /* Eliminate the item (from the floor) */
2030         else
2031         {
2032                 floor_item_increase(0 - item, -amt);
2033                 floor_item_describe(0 - item);
2034                 floor_item_optimize(0 - item);
2035         }
2036
2037         return TRUE;
2038 }
2039
2040
2041 /*!
2042  * @brief 呪いの打ち破り処理 /
2043  * Break the curse of an item
2044  * @param o_ptr 呪い装備情報の参照ポインタ
2045  * @return なし
2046  */
2047 static void break_curse(object_type *o_ptr)
2048 {
2049         if (object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
2050         {
2051                 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
2052
2053                 o_ptr->curse_flags = 0L;
2054                 o_ptr->ident |= (IDENT_SENSE);
2055                 o_ptr->feeling = FEEL_NONE;
2056         }
2057 }
2058
2059
2060 /*!
2061  * @brief 装備修正強化処理 /
2062  * Enchants a plus onto an item. -RAK-
2063  * @param o_ptr 強化するアイテムの参照ポインタ
2064  * @param n 強化基本量
2065  * @param eflag 強化オプション(命中/ダメージ/AC)
2066  * @return 強化に成功した場合TRUEを返す
2067  * @details
2068  * <pre>
2069  * Revamped!  Now takes item pointer, number of times to try enchanting,
2070  * and a flag of what to try enchanting.  Artifacts resist enchantment
2071  * some of the time, and successful enchantment to at least +0 might
2072  * break a curse on the item. -CFT-
2073  *
2074  * Note that an item can technically be enchanted all the way to +15 if
2075  * you wait a very, very, long time.  Going from +9 to +10 only works
2076  * about 5% of the time, and from +10 to +11 only about 1% of the time.
2077  *
2078  * Note that this function can now be used on "piles" of items, and
2079  * the larger the pile, the lower the chance of success.
2080  * </pre>
2081  */
2082 bool enchant(object_type *o_ptr, int n, int eflag)
2083 {
2084         int     i, chance, prob;
2085         bool    res = FALSE;
2086         bool    a = object_is_artifact(o_ptr);
2087         bool    force = (eflag & ENCH_FORCE);
2088
2089
2090         /* Large piles resist enchantment */
2091         prob = o_ptr->number * 100;
2092
2093         /* Missiles are easy to enchant */
2094         if ((o_ptr->tval == TV_BOLT) ||
2095             (o_ptr->tval == TV_ARROW) ||
2096             (o_ptr->tval == TV_SHOT))
2097         {
2098                 prob = prob / 20;
2099         }
2100
2101         /* Try "n" times */
2102         for (i = 0; i < n; i++)
2103         {
2104                 /* Hack -- Roll for pile resistance */
2105                 if (!force && randint0(prob) >= 100) continue;
2106
2107                 /* Enchant to hit */
2108                 if (eflag & ENCH_TOHIT)
2109                 {
2110                         if (o_ptr->to_h < 0) chance = 0;
2111                         else if (o_ptr->to_h > 15) chance = 1000;
2112                         else chance = enchant_table[o_ptr->to_h];
2113
2114                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2115                         {
2116                                 o_ptr->to_h++;
2117                                 res = TRUE;
2118
2119                                 /* only when you get it above -1 -CFT */
2120                                 if (o_ptr->to_h >= 0)
2121                                         break_curse(o_ptr);
2122                         }
2123                 }
2124
2125                 /* Enchant to damage */
2126                 if (eflag & ENCH_TODAM)
2127                 {
2128                         if (o_ptr->to_d < 0) chance = 0;
2129                         else if (o_ptr->to_d > 15) chance = 1000;
2130                         else chance = enchant_table[o_ptr->to_d];
2131
2132                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2133                         {
2134                                 o_ptr->to_d++;
2135                                 res = TRUE;
2136
2137                                 /* only when you get it above -1 -CFT */
2138                                 if (o_ptr->to_d >= 0)
2139                                         break_curse(o_ptr);
2140                         }
2141                 }
2142
2143                 /* Enchant to armor class */
2144                 if (eflag & ENCH_TOAC)
2145                 {
2146                         if (o_ptr->to_a < 0) chance = 0;
2147                         else if (o_ptr->to_a > 15) chance = 1000;
2148                         else chance = enchant_table[o_ptr->to_a];
2149
2150                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2151                         {
2152                                 o_ptr->to_a++;
2153                                 res = TRUE;
2154
2155                                 /* only when you get it above -1 -CFT */
2156                                 if (o_ptr->to_a >= 0)
2157                                         break_curse(o_ptr);
2158                         }
2159                 }
2160         }
2161
2162         /* Failure */
2163         if (!res) return (FALSE);
2164
2165         /* Recalculate bonuses */
2166         p_ptr->update |= (PU_BONUS);
2167
2168         /* Combine / Reorder the pack (later) */
2169         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2170
2171         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2172
2173         calc_android_exp();
2174
2175         /* Success */
2176         return (TRUE);
2177 }
2178
2179
2180 /*!
2181  * @brief 装備修正強化処理のメインルーチン /
2182  * Enchant an item (in the inventory or on the floor)
2183  * @param num_hit 命中修正量
2184  * @param num_dam ダメージ修正量
2185  * @param num_ac AC修正量
2186  * @return 強化に成功した場合TRUEを返す
2187  * @details
2188  * Note that "num_ac" requires armour, else weapon
2189  * Returns TRUE if attempted, FALSE if cancelled
2190  */
2191 bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
2192 {
2193         OBJECT_IDX item;
2194         bool        okay = FALSE;
2195         object_type *o_ptr;
2196         char        o_name[MAX_NLEN];
2197         cptr        q, s;
2198
2199
2200         /* Assume enchant weapon */
2201         item_tester_hook = object_allow_enchant_weapon;
2202         item_tester_no_ryoute = TRUE;
2203
2204         /* Enchant armor if requested */
2205         if (num_ac) item_tester_hook = object_is_armour;
2206
2207         q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
2208         s = _("強化できるアイテムがない。", "You have nothing to enchant.");
2209
2210         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2211
2212         /* Get the item (in the pack) */
2213         if (item >= 0)
2214         {
2215                 o_ptr = &inventory[item];
2216         }
2217
2218         /* Get the item (on the floor) */
2219         else
2220         {
2221                 o_ptr = &o_list[0 - item];
2222         }
2223
2224
2225         /* Description */
2226         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2227 #ifdef JP
2228         msg_format("%s は明るく輝いた!", o_name);
2229 #else
2230         msg_format("%s %s glow%s brightly!",
2231                    ((item >= 0) ? "Your" : "The"), o_name,
2232                    ((o_ptr->number > 1) ? "" : "s"));
2233 #endif
2234
2235
2236         /* Enchant */
2237         if (enchant(o_ptr, num_hit, ENCH_TOHIT)) okay = TRUE;
2238         if (enchant(o_ptr, num_dam, ENCH_TODAM)) okay = TRUE;
2239         if (enchant(o_ptr, num_ac, ENCH_TOAC)) okay = TRUE;
2240
2241         /* Failure */
2242         if (!okay)
2243         {
2244                 if (flush_failure) flush();
2245                 msg_print(_("強化に失敗した。", "The enchantment failed."));
2246                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2247         }
2248         else
2249                 chg_virtue(V_ENCHANT, 1);
2250
2251         calc_android_exp();
2252
2253         /* Something happened */
2254         return (TRUE);
2255 }
2256
2257
2258 /*!
2259  * @brief アーティファクト生成の巻物処理 /
2260  * @return 生成が実際に試みられたらTRUEを返す
2261  */
2262 bool artifact_scroll(void)
2263 {
2264         OBJECT_IDX item;
2265         bool            okay = FALSE;
2266         object_type     *o_ptr;
2267         char            o_name[MAX_NLEN];
2268         cptr            q, s;
2269
2270
2271         item_tester_no_ryoute = TRUE;
2272
2273         /* Enchant weapon/armour */
2274         item_tester_hook = item_tester_hook_nameless_weapon_armour;
2275
2276         q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
2277         s = _("強化できるアイテムがない。", "You have nothing to enchant.");
2278
2279         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2280
2281         /* Get the item (in the pack) */
2282         if (item >= 0)
2283         {
2284                 o_ptr = &inventory[item];
2285         }
2286
2287         /* Get the item (on the floor) */
2288         else
2289         {
2290                 o_ptr = &o_list[0 - item];
2291         }
2292
2293
2294         /* Description */
2295         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2296 #ifdef JP
2297         msg_format("%s は眩い光を発した!",o_name);
2298 #else
2299         msg_format("%s %s radiate%s a blinding light!",
2300                   ((item >= 0) ? "Your" : "The"), o_name,
2301                   ((o_ptr->number > 1) ? "" : "s"));
2302 #endif
2303
2304         if (object_is_artifact(o_ptr))
2305         {
2306 #ifdef JP
2307                 msg_format("%sは既に伝説のアイテムです!", o_name  );
2308 #else
2309                 msg_format("The %s %s already %s!",
2310                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2311                     ((o_ptr->number > 1) ? "artifacts" : "an artifact"));
2312 #endif
2313
2314                 okay = FALSE;
2315         }
2316
2317         else if (object_is_ego(o_ptr))
2318         {
2319 #ifdef JP
2320                 msg_format("%sは既に名のあるアイテムです!", o_name );
2321 #else
2322                 msg_format("The %s %s already %s!",
2323                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2324                     ((o_ptr->number > 1) ? "ego items" : "an ego item"));
2325 #endif
2326
2327                 okay = FALSE;
2328         }
2329
2330         else if (o_ptr->xtra3)
2331         {
2332 #ifdef JP
2333                 msg_format("%sは既に強化されています!", o_name );
2334 #else
2335                 msg_format("The %s %s already %s!",
2336                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2337                     ((o_ptr->number > 1) ? "customized items" : "a customized item"));
2338 #endif
2339         }
2340
2341         else
2342         {
2343                 if (o_ptr->number > 1)
2344                 {
2345 #ifdef JP
2346                         msg_print("複数のアイテムに魔法をかけるだけのエネルギーはありません!");
2347                         msg_format("%d 個の%sが壊れた!",(o_ptr->number)-1, o_name);
2348 #else
2349                         msg_print("Not enough enough energy to enchant more than one object!");
2350                         msg_format("%d of your %s %s destroyed!",(o_ptr->number)-1, o_name, (o_ptr->number>2?"were":"was"));
2351 #endif
2352
2353                         if (item >= 0)
2354                         {
2355                                 inven_item_increase(item, 1-(o_ptr->number));
2356                         }
2357                         else
2358                         {
2359                                 floor_item_increase(0-item, 1-(o_ptr->number));
2360                         }
2361                 }
2362                 okay = create_artifact(o_ptr, TRUE);
2363         }
2364
2365         /* Failure */
2366         if (!okay)
2367         {
2368                 if (flush_failure) flush();
2369                 msg_print(_("強化に失敗した。", "The enchantment failed."));
2370                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2371         }
2372         else
2373         {
2374                 if (record_rand_art)
2375                 {
2376                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2377                         do_cmd_write_nikki(NIKKI_ART_SCROLL, 0, o_name);
2378                 }
2379                 chg_virtue(V_ENCHANT, 1);
2380         }
2381
2382         calc_android_exp();
2383
2384         /* Something happened */
2385         return (TRUE);
2386 }
2387
2388
2389 /*!
2390  * @brief アイテム鑑定処理 /
2391  * Identify an object
2392  * @param o_ptr 鑑定されるアイテムの情報参照ポインタ
2393  * @return 実際に鑑定できたらTRUEを返す
2394  */
2395 bool identify_item(object_type *o_ptr)
2396 {
2397         bool old_known = FALSE;
2398         char o_name[MAX_NLEN];
2399
2400         /* Description */
2401         object_desc(o_name, o_ptr, 0);
2402
2403         if (o_ptr->ident & IDENT_KNOWN)
2404                 old_known = TRUE;
2405
2406         if (!(o_ptr->ident & (IDENT_MENTAL)))
2407         {
2408                 if (object_is_artifact(o_ptr) || one_in_(5))
2409                         chg_virtue(V_KNOWLEDGE, 1);
2410         }
2411
2412         /* Identify it fully */
2413         object_aware(o_ptr);
2414         object_known(o_ptr);
2415
2416         /* Player touches it */
2417         o_ptr->marked |= OM_TOUCHED;
2418
2419         /* Recalculate bonuses */
2420         p_ptr->update |= (PU_BONUS);
2421
2422         /* Combine / Reorder the pack (later) */
2423         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2424
2425         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2426
2427         strcpy(record_o_name, o_name);
2428         record_turn = turn;
2429
2430         /* Description */
2431         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2432
2433         if(record_fix_art && !old_known && object_is_fixed_artifact(o_ptr))
2434                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2435         if(record_rand_art && !old_known && o_ptr->art_name)
2436                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2437
2438         return old_known;
2439 }
2440
2441 /*!
2442  * @brief アイテム鑑定のメインルーチン処理 /
2443  * Identify an object in the inventory (or on the floor)
2444  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2445  * @return 実際に鑑定を行ったならばTRUEを返す
2446  * @details
2447  * This routine does *not* automatically combine objects.
2448  * Returns TRUE if something was identified, else FALSE.
2449  */
2450 bool ident_spell(bool only_equip)
2451 {
2452         OBJECT_IDX item;
2453         object_type     *o_ptr;
2454         char            o_name[MAX_NLEN];
2455         cptr            q, s;
2456         bool old_known;
2457
2458         item_tester_no_ryoute = TRUE;
2459
2460         if (only_equip)
2461                 item_tester_hook = item_tester_hook_identify_weapon_armour;
2462         else
2463                 item_tester_hook = item_tester_hook_identify;
2464
2465         if (can_get_item())
2466         {
2467                 q = _("どのアイテムを鑑定しますか? ", "Identify which item? ");
2468         }
2469         else
2470         {
2471                 if (only_equip)
2472                         item_tester_hook = object_is_weapon_armour_ammo;
2473                 else
2474                         item_tester_hook = NULL;
2475
2476                 q = _("すべて鑑定済みです。 ", "All items are identified. ");
2477         }
2478
2479         s = _("鑑定するべきアイテムがない。", "You have nothing to identify.");
2480
2481         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2482
2483         /* Get the item (in the pack) */
2484         if (item >= 0)
2485         {
2486                 o_ptr = &inventory[item];
2487         }
2488
2489         /* Get the item (on the floor) */
2490         else
2491         {
2492                 o_ptr = &o_list[0 - item];
2493         }
2494
2495         /* Identify it */
2496         old_known = identify_item(o_ptr);
2497
2498         /* Description */
2499         object_desc(o_name, o_ptr, 0);
2500         if (item >= INVEN_RARM)
2501         {
2502                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
2503         }
2504         else if (item >= 0)
2505         {
2506                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
2507         }
2508         else
2509         {
2510                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
2511         }
2512
2513         /* Auto-inscription/destroy */
2514         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2515
2516         /* Something happened */
2517         return (TRUE);
2518 }
2519
2520
2521 /*!
2522  * @brief アイテム凡庸化のメインルーチン処理 /
2523  * Identify an object in the inventory (or on the floor)
2524  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2525  * @return 実際に凡庸化をを行ったならばTRUEを返す
2526  * @details
2527  * <pre>
2528  * Mundanify an object in the inventory (or on the floor)
2529  * This routine does *not* automatically combine objects.
2530  * Returns TRUE if something was mundanified, else FALSE.
2531  * </pre>
2532  */
2533 bool mundane_spell(bool only_equip)
2534 {
2535         OBJECT_IDX item;
2536         object_type     *o_ptr;
2537         cptr            q, s;
2538
2539         if (only_equip) item_tester_hook = object_is_weapon_armour_ammo;
2540         item_tester_no_ryoute = TRUE;
2541
2542         q = _("どれを使いますか?", "Use which item? ");
2543         s = _("使えるものがありません。", "You have nothing you can use.");
2544
2545         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2546
2547         /* Get the item (in the pack) */
2548         if (item >= 0)
2549         {
2550                 o_ptr = &inventory[item];
2551         }
2552
2553         /* Get the item (on the floor) */
2554         else
2555         {
2556                 o_ptr = &o_list[0 - item];
2557         }
2558
2559         msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
2560         {
2561                 POSITION iy = o_ptr->iy;                 /* Y-position on map, or zero */
2562                 POSITION ix = o_ptr->ix;                 /* X-position on map, or zero */
2563                 s16b next_o_idx = o_ptr->next_o_idx; /* Next object in stack (if any) */
2564                 byte marked = o_ptr->marked;         /* Object is marked */
2565                 s16b weight = o_ptr->number * o_ptr->weight;
2566                 u16b inscription = o_ptr->inscription;
2567
2568                 /* Wipe it clean */
2569                 object_prep(o_ptr, o_ptr->k_idx);
2570
2571                 o_ptr->iy = iy;
2572                 o_ptr->ix = ix;
2573                 o_ptr->next_o_idx = next_o_idx;
2574                 o_ptr->marked = marked;
2575                 o_ptr->inscription = inscription;
2576                 if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
2577         }
2578         calc_android_exp();
2579
2580         /* Something happened */
2581         return TRUE;
2582 }
2583
2584 /*!
2585  * @brief アイテム*鑑定*のメインルーチン処理 /
2586  * Identify an object in the inventory (or on the floor)
2587  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2588  * @return 実際に鑑定を行ったならばTRUEを返す
2589  * @details
2590  * Fully "identify" an object in the inventory  -BEN-
2591  * This routine returns TRUE if an item was identified.
2592  */
2593 bool identify_fully(bool only_equip)
2594 {
2595         OBJECT_IDX item;
2596         object_type     *o_ptr;
2597         char            o_name[MAX_NLEN];
2598         cptr            q, s;
2599         bool old_known;
2600
2601         item_tester_no_ryoute = TRUE;
2602         if (only_equip)
2603                 item_tester_hook = item_tester_hook_identify_fully_weapon_armour;
2604         else
2605                 item_tester_hook = item_tester_hook_identify_fully;
2606
2607         if (can_get_item())
2608         {
2609                 q = _("どのアイテムを*鑑定*しますか? ", "*Identify* which item? ");
2610         }
2611         else
2612         {
2613                 if (only_equip)
2614                         item_tester_hook = object_is_weapon_armour_ammo;
2615                 else
2616                         item_tester_hook = NULL;
2617
2618                 q = _("すべて*鑑定*済みです。 ", "All items are *identified*. ");
2619         }
2620
2621         s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*.");
2622
2623         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2624
2625         /* Get the item (in the pack) */
2626         if (item >= 0)
2627         {
2628                 o_ptr = &inventory[item];
2629         }
2630
2631         /* Get the item (on the floor) */
2632         else
2633         {
2634                 o_ptr = &o_list[0 - item];
2635         }
2636
2637         /* Identify it */
2638         old_known = identify_item(o_ptr);
2639
2640         /* Mark the item as fully known */
2641         o_ptr->ident |= (IDENT_MENTAL);
2642
2643         /* Handle stuff */
2644         handle_stuff();
2645
2646         /* Description */
2647         object_desc(o_name, o_ptr, 0);
2648         if (item >= INVEN_RARM)
2649         {
2650                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
2651         }
2652         else if (item >= 0)
2653         {
2654                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
2655         }
2656         else
2657         {
2658                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
2659         }
2660
2661         /* Describe it fully */
2662         (void)screen_object(o_ptr, 0L);
2663
2664         /* Auto-inscription/destroy */
2665         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2666
2667         /* Success */
2668         return (TRUE);
2669 }
2670
2671
2672
2673 /*!
2674  * @brief 魔力充填処理 /
2675  * Recharge a wand/staff/rod from the pack or on the floor.
2676  * This function has been rewritten in Oangband and ZAngband.
2677  * @param power 充填パワー
2678  * @return ターン消費を要する処理まで進んだらTRUEを返す
2679  *
2680  * Sorcery/Arcane -- Recharge  --> recharge(plev * 4)
2681  * Chaos -- Arcane Binding     --> recharge(90)
2682  *
2683  * Scroll of recharging        --> recharge(130)
2684  * Artifact activation/Thingol --> recharge(130)
2685  *
2686  * It is harder to recharge high level, and highly charged wands,
2687  * staffs, and rods.  The more wands in a stack, the more easily and
2688  * strongly they recharge.  Staffs, however, each get fewer charges if
2689  * stacked.
2690  *
2691  * Beware of "sliding index errors".
2692  */
2693 bool recharge(int power)
2694 {
2695         OBJECT_IDX item;
2696         DEPTH lev;
2697         int recharge_strength;
2698         TIME_EFFECT recharge_amount;
2699
2700         object_type *o_ptr;
2701         object_kind *k_ptr;
2702
2703         bool fail = FALSE;
2704         byte fail_type = 1;
2705
2706         cptr q, s;
2707         char o_name[MAX_NLEN];
2708
2709         /* Only accept legal items */
2710         item_tester_hook = item_tester_hook_recharge;
2711
2712         q = _("どのアイテムに魔力を充填しますか? ", "Recharge which item? ");
2713         s = _("魔力を充填すべきアイテムがない。", "You have nothing to recharge.");
2714
2715         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
2716
2717         /* Get the item (in the pack) */
2718         if (item >= 0)
2719         {
2720                 o_ptr = &inventory[item];
2721         }
2722
2723         /* Get the item (on the floor) */
2724         else
2725         {
2726                 o_ptr = &o_list[0 - item];
2727         }
2728
2729         /* Get the object kind. */
2730         k_ptr = &k_info[o_ptr->k_idx];
2731
2732         /* Extract the object "level" */
2733         lev = k_info[o_ptr->k_idx].level;
2734
2735
2736         /* Recharge a rod */
2737         if (o_ptr->tval == TV_ROD)
2738         {
2739                 /* Extract a recharge strength by comparing object level to power. */
2740                 recharge_strength = ((power > lev / 2) ? (power - lev / 2) : 0) / 5;
2741
2742
2743                 /* Back-fire */
2744                 if (one_in_(recharge_strength))
2745                 {
2746                         /* Activate the failure code. */
2747                         fail = TRUE;
2748                 }
2749
2750                 /* Recharge */
2751                 else
2752                 {
2753                         /* Recharge amount */
2754                         recharge_amount = (power * damroll(3, 2));
2755
2756                         /* Recharge by that amount */
2757                         if (o_ptr->timeout > recharge_amount)
2758                                 o_ptr->timeout -= recharge_amount;
2759                         else
2760                                 o_ptr->timeout = 0;
2761                 }
2762         }
2763
2764
2765         /* Recharge wand/staff */
2766         else
2767         {
2768                 /* Extract a recharge strength by comparing object level to power.
2769                  * Divide up a stack of wands' charges to calculate charge penalty.
2770                  */
2771                 if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
2772                         recharge_strength = (100 + power - lev - (8 * o_ptr->pval / o_ptr->number)) / 15;
2773
2774                 /* All staffs, unstacked wands. */
2775                 else recharge_strength = (100 + power - lev - (8 * o_ptr->pval)) / 15;
2776
2777                 /* Paranoia */
2778                 if (recharge_strength < 0) recharge_strength = 0;
2779
2780                 /* Back-fire */
2781                 if (one_in_(recharge_strength))
2782                 {
2783                         /* Activate the failure code. */
2784                         fail = TRUE;
2785                 }
2786
2787                 /* If the spell didn't backfire, recharge the wand or staff. */
2788                 else
2789                 {
2790                         /* Recharge based on the standard number of charges. */
2791                         recharge_amount = randint1(1 + k_ptr->pval / 2);
2792
2793                         /* Multiple wands in a stack increase recharging somewhat. */
2794                         if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
2795                         {
2796                                 recharge_amount +=
2797                                         (randint1(recharge_amount * (o_ptr->number - 1))) / 2;
2798                                 if (recharge_amount < 1) recharge_amount = 1;
2799                                 if (recharge_amount > 12) recharge_amount = 12;
2800                         }
2801
2802                         /* But each staff in a stack gets fewer additional charges,
2803                          * although always at least one.
2804                          */
2805                         if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1))
2806                         {
2807                                 recharge_amount /= (TIME_EFFECT)o_ptr->number;
2808                                 if (recharge_amount < 1) recharge_amount = 1;
2809                         }
2810
2811                         /* Recharge the wand or staff. */
2812                         o_ptr->pval += recharge_amount;
2813
2814
2815                         /* Hack -- we no longer "know" the item */
2816                         o_ptr->ident &= ~(IDENT_KNOWN);
2817
2818                         /* Hack -- we no longer think the item is empty */
2819                         o_ptr->ident &= ~(IDENT_EMPTY);
2820                 }
2821         }
2822
2823
2824         /* Inflict the penalties for failing a recharge. */
2825         if (fail)
2826         {
2827                 /* Artifacts are never destroyed. */
2828                 if (object_is_fixed_artifact(o_ptr))
2829                 {
2830                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2831                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
2832
2833                         /* Artifact rods. */
2834                         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout < 10000))
2835                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
2836
2837                         /* Artifact wands and staffs. */
2838                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
2839                                 o_ptr->pval = 0;
2840                 }
2841                 else
2842                 {
2843                         /* Get the object description */
2844                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2845
2846                         /*** Determine Seriousness of Failure ***/
2847
2848                         /* Mages recharge objects more safely. */
2849                         if (IS_WIZARD_CLASS() || p_ptr->pclass == CLASS_MAGIC_EATER || p_ptr->pclass == CLASS_BLUE_MAGE)
2850                         {
2851                                 /* 10% chance to blow up one rod, otherwise draining. */
2852                                 if (o_ptr->tval == TV_ROD)
2853                                 {
2854                                         if (one_in_(10)) fail_type = 2;
2855                                         else fail_type = 1;
2856                                 }
2857                                 /* 75% chance to blow up one wand, otherwise draining. */
2858                                 else if (o_ptr->tval == TV_WAND)
2859                                 {
2860                                         if (!one_in_(3)) fail_type = 2;
2861                                         else fail_type = 1;
2862                                 }
2863                                 /* 50% chance to blow up one staff, otherwise no effect. */
2864                                 else if (o_ptr->tval == TV_STAFF)
2865                                 {
2866                                         if (one_in_(2)) fail_type = 2;
2867                                         else fail_type = 0;
2868                                 }
2869                         }
2870
2871                         /* All other classes get no special favors. */
2872                         else
2873                         {
2874                                 /* 33% chance to blow up one rod, otherwise draining. */
2875                                 if (o_ptr->tval == TV_ROD)
2876                                 {
2877                                         if (one_in_(3)) fail_type = 2;
2878                                         else fail_type = 1;
2879                                 }
2880                                 /* 20% chance of the entire stack, else destroy one wand. */
2881                                 else if (o_ptr->tval == TV_WAND)
2882                                 {
2883                                         if (one_in_(5)) fail_type = 3;
2884                                         else fail_type = 2;
2885                                 }
2886                                 /* Blow up one staff. */
2887                                 else if (o_ptr->tval == TV_STAFF)
2888                                 {
2889                                         fail_type = 2;
2890                                 }
2891                         }
2892
2893                         /*** Apply draining and destruction. ***/
2894
2895                         /* Drain object or stack of objects. */
2896                         if (fail_type == 1)
2897                         {
2898                                 if (o_ptr->tval == TV_ROD)
2899                                 {
2900                                         msg_print(_("魔力が逆噴射して、ロッドからさらに魔力を吸い取ってしまった!", "The recharge backfires, draining the rod further!"));
2901
2902                                         if (o_ptr->timeout < 10000)
2903                                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
2904                                 }
2905                                 else if (o_ptr->tval == TV_WAND)
2906                                 {
2907                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
2908                                         o_ptr->pval = 0;
2909                                 }
2910                                 /* Staffs aren't drained. */
2911                         }
2912
2913                         /* Destroy an object or one in a stack of objects. */
2914                         if (fail_type == 2)
2915                         {
2916                                 if (o_ptr->number > 1)
2917                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
2918                                 else
2919                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
2920
2921                                 /* Reduce rod stack maximum timeout, drain wands. */
2922                                 if (o_ptr->tval == TV_ROD) o_ptr->timeout = (o_ptr->number - 1) * k_ptr->pval;
2923                                 if (o_ptr->tval == TV_WAND) o_ptr->pval = 0;
2924
2925                                 /* Reduce and describe inventory */
2926                                 if (item >= 0)
2927                                 {
2928                                         inven_item_increase(item, -1);
2929                                         inven_item_describe(item);
2930                                         inven_item_optimize(item);
2931                                 }
2932
2933                                 /* Reduce and describe floor item */
2934                                 else
2935                                 {
2936                                         floor_item_increase(0 - item, -1);
2937                                         floor_item_describe(0 - item);
2938                                         floor_item_optimize(0 - item);
2939                                 }
2940                         }
2941
2942                         /* Destroy all members of a stack of objects. */
2943                         if (fail_type == 3)
2944                         {
2945                                 if (o_ptr->number > 1)
2946                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
2947                                 else
2948                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
2949
2950                                 /* Reduce and describe inventory */
2951                                 if (item >= 0)
2952                                 {
2953                                         inven_item_increase(item, -999);
2954                                         inven_item_describe(item);
2955                                         inven_item_optimize(item);
2956                                 }
2957
2958                                 /* Reduce and describe floor item */
2959                                 else
2960                                 {
2961                                         floor_item_increase(0 - item, -999);
2962                                         floor_item_describe(0 - item);
2963                                         floor_item_optimize(0 - item);
2964                                 }
2965                         }
2966                 }
2967         }
2968
2969         /* Combine / Reorder the pack (later) */
2970         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2971
2972         p_ptr->window |= (PW_INVEN);
2973
2974         /* Something was done */
2975         return (TRUE);
2976 }
2977
2978
2979 /*!
2980  * @brief 武器の祝福処理 /
2981  * Bless a weapon
2982  * @return ターン消費を要する処理を行ったならばTRUEを返す
2983  */
2984 bool bless_weapon(void)
2985 {
2986         OBJECT_IDX item;
2987         object_type     *o_ptr;
2988         BIT_FLAGS flgs[TR_FLAG_SIZE];
2989         char            o_name[MAX_NLEN];
2990         cptr            q, s;
2991
2992         item_tester_no_ryoute = TRUE;
2993
2994         /* Bless only weapons */
2995         item_tester_hook = object_is_weapon;
2996
2997         q = _("どのアイテムを祝福しますか?", "Bless which weapon? ");
2998         s = _("祝福できる武器がありません。", "You have weapon to bless.");
2999
3000         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3001                 return FALSE;
3002
3003         /* Get the item (in the pack) */
3004         if (item >= 0)
3005         {
3006                 o_ptr = &inventory[item];
3007         }
3008
3009         /* Get the item (on the floor) */
3010         else
3011         {
3012                 o_ptr = &o_list[0 - item];
3013         }
3014
3015
3016         /* Description */
3017         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3018
3019         /* Extract the flags */
3020         object_flags(o_ptr, flgs);
3021
3022         if (object_is_cursed(o_ptr))
3023         {
3024                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) ||
3025                         have_flag(flgs, TR_ADD_L_CURSE) ||
3026                         have_flag(flgs, TR_ADD_H_CURSE) ||
3027                     (o_ptr->curse_flags & TRC_PERMA_CURSE))
3028                 {
3029 #ifdef JP
3030 msg_format("%sを覆う黒いオーラは祝福を跳ね返した!",
3031     o_name);
3032 #else
3033                         msg_format("The black aura on %s %s disrupts the blessing!",
3034                             ((item >= 0) ? "your" : "the"), o_name);
3035 #endif
3036
3037                         return TRUE;
3038                 }
3039
3040 #ifdef JP
3041 msg_format("%s から邪悪なオーラが消えた。",
3042     o_name);
3043 #else
3044                 msg_format("A malignant aura leaves %s %s.",
3045                     ((item >= 0) ? "your" : "the"), o_name);
3046 #endif
3047
3048
3049                 /* Uncurse it */
3050                 o_ptr->curse_flags = 0L;
3051
3052                 /* Hack -- Assume felt */
3053                 o_ptr->ident |= (IDENT_SENSE);
3054
3055                 /* Take note */
3056                 o_ptr->feeling = FEEL_NONE;
3057
3058                 /* Recalculate the bonuses */
3059                 p_ptr->update |= (PU_BONUS);
3060
3061                 p_ptr->window |= (PW_EQUIP);
3062         }
3063
3064         /*
3065          * Next, we try to bless it. Artifacts have a 1/3 chance of
3066          * being blessed, otherwise, the operation simply disenchants
3067          * them, godly power negating the magic. Ok, the explanation
3068          * is silly, but otherwise priests would always bless every
3069          * artifact weapon they find. Ego weapons and normal weapons
3070          * can be blessed automatically.
3071          */
3072         if (have_flag(flgs, TR_BLESSED))
3073         {
3074 #ifdef JP
3075 msg_format("%s は既に祝福されている。",
3076     o_name    );
3077 #else
3078                 msg_format("%s %s %s blessed already.",
3079                     ((item >= 0) ? "Your" : "The"), o_name,
3080                     ((o_ptr->number > 1) ? "were" : "was"));
3081 #endif
3082
3083                 return TRUE;
3084         }
3085
3086         if (!(object_is_artifact(o_ptr) || object_is_ego(o_ptr)) || one_in_(3))
3087         {
3088 #ifdef JP
3089                 msg_format("%sは輝いた!", o_name);
3090 #else
3091                 msg_format("%s %s shine%s!",
3092                     ((item >= 0) ? "Your" : "The"), o_name,
3093                     ((o_ptr->number > 1) ? "" : "s"));
3094 #endif
3095
3096                 add_flag(o_ptr->art_flags, TR_BLESSED);
3097                 o_ptr->discount = 99;
3098         }
3099         else
3100         {
3101                 bool dis_happened = FALSE;
3102                 msg_print(_("その武器は祝福を嫌っている!", "The weapon resists your blessing!"));
3103
3104                 /* Disenchant tohit */
3105                 if (o_ptr->to_h > 0)
3106                 {
3107                         o_ptr->to_h--;
3108                         dis_happened = TRUE;
3109                 }
3110
3111                 if ((o_ptr->to_h > 5) && (randint0(100) < 33)) o_ptr->to_h--;
3112
3113                 /* Disenchant todam */
3114                 if (o_ptr->to_d > 0)
3115                 {
3116                         o_ptr->to_d--;
3117                         dis_happened = TRUE;
3118                 }
3119
3120                 if ((o_ptr->to_d > 5) && (randint0(100) < 33)) o_ptr->to_d--;
3121
3122                 /* Disenchant toac */
3123                 if (o_ptr->to_a > 0)
3124                 {
3125                         o_ptr->to_a--;
3126                         dis_happened = TRUE;
3127                 }
3128
3129                 if ((o_ptr->to_a > 5) && (randint0(100) < 33)) o_ptr->to_a--;
3130
3131                 if (dis_happened)
3132                 {
3133                         msg_print(_("周囲が凡庸な雰囲気で満ちた...", "There is a static feeling in the air..."));
3134
3135 #ifdef JP
3136 msg_format("%s は劣化した!",
3137      o_name    );
3138 #else
3139                         msg_format("%s %s %s disenchanted!",
3140                             ((item >= 0) ? "Your" : "The"), o_name,
3141                             ((o_ptr->number > 1) ? "were" : "was"));
3142 #endif
3143
3144                 }
3145         }
3146
3147         /* Recalculate bonuses */
3148         p_ptr->update |= (PU_BONUS);
3149
3150         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
3151
3152         calc_android_exp();
3153
3154         return TRUE;
3155 }
3156
3157
3158 /*!
3159  * @brief 盾磨き処理 /
3160  * pulish shield
3161  * @return ターン消費を要する処理を行ったならばTRUEを返す
3162  */
3163 bool pulish_shield(void)
3164 {
3165         OBJECT_IDX item;
3166         object_type     *o_ptr;
3167         BIT_FLAGS flgs[TR_FLAG_SIZE];
3168         char            o_name[MAX_NLEN];
3169         cptr            q, s;
3170
3171         item_tester_no_ryoute = TRUE;
3172         /* Assume enchant weapon */
3173         item_tester_tval = TV_SHIELD;
3174
3175         q = _("どの盾を磨きますか?", "Pulish which weapon? ");
3176         s = _("磨く盾がありません。", "You have weapon to pulish.");
3177
3178         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3179                 return FALSE;
3180
3181         /* Get the item (in the pack) */
3182         if (item >= 0)
3183         {
3184                 o_ptr = &inventory[item];
3185         }
3186
3187         /* Get the item (on the floor) */
3188         else
3189         {
3190                 o_ptr = &o_list[0 - item];
3191         }
3192
3193
3194         /* Description */
3195         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3196
3197         /* Extract the flags */
3198         object_flags(o_ptr, flgs);
3199
3200         if (o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) &&
3201             !object_is_cursed(o_ptr) && (o_ptr->sval != SV_MIRROR_SHIELD))
3202         {
3203 #ifdef JP
3204 msg_format("%sは輝いた!", o_name);
3205 #else
3206                 msg_format("%s %s shine%s!",
3207                     ((item >= 0) ? "Your" : "The"), o_name,
3208                     ((o_ptr->number > 1) ? "" : "s"));
3209 #endif
3210                 o_ptr->name2 = EGO_REFLECTION;
3211                 enchant(o_ptr, randint0(3) + 4, ENCH_TOAC);
3212
3213                 o_ptr->discount = 99;
3214                 chg_virtue(V_ENCHANT, 2);
3215
3216                 return TRUE;
3217         }
3218         else
3219         {
3220                 if (flush_failure) flush();
3221
3222                 msg_print(_("失敗した。", "Failed."));
3223                 chg_virtue(V_ENCHANT, -2);
3224         }
3225         calc_android_exp();
3226
3227         return FALSE;
3228 }
3229
3230
3231 /*!
3232  * @brief 薬の破損効果処理 /
3233  * Potions "smash open" and cause an area effect when
3234  * @param who 薬破損の主体ID(プレイヤー所持アイテムが壊れた場合0、床上のアイテムの場合モンスターID)
3235  * @param y 破壊時のY座標
3236  * @param x 破壊時のX座標
3237  * @param k_idx 破損した薬のアイテムID
3238  * @return 薬を浴びたモンスターが起こるならばTRUEを返す
3239  * @details
3240  * <pre>
3241  * (1) they are shattered while in the player's inventory,
3242  * due to cold (etc) attacks;
3243  * (2) they are thrown at a monster, or obstacle;
3244  * (3) they are shattered by a "cold ball" or other such spell
3245  * while lying on the floor.
3246  *
3247  * Arguments:
3248  *    who   ---  who caused the potion to shatter (0=player)
3249  *          potions that smash on the floor are assumed to
3250  *          be caused by no-one (who = 1), as are those that
3251  *          shatter inside the player inventory.
3252  *          (Not anymore -- I changed this; TY)
3253  *    y, x  --- coordinates of the potion (or player if
3254  *          the potion was in her inventory);
3255  *    o_ptr --- pointer to the potion object.
3256  * </pre>
3257  */
3258 bool potion_smash_effect(MONSTER_IDX who, POSITION y, POSITION x, KIND_OBJECT_IDX k_idx)
3259 {
3260         int     radius = 2;
3261         int     dt = 0;
3262         int     dam = 0;
3263         bool    angry = FALSE;
3264
3265         object_kind *k_ptr = &k_info[k_idx];
3266
3267         switch (k_ptr->sval)
3268         {
3269                 case SV_POTION_SALT_WATER:
3270                 case SV_POTION_SLIME_MOLD:
3271                 case SV_POTION_LOSE_MEMORIES:
3272                 case SV_POTION_DEC_STR:
3273                 case SV_POTION_DEC_INT:
3274                 case SV_POTION_DEC_WIS:
3275                 case SV_POTION_DEC_DEX:
3276                 case SV_POTION_DEC_CON:
3277                 case SV_POTION_DEC_CHR:
3278                 case SV_POTION_WATER:   /* perhaps a 'water' attack? */
3279                 case SV_POTION_APPLE_JUICE:
3280                         return TRUE;
3281
3282                 case SV_POTION_INFRAVISION:
3283                 case SV_POTION_DETECT_INVIS:
3284                 case SV_POTION_SLOW_POISON:
3285                 case SV_POTION_CURE_POISON:
3286                 case SV_POTION_BOLDNESS:
3287                 case SV_POTION_RESIST_HEAT:
3288                 case SV_POTION_RESIST_COLD:
3289                 case SV_POTION_HEROISM:
3290                 case SV_POTION_BESERK_STRENGTH:
3291                 case SV_POTION_RES_STR:
3292                 case SV_POTION_RES_INT:
3293                 case SV_POTION_RES_WIS:
3294                 case SV_POTION_RES_DEX:
3295                 case SV_POTION_RES_CON:
3296                 case SV_POTION_RES_CHR:
3297                 case SV_POTION_INC_STR:
3298                 case SV_POTION_INC_INT:
3299                 case SV_POTION_INC_WIS:
3300                 case SV_POTION_INC_DEX:
3301                 case SV_POTION_INC_CON:
3302                 case SV_POTION_INC_CHR:
3303                 case SV_POTION_AUGMENTATION:
3304                 case SV_POTION_ENLIGHTENMENT:
3305                 case SV_POTION_STAR_ENLIGHTENMENT:
3306                 case SV_POTION_SELF_KNOWLEDGE:
3307                 case SV_POTION_EXPERIENCE:
3308                 case SV_POTION_RESISTANCE:
3309                 case SV_POTION_INVULNERABILITY:
3310                 case SV_POTION_NEW_LIFE:
3311                         /* All of the above potions have no effect when shattered */
3312                         return FALSE;
3313                 case SV_POTION_SLOWNESS:
3314                         dt = GF_OLD_SLOW;
3315                         dam = 5;
3316                         angry = TRUE;
3317                         break;
3318                 case SV_POTION_POISON:
3319                         dt = GF_POIS;
3320                         dam = 3;
3321                         angry = TRUE;
3322                         break;
3323                 case SV_POTION_BLINDNESS:
3324                         dt = GF_DARK;
3325                         angry = TRUE;
3326                         break;
3327                 case SV_POTION_CONFUSION: /* Booze */
3328                         dt = GF_OLD_CONF;
3329                         angry = TRUE;
3330                         break;
3331                 case SV_POTION_SLEEP:
3332                         dt = GF_OLD_SLEEP;
3333                         angry = TRUE;
3334                         break;
3335                 case SV_POTION_RUINATION:
3336                 case SV_POTION_DETONATIONS:
3337                         dt = GF_SHARDS;
3338                         dam = damroll(25, 25);
3339                         angry = TRUE;
3340                         break;
3341                 case SV_POTION_DEATH:
3342                         dt = GF_DEATH_RAY;    /* !! */
3343                         dam = k_ptr->level * 10;
3344                         angry = TRUE;
3345                         radius = 1;
3346                         break;
3347                 case SV_POTION_SPEED:
3348                         dt = GF_OLD_SPEED;
3349                         break;
3350                 case SV_POTION_CURE_LIGHT:
3351                         dt = GF_OLD_HEAL;
3352                         dam = damroll(2, 3);
3353                         break;
3354                 case SV_POTION_CURE_SERIOUS:
3355                         dt = GF_OLD_HEAL;
3356                         dam = damroll(4, 3);
3357                         break;
3358                 case SV_POTION_CURE_CRITICAL:
3359                 case SV_POTION_CURING:
3360                         dt = GF_OLD_HEAL;
3361                         dam = damroll(6, 3);
3362                         break;
3363                 case SV_POTION_HEALING:
3364                         dt = GF_OLD_HEAL;
3365                         dam = damroll(10, 10);
3366                         break;
3367                 case SV_POTION_RESTORE_EXP:
3368                         dt = GF_STAR_HEAL;
3369                         dam = 0;
3370                         radius = 1;
3371                         break;
3372                 case SV_POTION_LIFE:
3373                         dt = GF_STAR_HEAL;
3374                         dam = damroll(50, 50);
3375                         radius = 1;
3376                         break;
3377                 case SV_POTION_STAR_HEALING:
3378                         dt = GF_OLD_HEAL;
3379                         dam = damroll(50, 50);
3380                         radius = 1;
3381                         break;
3382                 case SV_POTION_RESTORE_MANA:   /* MANA */
3383                         dt = GF_MANA;
3384                         dam = damroll(10, 10);
3385                         radius = 1;
3386                         break;
3387                 default:
3388                         /* Do nothing */  ;
3389         }
3390
3391         (void)project(who, radius, y, x, dam, dt,
3392             (PROJECT_JUMP | PROJECT_ITEM | PROJECT_KILL), -1);
3393
3394         /* XXX  those potions that explode need to become "known" */
3395         return angry;
3396 }
3397
3398
3399 /*!
3400  * @brief プレイヤーの全既知呪文を表示する /
3401  * Hack -- Display all known spells in a window
3402  * return なし
3403  * @details
3404  * Need to analyze size of the window.
3405  * Need more color coding.
3406  */
3407 void display_spell_list(void)
3408 {
3409         int i, j;
3410         TERM_LEN y, x;
3411         int m[9];
3412         const magic_type *s_ptr;
3413         char name[80];
3414         char out_val[160];
3415
3416
3417         /* Erase window */
3418         clear_from(0);
3419
3420         /* They have too many spells to list */
3421         if (p_ptr->pclass == CLASS_SORCERER) return;
3422         if (p_ptr->pclass == CLASS_RED_MAGE) return;
3423
3424         if (p_ptr->pclass == CLASS_SNIPER)
3425         {
3426                 display_snipe_list();
3427                 return;
3428         }
3429
3430         /* mind.c type classes */
3431         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
3432             (p_ptr->pclass == CLASS_BERSERKER) ||
3433             (p_ptr->pclass == CLASS_NINJA) ||
3434             (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
3435             (p_ptr->pclass == CLASS_FORCETRAINER))
3436         {
3437                 int             minfail = 0;
3438                 PLAYER_LEVEL plev = p_ptr->lev;
3439                 int             chance = 0;
3440                 mind_type       spell;
3441                 char            comment[80];
3442                 char            psi_desc[80];
3443                 int             use_mind;
3444                 bool use_hp = FALSE;
3445
3446                 y = 1;
3447                 x = 1;
3448
3449                 /* Display a list of spells */
3450                 prt("", y, x);
3451                 put_str(_("名前", "Name"), y, x + 5);
3452                 put_str(_("Lv   MP 失率 効果", "Lv Mana Fail Info"), y, x + 35);
3453
3454                 switch(p_ptr->pclass)
3455                 {
3456                 case CLASS_MINDCRAFTER: use_mind = MIND_MINDCRAFTER;break;
3457                 case CLASS_FORCETRAINER:          use_mind = MIND_KI;break;
3458                 case CLASS_BERSERKER: use_mind = MIND_BERSERKER; use_hp = TRUE; break;
3459                 case CLASS_MIRROR_MASTER: use_mind = MIND_MIRROR_MASTER; break;
3460                 case CLASS_NINJA: use_mind = MIND_NINJUTSU; use_hp = TRUE; break;
3461                 default:                use_mind = 0;break;
3462                 }
3463
3464                 /* Dump the spells */
3465                 for (i = 0; i < MAX_MIND_POWERS; i++)
3466                 {
3467                         byte a = TERM_WHITE;
3468
3469                         /* Access the available spell */
3470                         spell = mind_powers[use_mind].info[i];
3471                         if (spell.min_lev > plev) break;
3472
3473                         /* Get the failure rate */
3474                         chance = spell.fail;
3475
3476                         /* Reduce failure rate by "effective" level adjustment */
3477                         chance -= 3 * (p_ptr->lev - spell.min_lev);
3478
3479                         /* Reduce failure rate by INT/WIS adjustment */
3480                         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
3481
3482                         if (!use_hp)
3483                         {
3484                                 /* Not enough mana to cast */
3485                                 if (spell.mana_cost > p_ptr->csp)
3486                                 {
3487                                         chance += 5 * (spell.mana_cost - p_ptr->csp);
3488                                         a = TERM_ORANGE;
3489                                 }
3490                         }
3491                         else
3492                         {
3493                                 /* Not enough hp to cast */
3494                                 if (spell.mana_cost > p_ptr->chp)
3495                                 {
3496                                         chance += 100;
3497                                         a = TERM_RED;
3498                                 }
3499                         }
3500
3501                         /* Extract the minimum failure rate */
3502                         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
3503
3504                         /* Minimum failure rate */
3505                         if (chance < minfail) chance = minfail;
3506
3507                         /* Stunning makes spells harder */
3508                         if (p_ptr->stun > 50) chance += 25;
3509                         else if (p_ptr->stun) chance += 15;
3510
3511                         /* Always a 5 percent chance of working */
3512                         if (chance > 95) chance = 95;
3513
3514                         /* Get info */
3515                         mindcraft_info(comment, use_mind, i);
3516
3517                         /* Dump the spell */
3518                         sprintf(psi_desc, "  %c) %-30s%2d %4d %3d%%%s",
3519                             I2A(i), spell.name,
3520                             spell.min_lev, spell.mana_cost, chance, comment);
3521
3522                         Term_putstr(x, y + i + 1, -1, a, psi_desc);
3523                 }
3524                 return;
3525         }
3526
3527         /* Cannot read spellbooks */
3528         if (REALM_NONE == p_ptr->realm1) return;
3529
3530         /* Normal spellcaster with books */
3531
3532         /* Scan books */
3533         for (j = 0; j < ((p_ptr->realm2 > REALM_NONE) ? 2 : 1); j++)
3534         {
3535                 int n = 0;
3536
3537                 /* Reset vertical */
3538                 m[j] = 0;
3539
3540                 /* Vertical location */
3541                 y = (j < 3) ? 0 : (m[j - 3] + 2);
3542
3543                 /* Horizontal location */
3544                 x = 27 * (j % 3);
3545
3546                 /* Scan spells */
3547                 for (i = 0; i < 32; i++)
3548                 {
3549                         byte a = TERM_WHITE;
3550
3551                         /* Access the spell */
3552                         if (!is_magic((j < 1) ? p_ptr->realm1 : p_ptr->realm2))
3553                         {
3554                                 s_ptr = &technic_info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - MIN_TECHNIC][i % 32];
3555                         }
3556                         else
3557                         {
3558                                 s_ptr = &mp_ptr->info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - 1][i % 32];
3559                         }
3560
3561                         strcpy(name, do_spell((j < 1) ? p_ptr->realm1 : p_ptr->realm2, i % 32, SPELL_NAME));
3562
3563                         /* Illegible */
3564                         if (s_ptr->slevel >= 99)
3565                         {
3566                                 /* Illegible */
3567                                 strcpy(name, _("(判読不能)", "(illegible)"));
3568
3569                                 /* Unusable */
3570                                 a = TERM_L_DARK;
3571                         }
3572
3573                         /* Forgotten */
3574                         else if ((j < 1) ?
3575                                 ((p_ptr->spell_forgotten1 & (1L << i))) :
3576                                 ((p_ptr->spell_forgotten2 & (1L << (i % 32)))))
3577                         {
3578                                 /* Forgotten */
3579                                 a = TERM_ORANGE;
3580                         }
3581
3582                         /* Unknown */
3583                         else if (!((j < 1) ?
3584                                 (p_ptr->spell_learned1 & (1L << i)) :
3585                                 (p_ptr->spell_learned2 & (1L << (i % 32)))))
3586                         {
3587                                 /* Unknown */
3588                                 a = TERM_RED;
3589                         }
3590
3591                         /* Untried */
3592                         else if (!((j < 1) ?
3593                                 (p_ptr->spell_worked1 & (1L << i)) :
3594                                 (p_ptr->spell_worked2 & (1L << (i % 32)))))
3595                         {
3596                                 /* Untried */
3597                                 a = TERM_YELLOW;
3598                         }
3599
3600                         /* Dump the spell --(-- */
3601                         sprintf(out_val, "%c/%c) %-20.20s",
3602                                 I2A(n / 8), I2A(n % 8), name);
3603
3604                         /* Track maximum */
3605                         m[j] = y + n;
3606
3607                         /* Dump onto the window */
3608                         Term_putstr(x, m[j], -1, a, out_val);
3609
3610                         /* Next */
3611                         n++;
3612                 }
3613         }
3614 }
3615
3616
3617 /*!
3618  * @brief 呪文の経験値を返す /
3619  * Returns experience of a spell
3620  * @param spell 呪文ID
3621  * @param use_realm 魔法領域
3622  * @return 経験値
3623  */
3624 EXP experience_of_spell(SPELL_IDX spell, REALM_IDX use_realm)
3625 {
3626         if (p_ptr->pclass == CLASS_SORCERER) return SPELL_EXP_MASTER;
3627         else if (p_ptr->pclass == CLASS_RED_MAGE) return SPELL_EXP_SKILLED;
3628         else if (use_realm == p_ptr->realm1) return p_ptr->spell_exp[spell];
3629         else if (use_realm == p_ptr->realm2) return p_ptr->spell_exp[spell + 32];
3630         else return 0;
3631 }
3632
3633
3634 /*!
3635  * @brief 呪文の消費MPを返す /
3636  * Modify mana consumption rate using spell exp and p_ptr->dec_mana
3637  * @param need_mana 基本消費MP
3638  * @param spell 呪文ID
3639  * @param realm 魔法領域
3640  * @return 消費MP
3641  */
3642 MANA_POINT mod_need_mana(MANA_POINT need_mana, SPELL_IDX spell, REALM_IDX realm)
3643 {
3644 #define MANA_CONST   2400
3645 #define MANA_DIV        4
3646 #define DEC_MANA_DIV    3
3647
3648         /* Realm magic */
3649         if ((realm > REALM_NONE) && (realm <= MAX_REALM))
3650         {
3651                 /*
3652                  * need_mana defaults if spell exp equals SPELL_EXP_EXPERT and !p_ptr->dec_mana.
3653                  * MANA_CONST is used to calculate need_mana effected from spell proficiency.
3654                  */
3655                 need_mana = need_mana * (MANA_CONST + SPELL_EXP_EXPERT - experience_of_spell(spell, realm)) + (MANA_CONST - 1);
3656                 need_mana *= p_ptr->dec_mana ? DEC_MANA_DIV : MANA_DIV;
3657                 need_mana /= MANA_CONST * MANA_DIV;
3658                 if (need_mana < 1) need_mana = 1;
3659         }
3660
3661         /* Non-realm magic */
3662         else
3663         {
3664                 if (p_ptr->dec_mana) need_mana = (need_mana + 1) * DEC_MANA_DIV / MANA_DIV;
3665         }
3666
3667 #undef DEC_MANA_DIV
3668 #undef MANA_DIV
3669 #undef MANA_CONST
3670
3671         return need_mana;
3672 }
3673
3674
3675 /*!
3676  * @brief 呪文の失敗率修正処理1(呪い、消費魔力減少、呪文簡易化) /
3677  * Modify spell fail rate
3678  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
3679  * @param chance 修正前失敗率
3680  * @return 失敗率(%)
3681  * @todo 統合を検討
3682  */
3683 PERCENTAGE mod_spell_chance_1(PERCENTAGE chance)
3684 {
3685         chance += p_ptr->to_m_chance;
3686
3687         if (p_ptr->heavy_spell) chance += 20;
3688
3689         if (p_ptr->dec_mana && p_ptr->easy_spell) chance -= 4;
3690         else if (p_ptr->easy_spell) chance -= 3;
3691         else if (p_ptr->dec_mana) chance -= 2;
3692
3693         return chance;
3694 }
3695
3696
3697 /*!
3698  * @brief 呪文の失敗率修正処理2(消費魔力減少、呪い、負値修正) /
3699  * Modify spell fail rate
3700  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
3701  * @param chance 修正前失敗率
3702  * @return 失敗率(%)
3703  * Modify spell fail rate (as "suffix" process)
3704  * Using p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
3705  * Note: variable "chance" cannot be negative.
3706  * @todo 統合を検討
3707  */
3708 PERCENTAGE mod_spell_chance_2(PERCENTAGE chance)
3709 {
3710         if (p_ptr->dec_mana) chance--;
3711
3712         if (p_ptr->heavy_spell) chance += 5;
3713
3714         return MAX(chance, 0);
3715 }
3716
3717
3718 /*!
3719  * @brief 呪文の失敗率計算メインルーチン /
3720  * Returns spell chance of failure for spell -RAK-
3721  * @param spell 呪文ID
3722  * @param use_realm 魔法領域ID
3723  * @return 失敗率(%)
3724  */
3725 PERCENTAGE spell_chance(SPELL_IDX spell, REALM_IDX use_realm)
3726 {
3727         PERCENTAGE chance, minfail;
3728         const magic_type *s_ptr;
3729         MANA_POINT need_mana;
3730         PERCENTAGE penalty = (mp_ptr->spell_stat == A_WIS) ? 10 : 4;
3731
3732
3733         /* Paranoia -- must be literate */
3734         if (!mp_ptr->spell_book) return (100);
3735
3736         if (use_realm == REALM_HISSATSU) return 0;
3737
3738         /* Access the spell */
3739         if (!is_magic(use_realm))
3740         {
3741                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
3742         }
3743         else
3744         {
3745                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
3746         }
3747
3748         /* Extract the base spell failure rate */
3749         chance = s_ptr->sfail;
3750
3751         /* Reduce failure rate by "effective" level adjustment */
3752         chance -= 3 * (p_ptr->lev - s_ptr->slevel);
3753
3754         /* Reduce failure rate by INT/WIS adjustment */
3755         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
3756
3757         if (p_ptr->riding)
3758                 chance += (MAX(r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 100 - 10, 0));
3759
3760         /* Extract mana consumption rate */
3761         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
3762
3763         /* Not enough mana to cast */
3764         if (need_mana > p_ptr->csp)
3765         {
3766                 chance += 5 * (need_mana - p_ptr->csp);
3767         }
3768
3769         if ((use_realm != p_ptr->realm1) && ((p_ptr->pclass == CLASS_MAGE) || (p_ptr->pclass == CLASS_PRIEST))) chance += 5;
3770
3771         /* Extract the minimum failure rate */
3772         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
3773
3774         /*
3775          * Non mage/priest characters never get too good
3776          * (added high mage, mindcrafter)
3777          */
3778         if (mp_ptr->spell_xtra & MAGIC_FAIL_5PERCENT)
3779         {
3780                 if (minfail < 5) minfail = 5;
3781         }
3782
3783         /* Hack -- Priest prayer penalty for "edged" weapons  -DGK */
3784         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[0]) chance += 25;
3785         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[1]) chance += 25;
3786
3787         chance = mod_spell_chance_1(chance);
3788
3789         /* Goodness or evilness gives a penalty to failure rate */
3790         switch (use_realm)
3791         {
3792         case REALM_NATURE:
3793                 if ((p_ptr->align > 50) || (p_ptr->align < -50)) chance += penalty;
3794                 break;
3795         case REALM_LIFE: case REALM_CRUSADE:
3796                 if (p_ptr->align < -20) chance += penalty;
3797                 break;
3798         case REALM_DEATH: case REALM_DAEMON: case REALM_HEX:
3799                 if (p_ptr->align > 20) chance += penalty;
3800                 break;
3801         }
3802
3803         /* Minimum failure rate */
3804         if (chance < minfail) chance = minfail;
3805
3806         /* Stunning makes spells harder */
3807         if (p_ptr->stun > 50) chance += 25;
3808         else if (p_ptr->stun) chance += 15;
3809
3810         /* Always a 5 percent chance of working */
3811         if (chance > 95) chance = 95;
3812
3813         if ((use_realm == p_ptr->realm1) || (use_realm == p_ptr->realm2)
3814             || (p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
3815         {
3816                 EXP exp = experience_of_spell(spell, use_realm);
3817                 if (exp >= SPELL_EXP_EXPERT) chance--;
3818                 if (exp >= SPELL_EXP_MASTER) chance--;
3819         }
3820
3821         /* Return the chance */
3822         return mod_spell_chance_2(chance);
3823 }
3824
3825
3826 /*!
3827  * @brief 魔法が利用可能かどうかを返す /
3828  * Determine if a spell is "okay" for the player to cast or study
3829  * The spell must be legible, not forgotten, and also, to cast,
3830  * it must be known, and to study, it must not be known.
3831  * @param spell 呪文ID
3832  * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
3833  * @param study_pray 祈りの学習判定目的ならばTRUE
3834  * @param use_realm 魔法領域ID
3835  * @return 失敗率(%)
3836  */
3837 bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
3838 {
3839         const magic_type *s_ptr;
3840
3841         /* Access the spell */
3842         if (!is_magic(use_realm))
3843         {
3844                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
3845         }
3846         else
3847         {
3848                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
3849         }
3850
3851         /* Spell is illegal */
3852         if (s_ptr->slevel > p_ptr->lev) return (FALSE);
3853
3854         /* Spell is forgotten */
3855         if ((use_realm == p_ptr->realm2) ?
3856             (p_ptr->spell_forgotten2 & (1L << spell)) :
3857             (p_ptr->spell_forgotten1 & (1L << spell)))
3858         {
3859                 /* Never okay */
3860                 return (FALSE);
3861         }
3862
3863         if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
3864         if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
3865
3866         /* Spell is learned */
3867         if ((use_realm == p_ptr->realm2) ?
3868             (p_ptr->spell_learned2 & (1L << spell)) :
3869             (p_ptr->spell_learned1 & (1L << spell)))
3870         {
3871                 /* Always true */
3872                 return (!study_pray);
3873         }
3874
3875         /* Okay to study, not to cast */
3876         return (!learned);
3877 }
3878
3879
3880
3881 /*!
3882  * @brief 呪文情報の表示処理 /
3883  * Print a list of spells (for browsing or casting or viewing)
3884  * @param target_spell 呪文ID             
3885  * @param spells 表示するスペルID配列の参照ポインタ
3886  * @param num 表示するスペルの数(spellsの要素数)
3887  * @param y 表示メッセージ左上Y座標
3888  * @param x 表示メッセージ左上X座標
3889  * @param use_realm 魔法領域ID
3890  * @return なし
3891  */
3892 void print_spells(SPELL_IDX target_spell, SPELL_IDX *spells, int num, TERM_LEN y, TERM_LEN x, REALM_IDX use_realm)
3893 {
3894         int i;
3895         SPELL_IDX spell;
3896         int  exp_level, increment = 64;
3897         const magic_type *s_ptr;
3898         cptr comment;
3899         char info[80];
3900         char out_val[160];
3901         byte line_attr;
3902         MANA_POINT need_mana;
3903         char ryakuji[5];
3904         char buf[256];
3905         bool max = FALSE;
3906
3907         if (((use_realm <= REALM_NONE) || (use_realm > MAX_REALM)) && p_ptr->wizard)
3908         msg_print(_("警告! print_spell が領域なしに呼ばれた", "Warning! print_spells called with null realm"));
3909
3910         /* Title the list */
3911         prt("", y, x);
3912         if (use_realm == REALM_HISSATSU)
3913                 strcpy(buf,_("  Lv   MP", "  Lv   SP"));
3914         else
3915                 strcpy(buf,_("熟練度 Lv   MP 失率 効果", "Profic Lv   SP Fail Effect"));
3916
3917         put_str(_("名前", "Name"), y, x + 5);
3918         put_str(buf, y, x + 29);
3919
3920         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) increment = 0;
3921         else if (use_realm == p_ptr->realm1) increment = 0;
3922         else if (use_realm == p_ptr->realm2) increment = 32;
3923
3924         /* Dump the spells */
3925         for (i = 0; i < num; i++)
3926         {
3927                 spell = spells[i];
3928
3929                 if (!is_magic(use_realm))
3930                 {
3931                         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
3932                 }
3933                 else
3934                 {
3935                         s_ptr = &mp_ptr->info[use_realm - 1][spell];
3936                 }
3937
3938                 if (use_realm == REALM_HISSATSU)
3939                         need_mana = s_ptr->smana;
3940                 else
3941                 {
3942                         EXP exp = experience_of_spell(spell, use_realm);
3943
3944                         /* Extract mana consumption rate */
3945                         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
3946
3947                         if ((increment == 64) || (s_ptr->slevel >= 99)) exp_level = EXP_LEVEL_UNSKILLED;
3948                         else exp_level = spell_exp_level(exp);
3949
3950                         max = FALSE;
3951                         if (!increment && (exp_level == EXP_LEVEL_MASTER)) max = TRUE;
3952                         else if ((increment == 32) && (exp_level >= EXP_LEVEL_EXPERT)) max = TRUE;
3953                         else if (s_ptr->slevel >= 99) max = TRUE;
3954                         else if ((p_ptr->pclass == CLASS_RED_MAGE) && (exp_level >= EXP_LEVEL_SKILLED)) max = TRUE;
3955
3956                         strncpy(ryakuji, exp_level_str[exp_level], 4);
3957                         ryakuji[3] = ']';
3958                         ryakuji[4] = '\0';
3959                 }
3960
3961                 if (use_menu && target_spell)
3962                 {
3963                         if (i == (target_spell-1))
3964                                 strcpy(out_val, _("  》 ", "  >  "));
3965                         else
3966                                 strcpy(out_val, "     ");
3967                 }
3968                 else sprintf(out_val, "  %c) ", I2A(i));
3969                 /* Skip illegible spells */
3970                 if (s_ptr->slevel >= 99)
3971                 {
3972                         strcat(out_val, format("%-30s", _("(判読不能)", "(illegible)")));
3973                         c_prt(TERM_L_DARK, out_val, y + i + 1, x);
3974                         continue;
3975                 }
3976
3977                 /* XXX XXX Could label spells above the players level */
3978
3979                 /* Get extra info */
3980                 strcpy(info, do_spell(use_realm, spell, SPELL_INFO));
3981
3982                 /* Use that info */
3983                 comment = info;
3984
3985                 /* Assume spell is known and tried */
3986                 line_attr = TERM_WHITE;
3987
3988                 /* Analyze the spell */
3989                 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
3990                 {
3991                         if (s_ptr->slevel > p_ptr->max_plv)
3992                         {
3993                                 comment = _("未知", "unknown");
3994                                 line_attr = TERM_L_BLUE;
3995                         }
3996                         else if (s_ptr->slevel > p_ptr->lev)
3997                         {
3998                                 comment = _("忘却", "forgotten");
3999                                 line_attr = TERM_YELLOW;
4000                         }
4001                 }
4002                 else if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2))
4003                 {
4004                         comment = _("未知", "unknown");
4005                         line_attr = TERM_L_BLUE;
4006                 }
4007                 else if ((use_realm == p_ptr->realm1) ?
4008                     ((p_ptr->spell_forgotten1 & (1L << spell))) :
4009                     ((p_ptr->spell_forgotten2 & (1L << spell))))
4010                 {
4011                         comment = _("忘却", "forgotten");
4012                         line_attr = TERM_YELLOW;
4013                 }
4014                 else if (!((use_realm == p_ptr->realm1) ?
4015                     (p_ptr->spell_learned1 & (1L << spell)) :
4016                     (p_ptr->spell_learned2 & (1L << spell))))
4017                 {
4018                         comment = _("未知", "unknown");
4019                         line_attr = TERM_L_BLUE;
4020                 }
4021                 else if (!((use_realm == p_ptr->realm1) ?
4022                     (p_ptr->spell_worked1 & (1L << spell)) :
4023                     (p_ptr->spell_worked2 & (1L << spell))))
4024                 {
4025                         comment = _("未経験", "untried");
4026                         line_attr = TERM_L_GREEN;
4027                 }
4028
4029                 /* Dump the spell --(-- */
4030                 if (use_realm == REALM_HISSATSU)
4031                 {
4032                         strcat(out_val, format("%-25s %2d %4d",
4033                             do_spell(use_realm, spell, SPELL_NAME), /* realm, spell */
4034                             s_ptr->slevel, need_mana));
4035                 }
4036                 else
4037                 {
4038                         strcat(out_val, format("%-25s%c%-4s %2d %4d %3d%% %s",
4039                             do_spell(use_realm, spell, SPELL_NAME), /* realm, spell */
4040                             (max ? '!' : ' '), ryakuji,
4041                             s_ptr->slevel, need_mana, spell_chance(spell, use_realm), comment));
4042                 }
4043                 c_prt(line_attr, out_val, y + i + 1, x);
4044         }
4045
4046         /* Clear the bottom line */
4047         prt("", y + i + 1, x);
4048 }
4049
4050
4051
4052 /*!
4053  * @brief 防具の錆止め防止処理
4054  * @return ターン消費を要する処理を行ったならばTRUEを返す
4055  */
4056 bool rustproof(void)
4057 {
4058         OBJECT_IDX item;
4059         object_type *o_ptr;
4060         char        o_name[MAX_NLEN];
4061         cptr        q, s;
4062
4063         item_tester_no_ryoute = TRUE;
4064         /* Select a piece of armour */
4065         item_tester_hook = object_is_armour;
4066
4067         q = _("どの防具に錆止めをしますか?", "Rustproof which piece of armour? ");
4068         s = _("錆止めできるものがありません。", "You have nothing to rustproof.");
4069
4070         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return FALSE;
4071
4072         /* Get the item (in the pack) */
4073         if (item >= 0)
4074         {
4075                 o_ptr = &inventory[item];
4076         }
4077
4078         /* Get the item (on the floor) */
4079         else
4080         {
4081                 o_ptr = &o_list[0 - item];
4082         }
4083
4084
4085         /* Description */
4086         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4087
4088         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
4089
4090         if ((o_ptr->to_a < 0) && !object_is_cursed(o_ptr))
4091         {
4092 #ifdef JP
4093                 msg_format("%sは新品同様になった!",o_name);
4094 #else
4095                 msg_format("%s %s look%s as good as new!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
4096 #endif
4097
4098                 o_ptr->to_a = 0;
4099         }
4100
4101 #ifdef JP
4102         msg_format("%sは腐食しなくなった。", o_name);
4103 #else
4104         msg_format("%s %s %s now protected against corrosion.", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "are" : "is"));
4105 #endif
4106
4107         calc_android_exp();
4108         return TRUE;
4109 }
4110
4111
4112 /*!
4113  * @brief 防具呪縛処理 /
4114  * Curse the players armor
4115  * @return 実際に呪縛されたらTRUEを返す
4116  */
4117 bool curse_armor(void)
4118 {
4119         int i;
4120         object_type *o_ptr;
4121
4122         char o_name[MAX_NLEN];
4123
4124
4125         /* Curse the body armor */
4126         o_ptr = &inventory[INVEN_BODY];
4127
4128         /* Nothing to curse */
4129         if (!o_ptr->k_idx) return (FALSE);
4130
4131         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
4132
4133         /* Attempt a saving throw for artifacts */
4134         if (object_is_artifact(o_ptr) && (randint0(100) < 50))
4135         {
4136                 /* Cool */
4137 #ifdef JP
4138 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!",
4139 "恐怖の暗黒オーラ", "防具", o_name);
4140 #else
4141                 msg_format("A %s tries to %s, but your %s resists the effects!",
4142                            "terrible black aura", "surround your armor", o_name);
4143 #endif
4144
4145         }
4146
4147         /* not artifact or failed save... */
4148         else
4149         {
4150                 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
4151                 chg_virtue(V_ENCHANT, -5);
4152
4153                 /* Blast the armor */
4154                 o_ptr->name1 = 0;
4155                 o_ptr->name2 = EGO_BLASTED;
4156                 o_ptr->to_a = 0 - randint1(5) - randint1(5);
4157                 o_ptr->to_h = 0;
4158                 o_ptr->to_d = 0;
4159                 o_ptr->ac = 0;
4160                 o_ptr->dd = 0;
4161                 o_ptr->ds = 0;
4162
4163                 for (i = 0; i < TR_FLAG_SIZE; i++)
4164                         o_ptr->art_flags[i] = 0;
4165
4166                 /* Curse it */
4167                 o_ptr->curse_flags = TRC_CURSED;
4168
4169                 /* Break it */
4170                 o_ptr->ident |= (IDENT_BROKEN);
4171
4172                 /* Recalculate bonuses */
4173                 p_ptr->update |= (PU_BONUS);
4174
4175                 /* Recalculate mana */
4176                 p_ptr->update |= (PU_MANA);
4177
4178                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
4179         }
4180
4181         return (TRUE);
4182 }
4183
4184 /*!
4185  * @brief 武器呪縛処理 /
4186  * Curse the players weapon
4187  * @param force 無条件に呪縛を行うならばTRUE
4188  * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
4189  * @return 実際に呪縛されたらTRUEを返す
4190  */
4191 bool curse_weapon_object(bool force, object_type *o_ptr)
4192 {
4193         int i;
4194         char o_name[MAX_NLEN];
4195
4196         /* Nothing to curse */
4197         if (!o_ptr->k_idx) return (FALSE);
4198         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
4199
4200         /* Attempt a saving throw */
4201         if (object_is_artifact(o_ptr) && (randint0(100) < 50) && !force)
4202         {
4203                 /* Cool */
4204 #ifdef JP
4205                 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!",
4206                                 "恐怖の暗黒オーラ", "武器", o_name);
4207 #else
4208                 msg_format("A %s tries to %s, but your %s resists the effects!",
4209                                 "terrible black aura", "surround your weapon", o_name);
4210 #endif
4211         }
4212
4213         /* not artifact or failed save... */
4214         else
4215         {
4216                 if (!force) msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
4217                 chg_virtue(V_ENCHANT, -5);
4218
4219                 /* Shatter the weapon */
4220                 o_ptr->name1 = 0;
4221                 o_ptr->name2 = EGO_SHATTERED;
4222                 o_ptr->to_h = 0 - randint1(5) - randint1(5);
4223                 o_ptr->to_d = 0 - randint1(5) - randint1(5);
4224                 o_ptr->to_a = 0;
4225                 o_ptr->ac = 0;
4226                 o_ptr->dd = 0;
4227                 o_ptr->ds = 0;
4228
4229                 for (i = 0; i < TR_FLAG_SIZE; i++)
4230                         o_ptr->art_flags[i] = 0;
4231
4232                 /* Curse it */
4233                 o_ptr->curse_flags = TRC_CURSED;
4234
4235                 /* Break it */
4236                 o_ptr->ident |= (IDENT_BROKEN);
4237
4238                 /* Recalculate bonuses */
4239                 p_ptr->update |= (PU_BONUS);
4240
4241                 /* Recalculate mana */
4242                 p_ptr->update |= (PU_MANA);
4243
4244                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
4245         }
4246
4247         return (TRUE);
4248 }
4249
4250 /*!
4251  * @brief 武器呪縛処理のメインルーチン /
4252  * Curse the players weapon
4253  * @param force 無条件に呪縛を行うならばTRUE
4254  * @param slot 呪縛する武器の装備スロット
4255  * @return 実際に呪縛されたらTRUEを返す
4256  */
4257 bool curse_weapon(bool force, int slot)
4258 {
4259         /* Curse the weapon */
4260         return curse_weapon_object(force, &inventory[slot]);
4261 }
4262
4263
4264 /*!
4265  * @brief ボルトのエゴ化処理(火炎エゴのみ) /
4266  * Enchant some bolts
4267  * @return 常にTRUEを返す
4268  */
4269 bool brand_bolts(void)
4270 {
4271         int i;
4272
4273         /* Use the first acceptable bolts */
4274         for (i = 0; i < INVEN_PACK; i++)
4275         {
4276                 object_type *o_ptr = &inventory[i];
4277
4278                 /* Skip non-bolts */
4279                 if (o_ptr->tval != TV_BOLT) continue;
4280
4281                 /* Skip artifacts and ego-items */
4282                 if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
4283                         continue;
4284
4285                 /* Skip cursed/broken items */
4286                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) continue;
4287
4288                 /* Randomize */
4289                 if (randint0(100) < 75) continue;
4290
4291                 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
4292
4293                 /* Ego-item */
4294                 o_ptr->name2 = EGO_FLAME;
4295                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
4296                 return (TRUE);
4297         }
4298
4299         if (flush_failure) flush();
4300
4301         /* Fail */
4302         msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
4303
4304         return (TRUE);
4305 }
4306
4307
4308 /*!
4309  * @brief 変身処理向けにモンスターの近隣レベル帯モンスターを返す /
4310  * Helper function -- return a "nearby" race for polymorphing
4311  * @param r_idx 基準となるモンスター種族ID
4312  * @return 変更先のモンスター種族ID
4313  * @details
4314  * Note that this function is one of the more "dangerous" ones...
4315  */
4316 static IDX poly_r_idx(MONRACE_IDX r_idx)
4317 {
4318         monster_race *r_ptr = &r_info[r_idx];
4319
4320         int i;
4321         MONRACE_IDX r;
4322         DEPTH lev1, lev2;
4323
4324         /* Hack -- Uniques/Questors never polymorph */
4325         if ((r_ptr->flags1 & RF1_UNIQUE) ||
4326             (r_ptr->flags1 & RF1_QUESTOR))
4327                 return (r_idx);
4328
4329         /* Allowable range of "levels" for resulting monster */
4330         lev1 = r_ptr->level - ((randint1(20) / randint1(9)) + 1);
4331         lev2 = r_ptr->level + ((randint1(20) / randint1(9)) + 1);
4332
4333         /* Pick a (possibly new) non-unique race */
4334         for (i = 0; i < 1000; i++)
4335         {
4336                 /* Pick a new race, using a level calculation */
4337                 r = get_mon_num((dun_level + r_ptr->level) / 2 + 5);
4338
4339                 /* Handle failure */
4340                 if (!r) break;
4341
4342                 /* Obtain race */
4343                 r_ptr = &r_info[r];
4344
4345                 /* Ignore unique monsters */
4346                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
4347
4348                 /* Ignore monsters with incompatible levels */
4349                 if ((r_ptr->level < lev1) || (r_ptr->level > lev2)) continue;
4350
4351                 /* Use that index */
4352                 r_idx = r;
4353
4354                 break;
4355         }
4356         return (r_idx);
4357 }
4358
4359 /*!
4360  * @brief 指定座標にいるモンスターを変身させる /
4361  * Helper function -- return a "nearby" race for polymorphing
4362  * @param y 指定のY座標
4363  * @param x 指定のX座標
4364  * @return 実際に変身したらTRUEを返す
4365  */
4366 bool polymorph_monster(POSITION y, POSITION x)
4367 {
4368         cave_type *c_ptr = &cave[y][x];
4369         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4370         bool polymorphed = FALSE;
4371         MONRACE_IDX new_r_idx;
4372         MONRACE_IDX old_r_idx = m_ptr->r_idx;
4373         bool targeted = (target_who == c_ptr->m_idx) ? TRUE : FALSE;
4374         bool health_tracked = (p_ptr->health_who == c_ptr->m_idx) ? TRUE : FALSE;
4375         monster_type back_m;
4376
4377         if (p_ptr->inside_arena || p_ptr->inside_battle) return (FALSE);
4378
4379         if ((p_ptr->riding == c_ptr->m_idx) || (m_ptr->mflag2 & MFLAG2_KAGE)) return (FALSE);
4380
4381         /* Memorize the monster before polymorphing */
4382         back_m = *m_ptr;
4383
4384         /* Pick a "new" monster race */
4385         new_r_idx = poly_r_idx(old_r_idx);
4386
4387         /* Handle polymorph */
4388         if (new_r_idx != old_r_idx)
4389         {
4390                 BIT_FLAGS mode = 0L;
4391                 bool preserve_hold_objects = back_m.hold_o_idx ? TRUE : FALSE;
4392                 OBJECT_IDX this_o_idx, next_o_idx = 0;
4393
4394                 /* Get the monsters attitude */
4395                 if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
4396                 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
4397                 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4398
4399                 /* Mega-hack -- ignore held objects */
4400                 m_ptr->hold_o_idx = 0;
4401
4402                 /* "Kill" the "old" monster */
4403                 delete_monster_idx(c_ptr->m_idx);
4404
4405                 /* Create a new monster (no groups) */
4406                 if (place_monster_aux(0, y, x, new_r_idx, mode))
4407                 {
4408                         m_list[hack_m_idx_ii].nickname = back_m.nickname;
4409                         m_list[hack_m_idx_ii].parent_m_idx = back_m.parent_m_idx;
4410                         m_list[hack_m_idx_ii].hold_o_idx = back_m.hold_o_idx;
4411
4412                         /* Success */
4413                         polymorphed = TRUE;
4414                 }
4415                 else
4416                 {
4417                         /* Placing the new monster failed */
4418                         if (place_monster_aux(0, y, x, old_r_idx, (mode | PM_NO_KAGE | PM_IGNORE_TERRAIN)))
4419                         {
4420                                 m_list[hack_m_idx_ii] = back_m;
4421
4422                                 /* Re-initialize monster process */
4423                                 mproc_init();
4424                         }
4425                         else preserve_hold_objects = FALSE;
4426                 }
4427
4428                 /* Mega-hack -- preserve held objects */
4429                 if (preserve_hold_objects)
4430                 {
4431                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4432                         {
4433                                 /* Acquire object */
4434                                 object_type *o_ptr = &o_list[this_o_idx];
4435
4436                                 /* Acquire next object */
4437                                 next_o_idx = o_ptr->next_o_idx;
4438
4439                                 /* Held by new monster */
4440                                 o_ptr->held_m_idx = hack_m_idx_ii;
4441                         }
4442                 }
4443                 else if (back_m.hold_o_idx) /* Failed (paranoia) */
4444                 {
4445                         /* Delete objects */
4446                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4447                         {
4448                                 /* Acquire next object */
4449                                 next_o_idx = o_list[this_o_idx].next_o_idx;
4450
4451                                 delete_object_idx(this_o_idx);
4452                         }
4453                 }
4454
4455                 if (targeted) target_who = hack_m_idx_ii;
4456                 if (health_tracked) health_track(hack_m_idx_ii);
4457         }
4458
4459         return polymorphed;
4460 }
4461
4462 /*!
4463  * @brief 次元の扉処理 /
4464  * Dimension Door
4465  * @param x テレポート先のX座標
4466  * @param y テレポート先のY座標
4467  * @return 目標に指定通りテレポートできたならばTRUEを返す
4468  */
4469 static bool dimension_door_aux(DEPTH x, DEPTH y)
4470 {
4471         PLAYER_LEVEL plev = p_ptr->lev;
4472
4473         p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
4474
4475         if (!cave_player_teleportable_bold(y, x, 0L) ||
4476             (distance(y, x, p_ptr->y, p_ptr->x) > plev / 2 + 10) ||
4477             (!randint0(plev / 10 + 10)))
4478         {
4479                 p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
4480                 teleport_player((plev + 2) * 2, TELEPORT_PASSIVE);
4481
4482                 /* Failed */
4483                 return FALSE;
4484         }
4485         else
4486         {
4487                 teleport_player_to(y, x, 0L);
4488
4489                 /* Success */
4490                 return TRUE;
4491         }
4492 }
4493
4494
4495 /*!
4496  * @brief 次元の扉処理のメインルーチン /
4497  * Dimension Door
4498  * @return ターンを消費した場合TRUEを返す
4499  */
4500 bool dimension_door(void)
4501 {
4502         DEPTH x = 0, y = 0;
4503
4504         /* Rerutn FALSE if cancelled */
4505         if (!tgt_pt(&x, &y)) return FALSE;
4506
4507         if (dimension_door_aux(x, y)) return TRUE;
4508
4509         msg_print(_("精霊界から物質界に戻る時うまくいかなかった!", "You fail to exit the astral plane correctly!"));
4510
4511         return TRUE;
4512 }
4513
4514
4515 /*!
4516  * @brief 鏡抜け処理のメインルーチン /
4517  * Mirror Master's Dimension Door
4518  * @return ターンを消費した場合TRUEを返す
4519  */
4520 bool mirror_tunnel(void)
4521 {
4522         POSITION x = 0, y = 0;
4523
4524         /* Rerutn FALSE if cancelled */
4525         if (!tgt_pt(&x, &y)) return FALSE;
4526
4527         if (dimension_door_aux(x, y)) return TRUE;
4528
4529         msg_print(_("鏡の世界をうまく通れなかった!", "You fail to pass the mirror plane correctly!"));
4530
4531         return TRUE;
4532 }
4533
4534 /*!
4535  * @brief 魔力食い処理
4536  * @param power 基本効力
4537  * @return ターンを消費した場合TRUEを返す
4538  */
4539 bool eat_magic(int power)
4540 {
4541         object_type *o_ptr;
4542         object_kind *k_ptr;
4543         DEPTH lev;
4544         OBJECT_IDX item;
4545         int recharge_strength = 0;
4546
4547         bool fail = FALSE;
4548         byte fail_type = 1;
4549
4550         cptr q, s;
4551         char o_name[MAX_NLEN];
4552
4553         item_tester_hook = item_tester_hook_recharge;
4554
4555         q = _("どのアイテムから魔力を吸収しますか?", "Drain which item? ");
4556         s = _("魔力を吸収できるアイテムがありません。", "You have nothing to drain.");
4557
4558         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return FALSE;
4559
4560         if (item >= 0)
4561         {
4562                 o_ptr = &inventory[item];
4563         }
4564         else
4565         {
4566                 o_ptr = &o_list[0 - item];
4567         }
4568
4569         k_ptr = &k_info[o_ptr->k_idx];
4570         lev = k_info[o_ptr->k_idx].level;
4571
4572         if (o_ptr->tval == TV_ROD)
4573         {
4574                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
4575
4576                 /* Back-fire */
4577                 if (one_in_(recharge_strength))
4578                 {
4579                         /* Activate the failure code. */
4580                         fail = TRUE;
4581                 }
4582                 else
4583                 {
4584                         if (o_ptr->timeout > (o_ptr->number - 1) * k_ptr->pval)
4585                         {
4586                                 msg_print(_("充填中のロッドから魔力を吸収することはできません。", "You can't absorb energy from a discharged rod."));
4587                         }
4588                         else
4589                         {
4590                                 p_ptr->csp += lev;
4591                                 o_ptr->timeout += k_ptr->pval;
4592                         }
4593                 }
4594         }
4595         else
4596         {
4597                 /* All staffs, wands. */
4598                 recharge_strength = (100 + power - lev) / 15;
4599
4600                 /* Paranoia */
4601                 if (recharge_strength < 0) recharge_strength = 0;
4602
4603                 /* Back-fire */
4604                 if (one_in_(recharge_strength))
4605                 {
4606                         /* Activate the failure code. */
4607                         fail = TRUE;
4608                 }
4609                 else
4610                 {
4611                         if (o_ptr->pval > 0)
4612                         {
4613                                 p_ptr->csp += lev / 2;
4614                                 o_ptr->pval --;
4615
4616                                 /* XXX Hack -- unstack if necessary */
4617                                 if ((o_ptr->tval == TV_STAFF) && (item >= 0) && (o_ptr->number > 1))
4618                                 {
4619                                         object_type forge;
4620                                         object_type *q_ptr;
4621
4622                                         /* Get local object */
4623                                         q_ptr = &forge;
4624
4625                                         /* Obtain a local object */
4626                                         object_copy(q_ptr, o_ptr);
4627
4628                                         /* Modify quantity */
4629                                         q_ptr->number = 1;
4630
4631                                         /* Restore the charges */
4632                                         o_ptr->pval++;
4633
4634                                         /* Unstack the used item */
4635                                         o_ptr->number--;
4636                                         p_ptr->total_weight -= q_ptr->weight;
4637                                         item = inven_carry(q_ptr);
4638
4639                                         msg_print(_("杖をまとめなおした。", "You unstack your staff."));
4640                                 }
4641                         }
4642                         else
4643                         {
4644                                 msg_print(_("吸収できる魔力がありません!", "There's no energy there to absorb!"));
4645                         }
4646                         if (!o_ptr->pval) o_ptr->ident |= IDENT_EMPTY;
4647                 }
4648         }
4649
4650         /* Inflict the penalties for failing a recharge. */
4651         if (fail)
4652         {
4653                 /* Artifacts are never destroyed. */
4654                 if (object_is_fixed_artifact(o_ptr))
4655                 {
4656                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
4657                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
4658
4659                         /* Artifact rods. */
4660                         if (o_ptr->tval == TV_ROD)
4661                                 o_ptr->timeout = k_ptr->pval * o_ptr->number;
4662
4663                         /* Artifact wands and staffs. */
4664                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
4665                                 o_ptr->pval = 0;
4666                 }
4667                 else
4668                 {
4669                         /* Get the object description */
4670                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4671
4672                         /*** Determine Seriousness of Failure ***/
4673
4674                         /* Mages recharge objects more safely. */
4675                         if (IS_WIZARD_CLASS())
4676                         {
4677                                 /* 10% chance to blow up one rod, otherwise draining. */
4678                                 if (o_ptr->tval == TV_ROD)
4679                                 {
4680                                         if (one_in_(10)) fail_type = 2;
4681                                         else fail_type = 1;
4682                                 }
4683                                 /* 75% chance to blow up one wand, otherwise draining. */
4684                                 else if (o_ptr->tval == TV_WAND)
4685                                 {
4686                                         if (!one_in_(3)) fail_type = 2;
4687                                         else fail_type = 1;
4688                                 }
4689                                 /* 50% chance to blow up one staff, otherwise no effect. */
4690                                 else if (o_ptr->tval == TV_STAFF)
4691                                 {
4692                                         if (one_in_(2)) fail_type = 2;
4693                                         else fail_type = 0;
4694                                 }
4695                         }
4696
4697                         /* All other classes get no special favors. */
4698                         else
4699                         {
4700                                 /* 33% chance to blow up one rod, otherwise draining. */
4701                                 if (o_ptr->tval == TV_ROD)
4702                                 {
4703                                         if (one_in_(3)) fail_type = 2;
4704                                         else fail_type = 1;
4705                                 }
4706                                 /* 20% chance of the entire stack, else destroy one wand. */
4707                                 else if (o_ptr->tval == TV_WAND)
4708                                 {
4709                                         if (one_in_(5)) fail_type = 3;
4710                                         else fail_type = 2;
4711                                 }
4712                                 /* Blow up one staff. */
4713                                 else if (o_ptr->tval == TV_STAFF)
4714                                 {
4715                                         fail_type = 2;
4716                                 }
4717                         }
4718
4719                         /*** Apply draining and destruction. ***/
4720
4721                         /* Drain object or stack of objects. */
4722                         if (fail_type == 1)
4723                         {
4724                                 if (o_ptr->tval == TV_ROD)
4725                                 {
4726                                         msg_format(_("ロッドは破損を免れたが、魔力は全て失なわれた。",
4727                                                                  "You save your rod from destruction, but all charges are lost."), o_name);
4728                                         o_ptr->timeout = k_ptr->pval * o_ptr->number;
4729                                 }
4730                                 else if (o_ptr->tval == TV_WAND)
4731                                 {
4732                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
4733                                         o_ptr->pval = 0;
4734                                 }
4735                                 /* Staffs aren't drained. */
4736                         }
4737
4738                         /* Destroy an object or one in a stack of objects. */
4739                         if (fail_type == 2)
4740                         {
4741                                 if (o_ptr->number > 1)
4742                                 {
4743                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
4744                                         /* Reduce rod stack maximum timeout, drain wands. */
4745                                         if (o_ptr->tval == TV_ROD) o_ptr->timeout = MIN(o_ptr->timeout, k_ptr->pval * (o_ptr->number - 1));
4746                                         else if (o_ptr->tval == TV_WAND) o_ptr->pval = o_ptr->pval * (o_ptr->number - 1) / o_ptr->number;
4747                                 }
4748                                 else
4749                                 {
4750                                         msg_format(_("乱暴な魔法のために%sが何本か壊れた!", "Wild magic consumes your %s!"), o_name);
4751                                 }
4752                                 
4753                                 /* Reduce and describe inventory */
4754                                 if (item >= 0)
4755                                 {
4756                                         inven_item_increase(item, -1);
4757                                         inven_item_describe(item);
4758                                         inven_item_optimize(item);
4759                                 }
4760
4761                                 /* Reduce and describe floor item */
4762                                 else
4763                                 {
4764                                         floor_item_increase(0 - item, -1);
4765                                         floor_item_describe(0 - item);
4766                                         floor_item_optimize(0 - item);
4767                                 }
4768                         }
4769
4770                         /* Destroy all members of a stack of objects. */
4771                         if (fail_type == 3)
4772                         {
4773                                 if (o_ptr->number > 1)
4774                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
4775                                 else
4776                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
4777
4778                                 /* Reduce and describe inventory */
4779                                 if (item >= 0)
4780                                 {
4781                                         inven_item_increase(item, -999);
4782                                         inven_item_describe(item);
4783                                         inven_item_optimize(item);
4784                                 }
4785
4786                                 /* Reduce and describe floor item */
4787                                 else
4788                                 {
4789                                         floor_item_increase(0 - item, -999);
4790                                         floor_item_describe(0 - item);
4791                                         floor_item_optimize(0 - item);
4792                                 }
4793                         }
4794                 }
4795         }
4796
4797         if (p_ptr->csp > p_ptr->msp)
4798         {
4799                 p_ptr->csp = p_ptr->msp;
4800         }
4801
4802         /* Redraw mana and hp */
4803         p_ptr->redraw |= (PR_MANA);
4804
4805         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
4806         p_ptr->window |= (PW_INVEN);
4807
4808         return TRUE;
4809 }
4810
4811 /*!
4812  * @brief 同族召喚(援軍)処理
4813  * @param level 召喚基準レベル
4814  * @param y 召喚先Y座標
4815  * @param x 召喚先X座標
4816  * @param mode 召喚オプション
4817  * @return ターンを消費した場合TRUEを返す
4818  */
4819 bool summon_kin_player(DEPTH level, POSITION y, POSITION x, BIT_FLAGS mode)
4820 {
4821         bool pet = (bool)(mode & PM_FORCE_PET);
4822         if (!pet) mode |= PM_NO_PET;
4823
4824         switch (p_ptr->mimic_form)
4825         {
4826         case MIMIC_NONE:
4827                 switch (p_ptr->prace)
4828                 {
4829                         case RACE_HUMAN:
4830                         case RACE_AMBERITE:
4831                         case RACE_BARBARIAN:
4832                         case RACE_BEASTMAN:
4833                         case RACE_DUNADAN:
4834                                 summon_kin_type = 'p';
4835                                 break;
4836                         case RACE_HALF_ELF:
4837                         case RACE_ELF:
4838                         case RACE_HOBBIT:
4839                         case RACE_GNOME:
4840                         case RACE_DWARF:
4841                         case RACE_HIGH_ELF:
4842                         case RACE_NIBELUNG:
4843                         case RACE_DARK_ELF:
4844                         case RACE_MIND_FLAYER:
4845                         case RACE_KUTAR:
4846                         case RACE_S_FAIRY:
4847                                 summon_kin_type = 'h';
4848                                 break;
4849                         case RACE_HALF_ORC:
4850                                 summon_kin_type = 'o';
4851                                 break;
4852                         case RACE_HALF_TROLL:
4853                                 summon_kin_type = 'T';
4854                                 break;
4855                         case RACE_HALF_OGRE:
4856                                 summon_kin_type = 'O';
4857                                 break;
4858                         case RACE_HALF_GIANT:
4859                         case RACE_HALF_TITAN:
4860                         case RACE_CYCLOPS:
4861                                 summon_kin_type = 'P';
4862                                 break;
4863                         case RACE_YEEK:
4864                                 summon_kin_type = 'y';
4865                                 break;
4866                         case RACE_KLACKON:
4867                                 summon_kin_type = 'K';
4868                                 break;
4869                         case RACE_KOBOLD:
4870                                 summon_kin_type = 'k';
4871                                 break;
4872                         case RACE_IMP:
4873                                 if (one_in_(13)) summon_kin_type = 'U';
4874                                 else summon_kin_type = 'u';
4875                                 break;
4876                         case RACE_DRACONIAN:
4877                                 summon_kin_type = 'd';
4878                                 break;
4879                         case RACE_GOLEM:
4880                         case RACE_ANDROID:
4881                                 summon_kin_type = 'g';
4882                                 break;
4883                         case RACE_SKELETON:
4884                                 if (one_in_(13)) summon_kin_type = 'L';
4885                                 else summon_kin_type = 's';
4886                                 break;
4887                         case RACE_ZOMBIE:
4888                                 summon_kin_type = 'z';
4889                                 break;
4890                         case RACE_VAMPIRE:
4891                                 summon_kin_type = 'V';
4892                                 break;
4893                         case RACE_SPECTRE:
4894                                 summon_kin_type = 'G';
4895                                 break;
4896                         case RACE_SPRITE:
4897                                 summon_kin_type = 'I';
4898                                 break;
4899                         case RACE_ENT:
4900                                 summon_kin_type = '#';
4901                                 break;
4902                         case RACE_ANGEL:
4903                                 summon_kin_type = 'A';
4904                                 break;
4905                         case RACE_DEMON:
4906                                 summon_kin_type = 'U';
4907                                 break;
4908                         default:
4909                                 summon_kin_type = 'p';
4910                                 break;
4911                 }
4912                 break;
4913         case MIMIC_DEMON:
4914                 if (one_in_(13)) summon_kin_type = 'U';
4915                 else summon_kin_type = 'u';
4916                 break;
4917         case MIMIC_DEMON_LORD:
4918                 summon_kin_type = 'U';
4919                 break;
4920         case MIMIC_VAMPIRE:
4921                 summon_kin_type = 'V';
4922                 break;
4923         }       
4924         return summon_specific((pet ? -1 : 0), y, x, level, SUMMON_KIN, mode);
4925 }
4926
4927 /*!
4928  * @brief 皆殺し(全方向攻撃)処理
4929  * @param py プレイヤーY座標
4930  * @param px プレイヤーX座標
4931  * @return なし
4932  */
4933 void massacre(void)
4934 {
4935         POSITION x, y;
4936         cave_type       *c_ptr;
4937         monster_type    *m_ptr;
4938         DIRECTION dir;
4939
4940         for (dir = 0; dir < 8; dir++)
4941         {
4942                 y = p_ptr->y + ddy_ddd[dir];
4943                 x = p_ptr->x + ddx_ddd[dir];
4944                 c_ptr = &cave[y][x];
4945
4946                 /* Get the monster */
4947                 m_ptr = &m_list[c_ptr->m_idx];
4948
4949                 /* Hack -- attack monsters */
4950                 if (c_ptr->m_idx && (m_ptr->ml || cave_have_flag_bold(y, x, FF_PROJECT)))
4951                         py_attack(y, x, 0);
4952         }
4953 }
4954
4955 bool eat_lock(void)
4956 {
4957         POSITION x, y;
4958         cave_type *c_ptr;
4959         feature_type *f_ptr, *mimic_f_ptr;
4960         DIRECTION dir;
4961
4962         if (!get_direction(&dir, FALSE, FALSE)) return FALSE;
4963         y = p_ptr->y + ddy[dir];
4964         x = p_ptr->x + ddx[dir];
4965         c_ptr = &cave[y][x];
4966         f_ptr = &f_info[c_ptr->feat];
4967         mimic_f_ptr = &f_info[get_feat_mimic(c_ptr)];
4968
4969         stop_mouth();
4970
4971         if (!have_flag(mimic_f_ptr->flags, FF_HURT_ROCK))
4972         {
4973                 msg_print(_("この地形は食べられない。", "You cannot eat this feature."));
4974         }
4975         else if (have_flag(f_ptr->flags, FF_PERMANENT))
4976         {
4977                 msg_format(_("いてっ!この%sはあなたの歯より硬い!", "Ouch!  This %s is harder than your teeth!"), f_name + mimic_f_ptr->name);
4978         }
4979         else if (c_ptr->m_idx)
4980         {
4981                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
4982                 msg_print(_("何かが邪魔しています!", "There's something in the way!"));
4983
4984                 if (!m_ptr->ml || !is_pet(m_ptr)) py_attack(y, x, 0);
4985         }
4986         else if (have_flag(f_ptr->flags, FF_TREE))
4987         {
4988                 msg_print(_("木の味は好きじゃない!", "You don't like the woody taste!"));
4989         }
4990         else if (have_flag(f_ptr->flags, FF_GLASS))
4991         {
4992                 msg_print(_("ガラスの味は好きじゃない!", "You don't like the glassy taste!"));
4993         }
4994         else if (have_flag(f_ptr->flags, FF_DOOR) || have_flag(f_ptr->flags, FF_CAN_DIG))
4995         {
4996                 (void)set_food(p_ptr->food + 3000);
4997         }
4998         else if (have_flag(f_ptr->flags, FF_MAY_HAVE_GOLD) || have_flag(f_ptr->flags, FF_HAS_GOLD))
4999         {
5000                 (void)set_food(p_ptr->food + 5000);
5001         }
5002         else
5003         {
5004                 msg_format(_("この%sはとてもおいしい!", "This %s is very filling!"), f_name + mimic_f_ptr->name);
5005                 (void)set_food(p_ptr->food + 10000);
5006         }
5007
5008         /* Destroy the wall */
5009         cave_alter_feat(y, x, FF_HURT_ROCK);
5010
5011         /* Move the player */
5012         (void)move_player_effect(y, x, MPE_DONT_PICKUP);
5013         return TRUE;
5014 }
5015
5016
5017 bool shock_power(void)
5018 {
5019         DIRECTION dir;
5020         POSITION y, x;
5021         HIT_POINT dam;
5022         PLAYER_LEVEL plev = p_ptr->lev;
5023         int boost = P_PTR_KI;
5024         if (heavy_armor()) boost /= 2;
5025
5026         project_length = 1;
5027         if (!get_aim_dir(&dir)) return FALSE;
5028
5029         y = p_ptr->y + ddy[dir];
5030         x = p_ptr->x + ddx[dir];
5031         dam = damroll(8 + ((plev - 5) / 4) + boost / 12, 8);
5032         fire_beam(GF_MISSILE, dir, dam);
5033         if (cave[y][x].m_idx)
5034         {
5035                 int i;
5036                 int ty = y, tx = x;
5037                 int oy = y, ox = x;
5038                 MONSTER_IDX m_idx = cave[y][x].m_idx;
5039                 monster_type *m_ptr = &m_list[m_idx];
5040                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
5041                 char m_name[80];
5042
5043                 monster_desc(m_name, m_ptr, 0);
5044
5045                 if (randint1(r_ptr->level * 3 / 2) > randint0(dam / 2) + dam / 2)
5046                 {
5047                         msg_format(_("%sは飛ばされなかった。", "%^s was not blown away."), m_name);
5048                 }
5049                 else
5050                 {
5051                         for (i = 0; i < 5; i++)
5052                         {
5053                                 y += ddy[dir];
5054                                 x += ddx[dir];
5055                                 if (cave_empty_bold(y, x))
5056                                 {
5057                                         ty = y;
5058                                         tx = x;
5059                                 }
5060                                 else break;
5061                         }
5062                         if ((ty != oy) || (tx != ox))
5063                         {
5064                                 msg_format(_("%sを吹き飛ばした!", "You blow %s away!"), m_name);
5065                                 cave[oy][ox].m_idx = 0;
5066                                 cave[ty][tx].m_idx = (s16b)m_idx;
5067                                 m_ptr->fy = (byte_hack)ty;
5068                                 m_ptr->fx = (byte_hack)tx;
5069
5070                                 update_mon(m_idx, TRUE);
5071                                 lite_spot(oy, ox);
5072                                 lite_spot(ty, tx);
5073
5074                                 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
5075                                         p_ptr->update |= (PU_MON_LITE);
5076                         }
5077                 }
5078         }
5079         return TRUE;
5080 }