OSDN Git Service

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