OSDN Git Service

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