OSDN Git Service

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