OSDN Git Service

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