OSDN Git Service

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