OSDN Git Service

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