OSDN Git Service

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