OSDN Git Service

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