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