OSDN Git Service

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