OSDN Git Service

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