OSDN Git Service

move_player_effect()の処理をbitフラグで制御するように変更. また, プレ
[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         return TRUE;
1949 }
1950
1951
1952 /*
1953  * Leave an "explosive rune" which prevents monster movement
1954  */
1955 bool explosive_rune(void)
1956 {
1957         /* XXX XXX XXX */
1958         if (!cave_clean_bold(py, px))
1959         {
1960 #ifdef JP
1961 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1962 #else
1963                 msg_print("The object resists the spell.");
1964 #endif
1965
1966                 return FALSE;
1967         }
1968
1969         /* Create a glyph */
1970         cave[py][px].info |= CAVE_OBJECT;
1971         cave[py][px].mimic = FEAT_MINOR_GLYPH;
1972
1973         /* Notice */
1974         note_spot(py, px);
1975         
1976         /* Redraw */
1977         lite_spot(py, px);
1978
1979         return TRUE;
1980 }
1981
1982
1983 /*
1984  * Identify everything being carried.
1985  * Done by a potion of "self knowledge".
1986  */
1987 void identify_pack(void)
1988 {
1989         int i;
1990
1991         /* Simply identify and know every item */
1992         for (i = 0; i < INVEN_TOTAL; i++)
1993         {
1994                 object_type *o_ptr = &inventory[i];
1995
1996                 /* Skip non-objects */
1997                 if (!o_ptr->k_idx) continue;
1998
1999                 /* Identify it */
2000                 identify_item(o_ptr);
2001
2002                 /* Auto-inscription */
2003                 autopick_alter_item(i, FALSE);
2004         }
2005 }
2006
2007
2008 /*
2009  * Used by the "enchant" function (chance of failure)
2010  * (modified for Zangband, we need better stuff there...) -- TY
2011  */
2012 static int enchant_table[16] =
2013 {
2014         0, 10,  50, 100, 200,
2015         300, 400, 500, 650, 800,
2016         950, 987, 993, 995, 998,
2017         1000
2018 };
2019
2020
2021 /*
2022  * Removes curses from items in inventory
2023  *
2024  * Note that Items which are "Perma-Cursed" (The One Ring,
2025  * The Crown of Morgoth) can NEVER be uncursed.
2026  *
2027  * Note that if "all" is FALSE, then Items which are
2028  * "Heavy-Cursed" (Mormegil, Calris, and Weapons of Morgul)
2029  * will not be uncursed.
2030  */
2031 static int remove_curse_aux(int all)
2032 {
2033         int i, cnt = 0;
2034
2035         /* Attempt to uncurse items being worn */
2036         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2037         {
2038                 object_type *o_ptr = &inventory[i];
2039
2040                 /* Skip non-objects */
2041                 if (!o_ptr->k_idx) continue;
2042
2043                 /* Uncursed already */
2044                 if (!cursed_p(o_ptr)) continue;
2045
2046                 /* Heavily Cursed Items need a special spell */
2047                 if (!all && (o_ptr->curse_flags & TRC_HEAVY_CURSE)) continue;
2048
2049                 /* Perma-Cursed Items can NEVER be uncursed */
2050                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
2051                 {
2052                         /* Uncurse it */
2053                         o_ptr->curse_flags &= (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE);
2054                         continue;
2055                 }
2056
2057                 /* Uncurse it */
2058                 o_ptr->curse_flags = 0L;
2059
2060                 /* Hack -- Assume felt */
2061                 o_ptr->ident |= (IDENT_SENSE);
2062
2063                 /* Take note */
2064                 o_ptr->feeling = FEEL_NONE;
2065
2066                 /* Recalculate the bonuses */
2067                 p_ptr->update |= (PU_BONUS);
2068
2069                 /* Window stuff */
2070                 p_ptr->window |= (PW_EQUIP);
2071
2072                 /* Count the uncursings */
2073                 cnt++;
2074         }
2075
2076         /* Return "something uncursed" */
2077         return (cnt);
2078 }
2079
2080
2081 /*
2082  * Remove most curses
2083  */
2084 bool remove_curse(void)
2085 {
2086         return (remove_curse_aux(FALSE));
2087 }
2088
2089 /*
2090  * Remove all curses
2091  */
2092 bool remove_all_curse(void)
2093 {
2094         return (remove_curse_aux(TRUE));
2095 }
2096
2097
2098 /*
2099  * Turns an object into gold, gain some of its value in a shop
2100  */
2101 bool alchemy(void)
2102 {
2103         int item, amt = 1;
2104         int old_number;
2105         long price;
2106         bool force = FALSE;
2107         object_type *o_ptr;
2108         char o_name[MAX_NLEN];
2109         char out_val[MAX_NLEN+40];
2110
2111         cptr q, s;
2112
2113         /* Hack -- force destruction */
2114         if (command_arg > 0) force = TRUE;
2115
2116         /* Get an item */
2117 #ifdef JP
2118 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶â¤ËÊѤ¨¤Þ¤¹¤«¡©";
2119 s = "¶â¤ËÊѤ¨¤é¤ì¤ëʪ¤¬¤¢¤ê¤Þ¤»¤ó¡£";
2120 #else
2121         q = "Turn which item to gold? ";
2122         s = "You have nothing to turn to gold.";
2123 #endif
2124
2125         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
2126
2127         /* Get the item (in the pack) */
2128         if (item >= 0)
2129         {
2130                 o_ptr = &inventory[item];
2131         }
2132
2133         /* Get the item (on the floor) */
2134         else
2135         {
2136                 o_ptr = &o_list[0 - item];
2137         }
2138
2139
2140         /* See how many items */
2141         if (o_ptr->number > 1)
2142         {
2143                 /* Get a quantity */
2144                 amt = get_quantity(NULL, o_ptr->number);
2145
2146                 /* Allow user abort */
2147                 if (amt <= 0) return FALSE;
2148         }
2149
2150
2151         /* Describe the object */
2152         old_number = o_ptr->number;
2153         o_ptr->number = amt;
2154         object_desc(o_name, o_ptr, 0);
2155         o_ptr->number = old_number;
2156
2157         /* Verify unless quantity given */
2158         if (!force)
2159         {
2160                 if (confirm_destroy || (object_value(o_ptr) > 0))
2161                 {
2162                         /* Make a verification */
2163 #ifdef JP
2164 sprintf(out_val, "ËÜÅö¤Ë%s¤ò¶â¤ËÊѤ¨¤Þ¤¹¤«¡©", o_name);
2165 #else
2166                         sprintf(out_val, "Really turn %s to gold? ", o_name);
2167 #endif
2168
2169                         if (!get_check(out_val)) return FALSE;
2170                 }
2171         }
2172
2173         /* Artifacts cannot be destroyed */
2174         if (!can_player_destroy_object(o_ptr))
2175         {
2176                 /* Message */
2177 #ifdef JP
2178                 msg_format("%s¤ò¶â¤ËÊѤ¨¤ë¤³¤È¤Ë¼ºÇÔ¤·¤¿¡£", o_name);
2179 #else
2180                 msg_format("You fail to turn %s to gold!", o_name);
2181 #endif
2182
2183                 /* Done */
2184                 return FALSE;
2185         }
2186
2187         price = object_value_real(o_ptr);
2188
2189         if (price <= 0)
2190         {
2191                 /* Message */
2192 #ifdef JP
2193 msg_format("%s¤ò¥Ë¥»¤Î¶â¤ËÊѤ¨¤¿¡£", o_name);
2194 #else
2195                 msg_format("You turn %s to fool's gold.", o_name);
2196 #endif
2197
2198         }
2199         else
2200         {
2201                 price /= 3;
2202
2203                 if (amt > 1) price *= amt;
2204
2205                 if (price > 30000) price = 30000;
2206 #ifdef JP
2207 msg_format("%s¤ò¡ð%d ¤Î¶â¤ËÊѤ¨¤¿¡£", o_name, price);
2208 #else
2209                 msg_format("You turn %s to %ld coins worth of gold.", o_name, price);
2210 #endif
2211
2212                 p_ptr->au += price;
2213
2214                 /* Redraw gold */
2215                 p_ptr->redraw |= (PR_GOLD);
2216
2217                 /* Window stuff */
2218                 p_ptr->window |= (PW_PLAYER);
2219
2220         }
2221
2222         /* Eliminate the item (from the pack) */
2223         if (item >= 0)
2224         {
2225                 inven_item_increase(item, -amt);
2226                 inven_item_describe(item);
2227                 inven_item_optimize(item);
2228         }
2229
2230         /* Eliminate the item (from the floor) */
2231         else
2232         {
2233                 floor_item_increase(0 - item, -amt);
2234                 floor_item_describe(0 - item);
2235                 floor_item_optimize(0 - item);
2236         }
2237
2238         return TRUE;
2239 }
2240
2241
2242
2243 /*
2244  * Hook to specify "weapon"
2245  */
2246 bool item_tester_hook_weapon(object_type *o_ptr)
2247 {
2248         switch (o_ptr->tval)
2249         {
2250                 case TV_HAFTED:
2251                 case TV_POLEARM:
2252                 case TV_DIGGING:
2253                 case TV_BOW:
2254                 case TV_BOLT:
2255                 case TV_ARROW:
2256                 case TV_SHOT:
2257                 {
2258                         return (TRUE);
2259                 }
2260                 case TV_SWORD:
2261                 {
2262                         if (o_ptr->sval != SV_DOKUBARI) return (TRUE);
2263                 }
2264         }
2265
2266         return (FALSE);
2267 }
2268
2269 static bool item_tester_hook_weapon2(object_type *o_ptr)
2270 {
2271         switch (o_ptr->tval)
2272         {
2273                 case TV_SWORD:
2274                 case TV_HAFTED:
2275                 case TV_POLEARM:
2276                 case TV_DIGGING:
2277                 case TV_BOW:
2278                 case TV_BOLT:
2279                 case TV_ARROW:
2280                 case TV_SHOT:
2281                 {
2282                         return (TRUE);
2283                 }
2284         }
2285
2286         return (FALSE);
2287 }
2288
2289
2290 /*
2291  * Hook to specify "armour"
2292  */
2293 bool item_tester_hook_armour(object_type *o_ptr)
2294 {
2295         switch (o_ptr->tval)
2296         {
2297                 case TV_DRAG_ARMOR:
2298                 case TV_HARD_ARMOR:
2299                 case TV_SOFT_ARMOR:
2300                 case TV_SHIELD:
2301                 case TV_CLOAK:
2302                 case TV_CROWN:
2303                 case TV_HELM:
2304                 case TV_BOOTS:
2305                 case TV_GLOVES:
2306                 {
2307                         return (TRUE);
2308                 }
2309         }
2310
2311         return (FALSE);
2312 }
2313
2314
2315 /*
2316  * Check if an object is weapon or armour (but not arrow, bolt, or shot)
2317  */
2318 bool item_tester_hook_weapon_armour(object_type *o_ptr)
2319 {
2320         switch (o_ptr->tval)
2321         {
2322                 case TV_SWORD:
2323                 case TV_HAFTED:
2324                 case TV_POLEARM:
2325                 case TV_DIGGING:
2326                 case TV_BOW:
2327                 case TV_BOLT:
2328                 case TV_ARROW:
2329                 case TV_SHOT:
2330                 case TV_DRAG_ARMOR:
2331                 case TV_HARD_ARMOR:
2332                 case TV_SOFT_ARMOR:
2333                 case TV_SHIELD:
2334                 case TV_CLOAK:
2335                 case TV_CROWN:
2336                 case TV_HELM:
2337                 case TV_BOOTS:
2338                 case TV_GLOVES:
2339                 {
2340                         return (TRUE);
2341                 }
2342         }
2343
2344         return (FALSE);
2345 }
2346
2347
2348 /*
2349  * Check if an object is nameless weapon or armour
2350  */
2351 static bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
2352 {
2353         switch (o_ptr->tval)
2354         {
2355                 case TV_SWORD:
2356                 case TV_HAFTED:
2357                 case TV_POLEARM:
2358                 case TV_DIGGING:
2359                 case TV_BOW:
2360                 case TV_BOLT:
2361                 case TV_ARROW:
2362                 case TV_SHOT:
2363                 case TV_DRAG_ARMOR:
2364                 case TV_HARD_ARMOR:
2365                 case TV_SOFT_ARMOR:
2366                 case TV_SHIELD:
2367                 case TV_CLOAK:
2368                 case TV_CROWN:
2369                 case TV_HELM:
2370                 case TV_BOOTS:
2371                 case TV_GLOVES:
2372                         if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2 || o_ptr->xtra3)
2373                         {
2374                                 if (object_known_p(o_ptr)) return FALSE;
2375                         }
2376                         return TRUE;
2377         }
2378
2379         return FALSE;
2380 }
2381
2382
2383 /*
2384  * Break the curse of an item
2385  */
2386 static void break_curse(object_type *o_ptr)
2387 {
2388         if (cursed_p(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
2389         {
2390 #ifdef JP
2391 msg_print("¤«¤±¤é¤ì¤Æ¤¤¤¿¼ö¤¤¤¬ÂǤÁÇˤé¤ì¤¿¡ª");
2392 #else
2393                 msg_print("The curse is broken!");
2394 #endif
2395
2396                 o_ptr->curse_flags = 0L;
2397
2398                 o_ptr->ident |= (IDENT_SENSE);
2399
2400                 o_ptr->feeling = FEEL_NONE;
2401         }
2402 }
2403
2404
2405 /*
2406  * Enchants a plus onto an item. -RAK-
2407  *
2408  * Revamped!  Now takes item pointer, number of times to try enchanting,
2409  * and a flag of what to try enchanting.  Artifacts resist enchantment
2410  * some of the time, and successful enchantment to at least +0 might
2411  * break a curse on the item. -CFT-
2412  *
2413  * Note that an item can technically be enchanted all the way to +15 if
2414  * you wait a very, very, long time.  Going from +9 to +10 only works
2415  * about 5% of the time, and from +10 to +11 only about 1% of the time.
2416  *
2417  * Note that this function can now be used on "piles" of items, and
2418  * the larger the pile, the lower the chance of success.
2419  */
2420 bool enchant(object_type *o_ptr, int n, int eflag)
2421 {
2422         int     i, chance, prob;
2423         bool    res = FALSE;
2424         bool    a = (artifact_p(o_ptr) || o_ptr->art_name);
2425         bool    force = (eflag & ENCH_FORCE);
2426
2427
2428         /* Large piles resist enchantment */
2429         prob = o_ptr->number * 100;
2430
2431         /* Missiles are easy to enchant */
2432         if ((o_ptr->tval == TV_BOLT) ||
2433             (o_ptr->tval == TV_ARROW) ||
2434             (o_ptr->tval == TV_SHOT))
2435         {
2436                 prob = prob / 20;
2437         }
2438
2439         /* Try "n" times */
2440         for (i = 0; i < n; i++)
2441         {
2442                 /* Hack -- Roll for pile resistance */
2443                 if (!force && randint0(prob) >= 100) continue;
2444
2445                 /* Enchant to hit */
2446                 if (eflag & ENCH_TOHIT)
2447                 {
2448                         if (o_ptr->to_h < 0) chance = 0;
2449                         else if (o_ptr->to_h > 15) chance = 1000;
2450                         else chance = enchant_table[o_ptr->to_h];
2451
2452                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2453                         {
2454                                 o_ptr->to_h++;
2455                                 res = TRUE;
2456
2457                                 /* only when you get it above -1 -CFT */
2458                                 if (o_ptr->to_h >= 0)
2459                                         break_curse(o_ptr);
2460                         }
2461                 }
2462
2463                 /* Enchant to damage */
2464                 if (eflag & ENCH_TODAM)
2465                 {
2466                         if (o_ptr->to_d < 0) chance = 0;
2467                         else if (o_ptr->to_d > 15) chance = 1000;
2468                         else chance = enchant_table[o_ptr->to_d];
2469
2470                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2471                         {
2472                                 o_ptr->to_d++;
2473                                 res = TRUE;
2474
2475                                 /* only when you get it above -1 -CFT */
2476                                 if (o_ptr->to_d >= 0)
2477                                         break_curse(o_ptr);
2478                         }
2479                 }
2480
2481                 /* Enchant to armor class */
2482                 if (eflag & ENCH_TOAC)
2483                 {
2484                         if (o_ptr->to_a < 0) chance = 0;
2485                         else if (o_ptr->to_a > 15) chance = 1000;
2486                         else chance = enchant_table[o_ptr->to_a];
2487
2488                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2489                         {
2490                                 o_ptr->to_a++;
2491                                 res = TRUE;
2492
2493                                 /* only when you get it above -1 -CFT */
2494                                 if (o_ptr->to_a >= 0)
2495                                         break_curse(o_ptr);
2496                         }
2497                 }
2498         }
2499
2500         /* Failure */
2501         if (!res) return (FALSE);
2502
2503         /* Recalculate bonuses */
2504         p_ptr->update |= (PU_BONUS);
2505
2506         /* Combine / Reorder the pack (later) */
2507         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2508
2509         /* Window stuff */
2510         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2511
2512         calc_android_exp();
2513
2514         /* Success */
2515         return (TRUE);
2516 }
2517
2518
2519
2520 /*
2521  * Enchant an item (in the inventory or on the floor)
2522  * Note that "num_ac" requires armour, else weapon
2523  * Returns TRUE if attempted, FALSE if cancelled
2524  */
2525 bool enchant_spell(int num_hit, int num_dam, int num_ac)
2526 {
2527         int         item;
2528         bool        okay = FALSE;
2529         object_type *o_ptr;
2530         char        o_name[MAX_NLEN];
2531         cptr        q, s;
2532
2533
2534         /* Assume enchant weapon */
2535         item_tester_hook = item_tester_hook_weapon;
2536         item_tester_no_ryoute = TRUE;
2537
2538         /* Enchant armor if requested */
2539         if (num_ac) item_tester_hook = item_tester_hook_armour;
2540
2541         /* Get an item */
2542 #ifdef JP
2543 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶¯²½¤·¤Þ¤¹¤«? ";
2544 s = "¶¯²½¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
2545 #else
2546         q = "Enchant which item? ";
2547         s = "You have nothing to enchant.";
2548 #endif
2549
2550         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2551
2552         /* Get the item (in the pack) */
2553         if (item >= 0)
2554         {
2555                 o_ptr = &inventory[item];
2556         }
2557
2558         /* Get the item (on the floor) */
2559         else
2560         {
2561                 o_ptr = &o_list[0 - item];
2562         }
2563
2564
2565         /* Description */
2566         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2567
2568         /* Describe */
2569 #ifdef JP
2570 msg_format("%s ¤ÏÌÀ¤ë¤¯µ±¤¤¤¿¡ª",
2571     o_name);
2572 #else
2573         msg_format("%s %s glow%s brightly!",
2574                    ((item >= 0) ? "Your" : "The"), o_name,
2575                    ((o_ptr->number > 1) ? "" : "s"));
2576 #endif
2577
2578
2579         /* Enchant */
2580         if (enchant(o_ptr, num_hit, ENCH_TOHIT)) okay = TRUE;
2581         if (enchant(o_ptr, num_dam, ENCH_TODAM)) okay = TRUE;
2582         if (enchant(o_ptr, num_ac, ENCH_TOAC)) okay = TRUE;
2583
2584         /* Failure */
2585         if (!okay)
2586         {
2587                 /* Flush */
2588                 if (flush_failure) flush();
2589
2590                 /* Message */
2591 #ifdef JP
2592 msg_print("¶¯²½¤Ë¼ºÇÔ¤·¤¿¡£");
2593 #else
2594                 msg_print("The enchantment failed.");
2595 #endif
2596
2597                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2598         }
2599         else
2600                 chg_virtue(V_ENCHANT, 1);
2601
2602         calc_android_exp();
2603
2604         /* Something happened */
2605         return (TRUE);
2606 }
2607
2608
2609 bool artifact_scroll(void)
2610 {
2611         int             item;
2612         bool            okay = FALSE;
2613         object_type     *o_ptr;
2614         char            o_name[MAX_NLEN];
2615         cptr            q, s;
2616
2617
2618         item_tester_no_ryoute = TRUE;
2619         /* Enchant weapon/armour */
2620         item_tester_hook = item_tester_hook_nameless_weapon_armour;
2621
2622         /* Get an item */
2623 #ifdef JP
2624         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶¯²½¤·¤Þ¤¹¤«? ";
2625         s = "¶¯²½¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
2626 #else
2627         q = "Enchant which item? ";
2628         s = "You have nothing to enchant.";
2629 #endif
2630
2631         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2632
2633         /* Get the item (in the pack) */
2634         if (item >= 0)
2635         {
2636                 o_ptr = &inventory[item];
2637         }
2638
2639         /* Get the item (on the floor) */
2640         else
2641         {
2642                 o_ptr = &o_list[0 - item];
2643         }
2644
2645
2646         /* Description */
2647         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2648
2649         /* Describe */
2650 #ifdef JP
2651         msg_format("%s ¤ÏâÁ¤¤¸÷¤òȯ¤·¤¿¡ª",o_name);
2652 #else
2653         msg_format("%s %s radiate%s a blinding light!",
2654                   ((item >= 0) ? "Your" : "The"), o_name,
2655                   ((o_ptr->number > 1) ? "" : "s"));
2656 #endif
2657
2658         if (o_ptr->name1 || o_ptr->art_name)
2659         {
2660 #ifdef JP
2661                 msg_format("%s¤Ï´û¤ËÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤Ç¤¹¡ª", o_name  );
2662 #else
2663                 msg_format("The %s %s already %s!",
2664                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2665                     ((o_ptr->number > 1) ? "artifacts" : "an artifact"));
2666 #endif
2667
2668                 okay = FALSE;
2669         }
2670
2671         else if (o_ptr->name2)
2672         {
2673 #ifdef JP
2674                 msg_format("%s¤Ï´û¤Ë̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¤Ç¤¹¡ª", o_name );
2675 #else
2676                 msg_format("The %s %s already %s!",
2677                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2678                     ((o_ptr->number > 1) ? "ego items" : "an ego item"));
2679 #endif
2680
2681                 okay = FALSE;
2682         }
2683
2684         else if (o_ptr->xtra3)
2685         {
2686 #ifdef JP
2687                 msg_format("%s¤Ï´û¤Ë¶¯²½¤µ¤ì¤Æ¤¤¤Þ¤¹¡ª", o_name );
2688 #else
2689                 msg_format("The %s %s already %s!",
2690                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2691                     ((o_ptr->number > 1) ? "customized items" : "a customized item"));
2692 #endif
2693         }
2694
2695         else
2696         {
2697                 if (o_ptr->number > 1)
2698                 {
2699 #ifdef JP
2700                         msg_print("Ê£¿ô¤Î¥¢¥¤¥Æ¥à¤ËËâË¡¤ò¤«¤±¤ë¤À¤±¤Î¥¨¥Í¥ë¥®¡¼¤Ï¤¢¤ê¤Þ¤»¤ó¡ª");
2701                         msg_format("%d ¸Ä¤Î%s¤¬²õ¤ì¤¿¡ª",(o_ptr->number)-1, o_name);
2702 #else
2703                         msg_print("Not enough enough energy to enchant more than one object!");
2704                         msg_format("%d of your %s %s destroyed!",(o_ptr->number)-1, o_name, (o_ptr->number>2?"were":"was"));
2705 #endif
2706
2707                         if (item >= 0)
2708                         {
2709                                 inven_item_increase(item, 1-(o_ptr->number));
2710                         }
2711                         else
2712                         {
2713                                 floor_item_increase(0-item, 1-(o_ptr->number));
2714                         }
2715                 }
2716                 okay = create_artifact(o_ptr, TRUE);
2717         }
2718
2719         /* Failure */
2720         if (!okay)
2721         {
2722                 /* Flush */
2723                 if (flush_failure) flush();
2724
2725                 /* Message */
2726 #ifdef JP
2727                 msg_print("¶¯²½¤Ë¼ºÇÔ¤·¤¿¡£");
2728 #else
2729                 msg_print("The enchantment failed.");
2730 #endif
2731
2732                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2733         }
2734         else
2735                 chg_virtue(V_ENCHANT, 1);
2736
2737         calc_android_exp();
2738
2739         /* Something happened */
2740         return (TRUE);
2741 }
2742
2743
2744 /*
2745  * Identify an object
2746  */
2747 bool identify_item(object_type *o_ptr)
2748 {
2749         bool old_known = FALSE;
2750         char o_name[MAX_NLEN];
2751
2752         /* Description */
2753         object_desc(o_name, o_ptr, 0);
2754
2755         if (o_ptr->ident & IDENT_KNOWN)
2756                 old_known = TRUE;
2757
2758         if (!(o_ptr->ident & (IDENT_MENTAL)))
2759         {
2760                 if ((o_ptr->art_name) || (artifact_p(o_ptr)) || one_in_(5))
2761                         chg_virtue(V_KNOWLEDGE, 1);
2762         }
2763
2764         /* Identify it fully */
2765         object_aware(o_ptr);
2766         object_known(o_ptr);
2767
2768         /* Recalculate bonuses */
2769         p_ptr->update |= (PU_BONUS);
2770
2771         /* Combine / Reorder the pack (later) */
2772         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2773
2774         /* Window stuff */
2775         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2776
2777         strcpy(record_o_name, o_name);
2778         record_turn = turn;
2779
2780         /* Description */
2781         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2782
2783         if(record_fix_art && !old_known && artifact_p(o_ptr))
2784                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2785         if(record_rand_art && !old_known && o_ptr->art_name)
2786                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2787
2788         return old_known;
2789 }
2790
2791
2792 static bool item_tester_hook_identify(object_type *o_ptr)
2793 {
2794         return (bool)!object_known_p(o_ptr);
2795 }
2796
2797 static bool item_tester_hook_identify_weapon_armour(object_type *o_ptr)
2798 {
2799         if (object_known_p(o_ptr))
2800                 return FALSE;
2801         return item_tester_hook_weapon_armour(o_ptr);
2802 }
2803
2804 /*
2805  * Identify an object in the inventory (or on the floor)
2806  * This routine does *not* automatically combine objects.
2807  * Returns TRUE if something was identified, else FALSE.
2808  */
2809 bool ident_spell(bool only_equip)
2810 {
2811         int             item;
2812         object_type     *o_ptr;
2813         char            o_name[MAX_NLEN];
2814         cptr            q, s;
2815         bool old_known;
2816
2817         item_tester_no_ryoute = TRUE;
2818
2819         if (only_equip)
2820                 item_tester_hook = item_tester_hook_identify_weapon_armour;
2821         else
2822                 item_tester_hook = item_tester_hook_identify;
2823
2824         if (!can_get_item())
2825         {
2826                 if (only_equip)
2827                 {
2828                         item_tester_hook = item_tester_hook_weapon_armour;
2829                 }
2830                 else
2831                 {
2832                         item_tester_hook = NULL;
2833                 }
2834         }
2835
2836         /* Get an item */
2837 #ifdef JP
2838 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò´ÕÄꤷ¤Þ¤¹¤«? ";
2839 s = "´ÕÄꤹ¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
2840 #else
2841         q = "Identify which item? ";
2842         s = "You have nothing to identify.";
2843 #endif
2844
2845         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2846
2847         /* Get the item (in the pack) */
2848         if (item >= 0)
2849         {
2850                 o_ptr = &inventory[item];
2851         }
2852
2853         /* Get the item (on the floor) */
2854         else
2855         {
2856                 o_ptr = &o_list[0 - item];
2857         }
2858
2859         /* Identify it */
2860         old_known = identify_item(o_ptr);
2861
2862         /* Description */
2863         object_desc(o_name, o_ptr, 0);
2864
2865         /* Describe */
2866         if (item >= INVEN_RARM)
2867         {
2868 #ifdef JP
2869                 msg_format("%^s: %s(%c)¡£", describe_use(item), o_name, index_to_label(item));
2870 #else
2871                 msg_format("%^s: %s (%c).", describe_use(item), o_name, index_to_label(item));
2872 #endif
2873         }
2874         else if (item >= 0)
2875         {
2876 #ifdef JP
2877                 msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£", o_name, index_to_label(item));
2878 #else
2879                 msg_format("In your pack: %s (%c).", o_name, index_to_label(item));
2880 #endif
2881         }
2882         else
2883         {
2884 #ifdef JP
2885                 msg_format("¾²¾å: %s¡£", o_name);
2886 #else
2887                 msg_format("On the ground: %s.", o_name);
2888 #endif
2889         }
2890
2891         /* Auto-inscription/destroy */
2892         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2893
2894         /* Something happened */
2895         return (TRUE);
2896 }
2897
2898
2899 /*
2900  * Mundanify an object in the inventory (or on the floor)
2901  * This routine does *not* automatically combine objects.
2902  * Returns TRUE if something was mundanified, else FALSE.
2903  */
2904 bool mundane_spell(bool only_equip)
2905 {
2906         int             item;
2907         object_type     *o_ptr;
2908         cptr            q, s;
2909
2910         if (only_equip) item_tester_hook = item_tester_hook_weapon_armour;
2911         item_tester_no_ryoute = TRUE;
2912
2913         /* Get an item */
2914 #ifdef JP
2915 q = "¤É¤ì¤ò»È¤¤¤Þ¤¹¤«¡©";
2916 s = "»È¤¨¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£";
2917 #else
2918         q = "Use which item? ";
2919         s = "You have nothing you can use.";
2920 #endif
2921
2922         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2923
2924         /* Get the item (in the pack) */
2925         if (item >= 0)
2926         {
2927                 o_ptr = &inventory[item];
2928         }
2929
2930         /* Get the item (on the floor) */
2931         else
2932         {
2933                 o_ptr = &o_list[0 - item];
2934         }
2935
2936         /* Oops */
2937 #ifdef JP
2938         msg_print("¤Þ¤Ð¤æ¤¤Á®¸÷¤¬Áö¤Ã¤¿¡ª");
2939 #else
2940         msg_print("There is a bright flash of light!");
2941 #endif
2942         {
2943                 byte iy = o_ptr->iy;                 /* Y-position on map, or zero */
2944                 byte ix = o_ptr->ix;                 /* X-position on map, or zero */
2945                 s16b next_o_idx = o_ptr->next_o_idx; /* Next object in stack (if any) */
2946                 byte marked = o_ptr->marked;         /* Object is marked */
2947                 s16b weight = o_ptr->number * o_ptr->weight;
2948                 u16b inscription = o_ptr->inscription;
2949
2950                 /* Wipe it clean */
2951                 object_prep(o_ptr, o_ptr->k_idx);
2952
2953                 o_ptr->iy = iy;
2954                 o_ptr->ix = ix;
2955                 o_ptr->next_o_idx = next_o_idx;
2956                 o_ptr->marked = marked;
2957                 o_ptr->inscription = inscription;
2958                 if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
2959         }
2960         calc_android_exp();
2961
2962         /* Something happened */
2963         return TRUE;
2964 }
2965
2966
2967
2968 static bool item_tester_hook_identify_fully(object_type *o_ptr)
2969 {
2970         return (bool)(!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL));
2971 }
2972
2973 static bool item_tester_hook_identify_fully_weapon_armour(object_type *o_ptr)
2974 {
2975         if (!item_tester_hook_identify_fully(o_ptr))
2976                 return FALSE;
2977         return item_tester_hook_weapon_armour(o_ptr);
2978 }
2979
2980 /*
2981  * Fully "identify" an object in the inventory  -BEN-
2982  * This routine returns TRUE if an item was identified.
2983  */
2984 bool identify_fully(bool only_equip)
2985 {
2986         int             item;
2987         object_type     *o_ptr;
2988         char            o_name[MAX_NLEN];
2989         cptr            q, s;
2990         bool old_known;
2991
2992         item_tester_no_ryoute = TRUE;
2993         if (only_equip)
2994                 item_tester_hook = item_tester_hook_identify_fully_weapon_armour;
2995         else
2996                 item_tester_hook = item_tester_hook_identify_fully;
2997
2998         if (!can_get_item())
2999         {
3000                 if (only_equip)
3001                         item_tester_hook = item_tester_hook_weapon_armour;
3002                 else
3003                         item_tester_hook = NULL;
3004         }
3005
3006         /* Get an item */
3007 #ifdef JP
3008 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò´ÕÄꤷ¤Þ¤¹¤«? ";
3009 s = "´ÕÄꤹ¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
3010 #else
3011         q = "Identify which item? ";
3012         s = "You have nothing to identify.";
3013 #endif
3014
3015         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
3016
3017         /* Get the item (in the pack) */
3018         if (item >= 0)
3019         {
3020                 o_ptr = &inventory[item];
3021         }
3022
3023         /* Get the item (on the floor) */
3024         else
3025         {
3026                 o_ptr = &o_list[0 - item];
3027         }
3028
3029         /* Identify it */
3030         old_known = identify_item(o_ptr);
3031
3032         /* Mark the item as fully known */
3033         o_ptr->ident |= (IDENT_MENTAL);
3034
3035         /* Handle stuff */
3036         handle_stuff();
3037
3038         /* Description */
3039         object_desc(o_name, o_ptr, 0);
3040
3041         /* Describe */
3042         if (item >= INVEN_RARM)
3043         {
3044 #ifdef JP
3045                 msg_format("%^s: %s(%c)¡£", describe_use(item), o_name, index_to_label(item));
3046 #else
3047                 msg_format("%^s: %s (%c).", describe_use(item), o_name, index_to_label(item));
3048 #endif
3049
3050
3051         }
3052         else if (item >= 0)
3053         {
3054 #ifdef JP
3055                 msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£", o_name, index_to_label(item));
3056 #else
3057                 msg_format("In your pack: %s (%c).", o_name, index_to_label(item));
3058 #endif
3059         }
3060         else
3061         {
3062 #ifdef JP
3063                 msg_format("¾²¾å: %s¡£", o_name);
3064 #else
3065                 msg_format("On the ground: %s.", o_name);
3066 #endif
3067         }
3068
3069         /* Describe it fully */
3070         (void)screen_object(o_ptr, TRUE);
3071
3072         /* Auto-inscription/destroy */
3073         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
3074
3075         /* Success */
3076         return (TRUE);
3077 }
3078
3079
3080
3081
3082 /*
3083  * Hook for "get_item()".  Determine if something is rechargable.
3084  */
3085 bool item_tester_hook_recharge(object_type *o_ptr)
3086 {
3087         /* Recharge staffs */
3088         if (o_ptr->tval == TV_STAFF) return (TRUE);
3089
3090         /* Recharge wands */
3091         if (o_ptr->tval == TV_WAND) return (TRUE);
3092
3093         /* Hack -- Recharge rods */
3094         if (o_ptr->tval == TV_ROD) return (TRUE);
3095
3096         /* Nope */
3097         return (FALSE);
3098 }
3099
3100
3101 /*
3102  * Recharge a wand/staff/rod from the pack or on the floor.
3103  * This function has been rewritten in Oangband and ZAngband.
3104  *
3105  * Sorcery/Arcane -- Recharge  --> recharge(plev * 4)
3106  * Chaos -- Arcane Binding     --> recharge(90)
3107  *
3108  * Scroll of recharging        --> recharge(130)
3109  * Artifact activation/Thingol --> recharge(130)
3110  *
3111  * It is harder to recharge high level, and highly charged wands,
3112  * staffs, and rods.  The more wands in a stack, the more easily and
3113  * strongly they recharge.  Staffs, however, each get fewer charges if
3114  * stacked.
3115  *
3116  * XXX XXX XXX Beware of "sliding index errors".
3117  */
3118 bool recharge(int power)
3119 {
3120         int item, lev;
3121         int recharge_strength, recharge_amount;
3122
3123         object_type *o_ptr;
3124         object_kind *k_ptr;
3125
3126         bool fail = FALSE;
3127         byte fail_type = 1;
3128
3129         cptr q, s;
3130         char o_name[MAX_NLEN];
3131
3132         /* Only accept legal items */
3133         item_tester_hook = item_tester_hook_recharge;
3134
3135         /* Get an item */
3136 #ifdef JP
3137 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ËËâÎϤò½¼Å¶¤·¤Þ¤¹¤«? ";
3138 s = "ËâÎϤò½¼Å¶¤¹¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
3139 #else
3140         q = "Recharge which item? ";
3141         s = "You have nothing to recharge.";
3142 #endif
3143
3144         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
3145
3146         /* Get the item (in the pack) */
3147         if (item >= 0)
3148         {
3149                 o_ptr = &inventory[item];
3150         }
3151
3152         /* Get the item (on the floor) */
3153         else
3154         {
3155                 o_ptr = &o_list[0 - item];
3156         }
3157
3158         /* Get the object kind. */
3159         k_ptr = &k_info[o_ptr->k_idx];
3160
3161         /* Extract the object "level" */
3162         lev = get_object_level(o_ptr);
3163
3164
3165         /* Recharge a rod */
3166         if (o_ptr->tval == TV_ROD)
3167         {
3168                 /* Extract a recharge strength by comparing object level to power. */
3169                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
3170
3171
3172                 /* Back-fire */
3173                 if (one_in_(recharge_strength))
3174                 {
3175                         /* Activate the failure code. */
3176                         fail = TRUE;
3177                 }
3178
3179                 /* Recharge */
3180                 else
3181                 {
3182                         /* Recharge amount */
3183                         recharge_amount = (power * damroll(3, 2));
3184
3185                         /* Recharge by that amount */
3186                         if (o_ptr->timeout > recharge_amount)
3187                                 o_ptr->timeout -= recharge_amount;
3188                         else
3189                                 o_ptr->timeout = 0;
3190                 }
3191         }
3192
3193
3194         /* Recharge wand/staff */
3195         else
3196         {
3197                 /* Extract a recharge strength by comparing object level to power.
3198                  * Divide up a stack of wands' charges to calculate charge penalty.
3199                  */
3200                 if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
3201                         recharge_strength = (100 + power - lev -
3202                         (8 * o_ptr->pval / o_ptr->number)) / 15;
3203
3204                 /* All staffs, unstacked wands. */
3205                 else recharge_strength = (100 + power - lev -
3206                         (8 * o_ptr->pval)) / 15;
3207
3208                 /* Paranoia */
3209                 if (recharge_strength < 0) recharge_strength = 0;
3210
3211                 /* Back-fire */
3212                 if (one_in_(recharge_strength))
3213                 {
3214                         /* Activate the failure code. */
3215                         fail = TRUE;
3216                 }
3217
3218                 /* If the spell didn't backfire, recharge the wand or staff. */
3219                 else
3220                 {
3221                         /* Recharge based on the standard number of charges. */
3222                         recharge_amount = randint1(1 + k_ptr->pval / 2);
3223
3224                         /* Multiple wands in a stack increase recharging somewhat. */
3225                         if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
3226                         {
3227                                 recharge_amount +=
3228                                         (randint1(recharge_amount * (o_ptr->number - 1))) / 2;
3229                                 if (recharge_amount < 1) recharge_amount = 1;
3230                                 if (recharge_amount > 12) recharge_amount = 12;
3231                         }
3232
3233                         /* But each staff in a stack gets fewer additional charges,
3234                          * although always at least one.
3235                          */
3236                         if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1))
3237                         {
3238                                 recharge_amount /= o_ptr->number;
3239                                 if (recharge_amount < 1) recharge_amount = 1;
3240                         }
3241
3242                         /* Recharge the wand or staff. */
3243                         o_ptr->pval += recharge_amount;
3244
3245
3246                         /* Hack -- we no longer "know" the item */
3247                         o_ptr->ident &= ~(IDENT_KNOWN);
3248
3249                         /* Hack -- we no longer think the item is empty */
3250                         o_ptr->ident &= ~(IDENT_EMPTY);
3251                 }
3252         }
3253
3254
3255         /* Inflict the penalties for failing a recharge. */
3256         if (fail)
3257         {
3258                 /* Artifacts are never destroyed. */
3259                 if (artifact_p(o_ptr))
3260                 {
3261                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
3262 #ifdef JP
3263 msg_format("ËâÎϤ¬µÕή¤·¤¿¡ª%s¤Ï´°Á´¤ËËâÎϤò¼º¤Ã¤¿¡£", o_name);
3264 #else
3265                         msg_format("The recharging backfires - %s is completely drained!", o_name);
3266 #endif
3267
3268
3269                         /* Artifact rods. */
3270                         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout < 10000))
3271                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
3272
3273                         /* Artifact wands and staffs. */
3274                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
3275                                 o_ptr->pval = 0;
3276                 }
3277                 else
3278                 {
3279                         /* Get the object description */
3280                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3281
3282                         /*** Determine Seriousness of Failure ***/
3283
3284                         /* Mages recharge objects more safely. */
3285                         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)
3286                         {
3287                                 /* 10% chance to blow up one rod, otherwise draining. */
3288                                 if (o_ptr->tval == TV_ROD)
3289                                 {
3290                                         if (one_in_(10)) fail_type = 2;
3291                                         else fail_type = 1;
3292                                 }
3293                                 /* 75% chance to blow up one wand, otherwise draining. */
3294                                 else if (o_ptr->tval == TV_WAND)
3295                                 {
3296                                         if (!one_in_(3)) fail_type = 2;
3297                                         else fail_type = 1;
3298                                 }
3299                                 /* 50% chance to blow up one staff, otherwise no effect. */
3300                                 else if (o_ptr->tval == TV_STAFF)
3301                                 {
3302                                         if (one_in_(2)) fail_type = 2;
3303                                         else fail_type = 0;
3304                                 }
3305                         }
3306
3307                         /* All other classes get no special favors. */
3308                         else
3309                         {
3310                                 /* 33% chance to blow up one rod, otherwise draining. */
3311                                 if (o_ptr->tval == TV_ROD)
3312                                 {
3313                                         if (one_in_(3)) fail_type = 2;
3314                                         else fail_type = 1;
3315                                 }
3316                                 /* 20% chance of the entire stack, else destroy one wand. */
3317                                 else if (o_ptr->tval == TV_WAND)
3318                                 {
3319                                         if (one_in_(5)) fail_type = 3;
3320                                         else fail_type = 2;
3321                                 }
3322                                 /* Blow up one staff. */
3323                                 else if (o_ptr->tval == TV_STAFF)
3324                                 {
3325                                         fail_type = 2;
3326                                 }
3327                         }
3328
3329                         /*** Apply draining and destruction. ***/
3330
3331                         /* Drain object or stack of objects. */
3332                         if (fail_type == 1)
3333                         {
3334                                 if (o_ptr->tval == TV_ROD)
3335                                 {
3336 #ifdef JP
3337 msg_print("ËâÎϤ¬µÕÊ®¼Í¤·¤Æ¡¢¥í¥Ã¥É¤«¤é¤µ¤é¤ËËâÎϤòµÛ¤¤¼è¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
3338 #else
3339                                         msg_print("The recharge backfires, draining the rod further!");
3340 #endif
3341
3342                                         if (o_ptr->timeout < 10000)
3343                                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
3344                                 }
3345                                 else if (o_ptr->tval == TV_WAND)
3346                                 {
3347 #ifdef JP
3348 msg_format("%s¤ÏÇË»¤òÌȤ줿¤¬¡¢ËâÎϤ¬Á´¤Æ¼º¤ï¤ì¤¿¡£", o_name);
3349 #else
3350                                         msg_format("You save your %s from destruction, but all charges are lost.", o_name);
3351 #endif
3352
3353                                         o_ptr->pval = 0;
3354                                 }
3355                                 /* Staffs aren't drained. */
3356                         }
3357
3358                         /* Destroy an object or one in a stack of objects. */
3359                         if (fail_type == 2)
3360                         {
3361                                 if (o_ptr->number > 1)
3362 #ifdef JP
3363 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬°ìËܲõ¤ì¤¿¡ª", o_name);
3364 #else
3365                                         msg_format("Wild magic consumes one of your %s!", o_name);
3366 #endif
3367
3368                                 else
3369 #ifdef JP
3370 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²õ¤ì¤¿¡ª", o_name);
3371 #else
3372                                         msg_format("Wild magic consumes your %s!", o_name);
3373 #endif
3374
3375
3376                                 /* Reduce rod stack maximum timeout, drain wands. */
3377                                 if (o_ptr->tval == TV_ROD) o_ptr->timeout = (o_ptr->number - 1) * k_ptr->pval;
3378                                 if (o_ptr->tval == TV_WAND) o_ptr->pval = 0;
3379
3380                                 /* Reduce and describe inventory */
3381                                 if (item >= 0)
3382                                 {
3383                                         inven_item_increase(item, -1);
3384                                         inven_item_describe(item);
3385                                         inven_item_optimize(item);
3386                                 }
3387
3388                                 /* Reduce and describe floor item */
3389                                 else
3390                                 {
3391                                         floor_item_increase(0 - item, -1);
3392                                         floor_item_describe(0 - item);
3393                                         floor_item_optimize(0 - item);
3394                                 }
3395                         }
3396
3397                         /* Destroy all members of a stack of objects. */
3398                         if (fail_type == 3)
3399                         {
3400                                 if (o_ptr->number > 1)
3401 #ifdef JP
3402 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬Á´¤Æ²õ¤ì¤¿¡ª", o_name);
3403 #else
3404                                         msg_format("Wild magic consumes all your %s!", o_name);
3405 #endif
3406
3407                                 else
3408 #ifdef JP
3409 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²õ¤ì¤¿¡ª", o_name);
3410 #else
3411                                         msg_format("Wild magic consumes your %s!", o_name);
3412 #endif
3413
3414
3415
3416                                 /* Reduce and describe inventory */
3417                                 if (item >= 0)
3418                                 {
3419                                         inven_item_increase(item, -999);
3420                                         inven_item_describe(item);
3421                                         inven_item_optimize(item);
3422                                 }
3423
3424                                 /* Reduce and describe floor item */
3425                                 else
3426                                 {
3427                                         floor_item_increase(0 - item, -999);
3428                                         floor_item_describe(0 - item);
3429                                         floor_item_optimize(0 - item);
3430                                 }
3431                         }
3432                 }
3433         }
3434
3435         /* Combine / Reorder the pack (later) */
3436         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3437
3438         /* Window stuff */
3439         p_ptr->window |= (PW_INVEN);
3440
3441         /* Something was done */
3442         return (TRUE);
3443 }
3444
3445
3446 /*
3447  * Bless a weapon
3448  */
3449 bool bless_weapon(void)
3450 {
3451         int             item;
3452         object_type     *o_ptr;
3453         u32b flgs[TR_FLAG_SIZE];
3454         char            o_name[MAX_NLEN];
3455         cptr            q, s;
3456
3457         item_tester_no_ryoute = TRUE;
3458         /* Assume enchant weapon */
3459         item_tester_hook = item_tester_hook_weapon2;
3460
3461         /* Get an item */
3462 #ifdef JP
3463 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò½ËÊ¡¤·¤Þ¤¹¤«¡©";
3464 s = "½ËÊ¡¤Ç¤­¤ëÉð´ï¤¬¤¢¤ê¤Þ¤»¤ó¡£";
3465 #else
3466         q = "Bless which weapon? ";
3467         s = "You have weapon to bless.";
3468 #endif
3469
3470         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3471                 return FALSE;
3472
3473         /* Get the item (in the pack) */
3474         if (item >= 0)
3475         {
3476                 o_ptr = &inventory[item];
3477         }
3478
3479         /* Get the item (on the floor) */
3480         else
3481         {
3482                 o_ptr = &o_list[0 - item];
3483         }
3484
3485
3486         /* Description */
3487         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3488
3489         /* Extract the flags */
3490         object_flags(o_ptr, flgs);
3491
3492         if (cursed_p(o_ptr))
3493         {
3494                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) ||
3495                     (o_ptr->curse_flags & TRC_PERMA_CURSE))
3496                 {
3497 #ifdef JP
3498 msg_format("%s¤òʤ¤¦¹õ¤¤¥ª¡¼¥é¤Ï½ËÊ¡¤òÄ·¤ÍÊÖ¤·¤¿¡ª",
3499     o_name);
3500 #else
3501                         msg_format("The black aura on %s %s disrupts the blessing!",
3502                             ((item >= 0) ? "your" : "the"), o_name);
3503 #endif
3504
3505                         return TRUE;
3506                 }
3507
3508 #ifdef JP
3509 msg_format("%s ¤«¤é¼Ù°­¤Ê¥ª¡¼¥é¤¬¾Ã¤¨¤¿¡£",
3510     o_name);
3511 #else
3512                 msg_format("A malignant aura leaves %s %s.",
3513                     ((item >= 0) ? "your" : "the"), o_name);
3514 #endif
3515
3516
3517                 /* Uncurse it */
3518                 o_ptr->curse_flags = 0L;
3519
3520                 /* Hack -- Assume felt */
3521                 o_ptr->ident |= (IDENT_SENSE);
3522
3523                 /* Take note */
3524                 o_ptr->feeling = FEEL_NONE;
3525
3526                 /* Recalculate the bonuses */
3527                 p_ptr->update |= (PU_BONUS);
3528
3529                 /* Window stuff */
3530                 p_ptr->window |= (PW_EQUIP);
3531         }
3532
3533         /*
3534          * Next, we try to bless it. Artifacts have a 1/3 chance of
3535          * being blessed, otherwise, the operation simply disenchants
3536          * them, godly power negating the magic. Ok, the explanation
3537          * is silly, but otherwise priests would always bless every
3538          * artifact weapon they find. Ego weapons and normal weapons
3539          * can be blessed automatically.
3540          */
3541         if (have_flag(flgs, TR_BLESSED))
3542         {
3543 #ifdef JP
3544 msg_format("%s ¤Ï´û¤Ë½ËÊ¡¤µ¤ì¤Æ¤¤¤ë¡£",
3545     o_name    );
3546 #else
3547                 msg_format("%s %s %s blessed already.",
3548                     ((item >= 0) ? "Your" : "The"), o_name,
3549                     ((o_ptr->number > 1) ? "were" : "was"));
3550 #endif
3551
3552                 return TRUE;
3553         }
3554
3555         if (!(o_ptr->art_name || o_ptr->name1 || o_ptr->name2) || one_in_(3))
3556         {
3557                 /* Describe */
3558 #ifdef JP
3559 msg_format("%s¤Ïµ±¤¤¤¿¡ª",
3560      o_name);
3561 #else
3562                 msg_format("%s %s shine%s!",
3563                     ((item >= 0) ? "Your" : "The"), o_name,
3564                     ((o_ptr->number > 1) ? "" : "s"));
3565 #endif
3566
3567                 add_flag(o_ptr->art_flags, TR_BLESSED);
3568                 o_ptr->discount = 99;
3569         }
3570         else
3571         {
3572                 bool dis_happened = FALSE;
3573
3574 #ifdef JP
3575 msg_print("¤½¤ÎÉð´ï¤Ï½ËÊ¡¤ò·ù¤Ã¤Æ¤¤¤ë¡ª");
3576 #else
3577                 msg_print("The weapon resists your blessing!");
3578 #endif
3579
3580
3581                 /* Disenchant tohit */
3582                 if (o_ptr->to_h > 0)
3583                 {
3584                         o_ptr->to_h--;
3585                         dis_happened = TRUE;
3586                 }
3587
3588                 if ((o_ptr->to_h > 5) && (randint0(100) < 33)) o_ptr->to_h--;
3589
3590                 /* Disenchant todam */
3591                 if (o_ptr->to_d > 0)
3592                 {
3593                         o_ptr->to_d--;
3594                         dis_happened = TRUE;
3595                 }
3596
3597                 if ((o_ptr->to_d > 5) && (randint0(100) < 33)) o_ptr->to_d--;
3598
3599                 /* Disenchant toac */
3600                 if (o_ptr->to_a > 0)
3601                 {
3602                         o_ptr->to_a--;
3603                         dis_happened = TRUE;
3604                 }
3605
3606                 if ((o_ptr->to_a > 5) && (randint0(100) < 33)) o_ptr->to_a--;
3607
3608                 if (dis_happened)
3609                 {
3610 #ifdef JP
3611 msg_print("¼þ°Ï¤¬ËÞÍǤÊÊ·°Ïµ¤¤ÇËþ¤Á¤¿...");
3612 #else
3613                         msg_print("There is a static feeling in the air...");
3614 #endif
3615
3616 #ifdef JP
3617 msg_format("%s ¤ÏÎô²½¤·¤¿¡ª",
3618      o_name    );
3619 #else
3620                         msg_format("%s %s %s disenchanted!",
3621                             ((item >= 0) ? "Your" : "The"), o_name,
3622                             ((o_ptr->number > 1) ? "were" : "was"));
3623 #endif
3624
3625                 }
3626         }
3627
3628         /* Recalculate bonuses */
3629         p_ptr->update |= (PU_BONUS);
3630
3631         /* Window stuff */
3632         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
3633
3634         calc_android_exp();
3635
3636         return TRUE;
3637 }
3638
3639
3640 /*
3641  * pulish shield
3642  */
3643 bool pulish_shield(void)
3644 {
3645         int             item;
3646         object_type     *o_ptr;
3647         u32b flgs[TR_FLAG_SIZE];
3648         char            o_name[MAX_NLEN];
3649         cptr            q, s;
3650
3651         item_tester_no_ryoute = TRUE;
3652         /* Assume enchant weapon */
3653         item_tester_tval = TV_SHIELD;
3654
3655         /* Get an item */
3656 #ifdef JP
3657 q = "¤É¤Î½â¤òË᤭¤Þ¤¹¤«¡©";
3658 s = "Ë᤯½â¤¬¤¢¤ê¤Þ¤»¤ó¡£";
3659 #else
3660         q = "Pulish which weapon? ";
3661         s = "You have weapon to pulish.";
3662 #endif
3663
3664         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3665                 return FALSE;
3666
3667         /* Get the item (in the pack) */
3668         if (item >= 0)
3669         {
3670                 o_ptr = &inventory[item];
3671         }
3672
3673         /* Get the item (on the floor) */
3674         else
3675         {
3676                 o_ptr = &o_list[0 - item];
3677         }
3678
3679
3680         /* Description */
3681         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3682
3683         /* Extract the flags */
3684         object_flags(o_ptr, flgs);
3685
3686         if (o_ptr->k_idx && !artifact_p(o_ptr) && !ego_item_p(o_ptr) &&
3687             !o_ptr->art_name && !cursed_p(o_ptr) && (o_ptr->sval != SV_MIRROR_SHIELD))
3688         {
3689 #ifdef JP
3690 msg_format("%s¤Ïµ±¤¤¤¿¡ª", o_name);
3691 #else
3692                 msg_format("%s %s shine%s!",
3693                     ((item >= 0) ? "Your" : "The"), o_name,
3694                     ((o_ptr->number > 1) ? "" : "s"));
3695 #endif
3696                 o_ptr->name2 = EGO_REFLECTION;
3697                 enchant(o_ptr, randint0(3) + 4, ENCH_TOAC);
3698
3699                 o_ptr->discount = 99;
3700                 chg_virtue(V_ENCHANT, 2);
3701
3702                 return TRUE;
3703         }
3704         else
3705         {
3706                 if (flush_failure) flush();
3707
3708 #ifdef JP
3709 msg_print("¼ºÇÔ¤·¤¿¡£");
3710 #else
3711                 msg_print("Failed.");
3712 #endif
3713
3714                 chg_virtue(V_ENCHANT, -2);
3715         }
3716         calc_android_exp();
3717
3718         return FALSE;
3719 }
3720
3721
3722 /*
3723  * Potions "smash open" and cause an area effect when
3724  * (1) they are shattered while in the player's inventory,
3725  * due to cold (etc) attacks;
3726  * (2) they are thrown at a monster, or obstacle;
3727  * (3) they are shattered by a "cold ball" or other such spell
3728  * while lying on the floor.
3729  *
3730  * Arguments:
3731  *    who   ---  who caused the potion to shatter (0=player)
3732  *          potions that smash on the floor are assumed to
3733  *          be caused by no-one (who = 1), as are those that
3734  *          shatter inside the player inventory.
3735  *          (Not anymore -- I changed this; TY)
3736  *    y, x  --- coordinates of the potion (or player if
3737  *          the potion was in her inventory);
3738  *    o_ptr --- pointer to the potion object.
3739  */
3740 bool potion_smash_effect(int who, int y, int x, int k_idx)
3741 {
3742         int     radius = 2;
3743         int     dt = 0;
3744         int     dam = 0;
3745         bool    angry = FALSE;
3746
3747         object_kind *k_ptr = &k_info[k_idx];
3748
3749         switch (k_ptr->sval)
3750         {
3751                 case SV_POTION_SALT_WATER:
3752                 case SV_POTION_SLIME_MOLD:
3753                 case SV_POTION_LOSE_MEMORIES:
3754                 case SV_POTION_DEC_STR:
3755                 case SV_POTION_DEC_INT:
3756                 case SV_POTION_DEC_WIS:
3757                 case SV_POTION_DEC_DEX:
3758                 case SV_POTION_DEC_CON:
3759                 case SV_POTION_DEC_CHR:
3760                 case SV_POTION_WATER:   /* perhaps a 'water' attack? */
3761                 case SV_POTION_APPLE_JUICE:
3762                         return TRUE;
3763
3764                 case SV_POTION_INFRAVISION:
3765                 case SV_POTION_DETECT_INVIS:
3766                 case SV_POTION_SLOW_POISON:
3767                 case SV_POTION_CURE_POISON:
3768                 case SV_POTION_BOLDNESS:
3769                 case SV_POTION_RESIST_HEAT:
3770                 case SV_POTION_RESIST_COLD:
3771                 case SV_POTION_HEROISM:
3772                 case SV_POTION_BESERK_STRENGTH:
3773                 case SV_POTION_RES_STR:
3774                 case SV_POTION_RES_INT:
3775                 case SV_POTION_RES_WIS:
3776                 case SV_POTION_RES_DEX:
3777                 case SV_POTION_RES_CON:
3778                 case SV_POTION_RES_CHR:
3779                 case SV_POTION_INC_STR:
3780                 case SV_POTION_INC_INT:
3781                 case SV_POTION_INC_WIS:
3782                 case SV_POTION_INC_DEX:
3783                 case SV_POTION_INC_CON:
3784                 case SV_POTION_INC_CHR:
3785                 case SV_POTION_AUGMENTATION:
3786                 case SV_POTION_ENLIGHTENMENT:
3787                 case SV_POTION_STAR_ENLIGHTENMENT:
3788                 case SV_POTION_SELF_KNOWLEDGE:
3789                 case SV_POTION_EXPERIENCE:
3790                 case SV_POTION_RESISTANCE:
3791                 case SV_POTION_INVULNERABILITY:
3792                 case SV_POTION_NEW_LIFE:
3793                         /* All of the above potions have no effect when shattered */
3794                         return FALSE;
3795                 case SV_POTION_SLOWNESS:
3796                         dt = GF_OLD_SLOW;
3797                         dam = 5;
3798                         angry = TRUE;
3799                         break;
3800                 case SV_POTION_POISON:
3801                         dt = GF_POIS;
3802                         dam = 3;
3803                         angry = TRUE;
3804                         break;
3805                 case SV_POTION_BLINDNESS:
3806                         dt = GF_DARK;
3807                         angry = TRUE;
3808                         break;
3809                 case SV_POTION_CONFUSION: /* Booze */
3810                         dt = GF_OLD_CONF;
3811                         angry = TRUE;
3812                         break;
3813                 case SV_POTION_SLEEP:
3814                         dt = GF_OLD_SLEEP;
3815                         angry = TRUE;
3816                         break;
3817                 case SV_POTION_RUINATION:
3818                 case SV_POTION_DETONATIONS:
3819                         dt = GF_SHARDS;
3820                         dam = damroll(25, 25);
3821                         angry = TRUE;
3822                         break;
3823                 case SV_POTION_DEATH:
3824                         dt = GF_DEATH_RAY;    /* !! */
3825                         dam = k_ptr->level * 10;
3826                         angry = TRUE;
3827                         radius = 1;
3828                         break;
3829                 case SV_POTION_SPEED:
3830                         dt = GF_OLD_SPEED;
3831                         break;
3832                 case SV_POTION_CURE_LIGHT:
3833                         dt = GF_OLD_HEAL;
3834                         dam = damroll(2, 3);
3835                         break;
3836                 case SV_POTION_CURE_SERIOUS:
3837                         dt = GF_OLD_HEAL;
3838                         dam = damroll(4, 3);
3839                         break;
3840                 case SV_POTION_CURE_CRITICAL:
3841                 case SV_POTION_CURING:
3842                         dt = GF_OLD_HEAL;
3843                         dam = damroll(6, 3);
3844                         break;
3845                 case SV_POTION_HEALING:
3846                         dt = GF_OLD_HEAL;
3847                         dam = damroll(10, 10);
3848                         break;
3849                 case SV_POTION_RESTORE_EXP:
3850                         dt = GF_STAR_HEAL;
3851                         dam = 0;
3852                         radius = 1;
3853                         break;
3854                 case SV_POTION_LIFE:
3855                         dt = GF_STAR_HEAL;
3856                         dam = damroll(50, 50);
3857                         radius = 1;
3858                         break;
3859                 case SV_POTION_STAR_HEALING:
3860                         dt = GF_OLD_HEAL;
3861                         dam = damroll(50, 50);
3862                         radius = 1;
3863                         break;
3864                 case SV_POTION_RESTORE_MANA:   /* MANA */
3865                         dt = GF_MANA;
3866                         dam = damroll(10, 10);
3867                         radius = 1;
3868                         break;
3869                 default:
3870                         /* Do nothing */  ;
3871         }
3872
3873         (void)project(who, radius, y, x, dam, dt,
3874             (PROJECT_JUMP | PROJECT_ITEM | PROJECT_KILL), -1);
3875
3876         /* XXX  those potions that explode need to become "known" */
3877         return angry;
3878 }
3879
3880
3881 /*
3882  * Hack -- Display all known spells in a window
3883  *
3884  * XXX XXX XXX Need to analyze size of the window.
3885  *
3886  * XXX XXX XXX Need more color coding.
3887  */
3888 void display_spell_list(void)
3889 {
3890         int             i, j;
3891         int             y, x;
3892         int             m[9];
3893         magic_type      *s_ptr;
3894         char            name[80];
3895         char            out_val[160];
3896
3897
3898         /* Erase window */
3899         clear_from(0);
3900
3901         /* They have too many spells to list */
3902         if (p_ptr->pclass == CLASS_SORCERER) return;
3903         if (p_ptr->pclass == CLASS_RED_MAGE) return;
3904
3905         /* mind.c type classes */
3906         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
3907             (p_ptr->pclass == CLASS_BERSERKER) ||
3908             (p_ptr->pclass == CLASS_NINJA) ||
3909             (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
3910             (p_ptr->pclass == CLASS_FORCETRAINER))
3911         {
3912                 int             i;
3913                 int             y = 1;
3914                 int             x = 1;
3915                 int             minfail = 0;
3916                 int             plev = p_ptr->lev;
3917                 int             chance = 0;
3918                 mind_type       spell;
3919                 char            comment[80];
3920                 char            psi_desc[80];
3921                 int             use_mind;
3922                 bool use_hp = FALSE;
3923
3924                 /* Display a list of spells */
3925                 prt("", y, x);
3926 #ifdef JP
3927 put_str("̾Á°", y, x + 5);
3928 put_str("Lv   MP ¼ºÎ¨ ¸ú²Ì", y, x + 35);
3929 #else
3930                 put_str("Name", y, x + 5);
3931                 put_str("Lv Mana Fail Info", y, x + 35);
3932 #endif
3933
3934                 switch(p_ptr->pclass)
3935                 {
3936                 case CLASS_MINDCRAFTER: use_mind = MIND_MINDCRAFTER;break;
3937                 case CLASS_FORCETRAINER:          use_mind = MIND_KI;break;
3938                 case CLASS_BERSERKER: use_mind = MIND_BERSERKER; use_hp = TRUE; break;
3939                 case CLASS_MIRROR_MASTER: use_mind = MIND_MIRROR_MASTER; break;
3940                 case CLASS_NINJA: use_mind = MIND_NINJUTSU; use_hp = TRUE; break;
3941                 default:                use_mind = 0;break;
3942                 }
3943
3944                 /* Dump the spells */
3945                 for (i = 0; i < MAX_MIND_POWERS; i++)
3946                 {
3947                         byte a = TERM_WHITE;
3948
3949                         /* Access the available spell */
3950                         spell = mind_powers[use_mind].info[i];
3951                         if (spell.min_lev > plev) break;
3952
3953                         /* Get the failure rate */
3954                         chance = spell.fail;
3955
3956                         /* Reduce failure rate by "effective" level adjustment */
3957                         chance -= 3 * (p_ptr->lev - spell.min_lev);
3958
3959                         /* Reduce failure rate by INT/WIS adjustment */
3960                         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
3961
3962                         if (!use_hp)
3963                         {
3964                                 /* Not enough mana to cast */
3965                                 if (spell.mana_cost > p_ptr->csp)
3966                                 {
3967                                         chance += 5 * (spell.mana_cost - p_ptr->csp);
3968                                         a = TERM_ORANGE;
3969                                 }
3970                         }
3971                         else
3972                         {
3973                                 /* Not enough hp to cast */
3974                                 if (spell.mana_cost > p_ptr->chp)
3975                                 {
3976                                         chance += 100;
3977                                         a = TERM_RED;
3978                                 }
3979                         }
3980
3981                         /* Extract the minimum failure rate */
3982                         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
3983
3984                         /* Minimum failure rate */
3985                         if (chance < minfail) chance = minfail;
3986
3987                         /* Stunning makes spells harder */
3988                         if (p_ptr->stun > 50) chance += 25;
3989                         else if (p_ptr->stun) chance += 15;
3990
3991                         /* Always a 5 percent chance of working */
3992                         if (chance > 95) chance = 95;
3993
3994                         /* Get info */
3995                         mindcraft_info(comment, use_mind, i);
3996
3997                         /* Dump the spell */
3998                         sprintf(psi_desc, "  %c) %-30s%2d %4d %3d%%%s",
3999                             I2A(i), spell.name,
4000                             spell.min_lev, spell.mana_cost, chance, comment);
4001
4002                         Term_putstr(x, y + i + 1, -1, a, psi_desc);
4003                 }
4004                 return;
4005         }
4006
4007         /* Cannot read spellbooks */
4008         if (REALM_NONE == p_ptr->realm1) return;
4009
4010         /* Normal spellcaster with books */
4011
4012         /* Scan books */
4013         for (j = 0; j < ((p_ptr->realm2 > REALM_NONE) ? 2 : 1); j++)
4014         {
4015                 int n = 0;
4016
4017                 /* Reset vertical */
4018                 m[j] = 0;
4019
4020                 /* Vertical location */
4021                 y = (j < 3) ? 0 : (m[j - 3] + 2);
4022
4023                 /* Horizontal location */
4024                 x = 27 * (j % 3);
4025
4026                 /* Scan spells */
4027                 for (i = 0; i < 32; i++)
4028                 {
4029                         byte a = TERM_WHITE;
4030
4031                         /* Access the spell */
4032                         if (!is_magic((j < 1) ? p_ptr->realm1 : p_ptr->realm2))
4033                         {
4034                                 s_ptr = &technic_info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - MIN_TECHNIC][i % 32];
4035                         }
4036                         else
4037                         {
4038                                 s_ptr = &mp_ptr->info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - 1][i % 32];
4039                         }
4040
4041                         strcpy(name, spell_names[technic2magic((j < 1) ? p_ptr->realm1 : p_ptr->realm2)-1][i % 32]);
4042
4043                         /* Illegible */
4044                         if (s_ptr->slevel >= 99)
4045                         {
4046                                 /* Illegible */
4047 #ifdef JP
4048 strcpy(name, "(ȽÆÉÉÔǽ)");
4049 #else
4050                                 strcpy(name, "(illegible)");
4051 #endif
4052
4053
4054                                 /* Unusable */
4055                                 a = TERM_L_DARK;
4056                         }
4057
4058                         /* Forgotten */
4059                         else if ((j < 1) ?
4060                                 ((p_ptr->spell_forgotten1 & (1L << i))) :
4061                                 ((p_ptr->spell_forgotten2 & (1L << (i % 32)))))
4062                         {
4063                                 /* Forgotten */
4064                                 a = TERM_ORANGE;
4065                         }
4066
4067                         /* Unknown */
4068                         else if (!((j < 1) ?
4069                                 (p_ptr->spell_learned1 & (1L << i)) :
4070                                 (p_ptr->spell_learned2 & (1L << (i % 32)))))
4071                         {
4072                                 /* Unknown */
4073                                 a = TERM_RED;
4074                         }
4075
4076                         /* Untried */
4077                         else if (!((j < 1) ?
4078                                 (p_ptr->spell_worked1 & (1L << i)) :
4079                                 (p_ptr->spell_worked2 & (1L << (i % 32)))))
4080                         {
4081                                 /* Untried */
4082                                 a = TERM_YELLOW;
4083                         }
4084
4085                         /* Dump the spell --(-- */
4086                         sprintf(out_val, "%c/%c) %-20.20s",
4087                                 I2A(n / 8), I2A(n % 8), name);
4088
4089                         /* Track maximum */
4090                         m[j] = y + n;
4091
4092                         /* Dump onto the window */
4093                         Term_putstr(x, m[j], -1, a, out_val);
4094
4095                         /* Next */
4096                         n++;
4097                 }
4098         }
4099 }
4100
4101
4102 /*
4103  * Returns experience of a spell
4104  */
4105 s16b experience_of_spell(int spell, int use_realm)
4106 {
4107         if (p_ptr->pclass == CLASS_SORCERER) return SPELL_EXP_MASTER;
4108         else if (p_ptr->pclass == CLASS_RED_MAGE) return SPELL_EXP_SKILLED;
4109         else if (use_realm == p_ptr->realm1) return p_ptr->spell_exp[spell];
4110         else if (use_realm == p_ptr->realm2) return p_ptr->spell_exp[spell + 32];
4111         else return 0;
4112 }
4113
4114
4115 /*
4116  * Modify mana consumption rate using spell exp and p_ptr->dec_mana
4117  */
4118 int mod_need_mana(int need_mana, int spell, int realm)
4119 {
4120 #define MANA_CONST   2400
4121 #define MANA_DIV        4
4122 #define DEC_MANA_DIV    3
4123
4124         /* Realm magic */
4125         if ((realm > REALM_NONE) && (realm <= MAX_REALM))
4126         {
4127                 /*
4128                  * need_mana defaults if spell exp equals SPELL_EXP_EXPERT and !p_ptr->dec_mana.
4129                  * MANA_CONST is used to calculate need_mana effected from spell proficiency.
4130                  */
4131                 need_mana = need_mana * (MANA_CONST + SPELL_EXP_EXPERT - experience_of_spell(spell, realm)) + (MANA_CONST - 1);
4132                 need_mana *= p_ptr->dec_mana ? DEC_MANA_DIV : MANA_DIV;
4133                 need_mana /= MANA_CONST * MANA_DIV;
4134                 if (need_mana < 1) need_mana = 1;
4135         }
4136
4137         /* Non-realm magic */
4138         else
4139         {
4140                 if (p_ptr->dec_mana) need_mana = (need_mana + 1) * DEC_MANA_DIV / MANA_DIV;
4141         }
4142
4143 #undef DEC_MANA_DIV
4144 #undef MANA_DIV
4145 #undef MANA_CONST
4146
4147         return need_mana;
4148 }
4149
4150
4151 /*
4152  * Modify spell fail rate
4153  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
4154  */
4155 int mod_spell_chance_1(int chance)
4156 {
4157         chance += p_ptr->to_m_chance;
4158
4159         if (p_ptr->heavy_spell) chance += 20;
4160
4161         if (p_ptr->dec_mana && p_ptr->easy_spell) chance -= 4;
4162         else if (p_ptr->easy_spell) chance -= 3;
4163         else if (p_ptr->dec_mana) chance -= 2;
4164
4165         return chance;
4166 }
4167
4168
4169 /*
4170  * Modify spell fail rate (as "suffix" process)
4171  * Using p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
4172  * Note: variable "chance" cannot be negative.
4173  */
4174 int mod_spell_chance_2(int chance)
4175 {
4176         if (p_ptr->dec_mana) chance--;
4177
4178         if (p_ptr->heavy_spell) chance += 5;
4179
4180         return MAX(chance, 0);
4181 }
4182
4183
4184 /*
4185  * Returns spell chance of failure for spell -RAK-
4186  */
4187 s16b spell_chance(int spell, int use_realm)
4188 {
4189         int             chance, minfail;
4190         magic_type      *s_ptr;
4191         int             need_mana;
4192         int penalty = (mp_ptr->spell_stat == A_WIS) ? 10 : 4;
4193
4194
4195         /* Paranoia -- must be literate */
4196         if (!mp_ptr->spell_book) return (100);
4197
4198         if (use_realm == REALM_HISSATSU) return 0;
4199
4200         /* Access the spell */
4201         if (!is_magic(use_realm))
4202         {
4203                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4204         }
4205         else
4206         {
4207                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
4208         }
4209
4210         /* Extract the base spell failure rate */
4211         chance = s_ptr->sfail;
4212
4213         /* Reduce failure rate by "effective" level adjustment */
4214         chance -= 3 * (p_ptr->lev - s_ptr->slevel);
4215
4216         /* Reduce failure rate by INT/WIS adjustment */
4217         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
4218
4219         if (p_ptr->riding)
4220                 chance += (MAX(r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 100 - 10, 0));
4221
4222         /* Extract mana consumption rate */
4223         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
4224
4225         /* Not enough mana to cast */
4226         if (need_mana > p_ptr->csp)
4227         {
4228                 chance += 5 * (need_mana - p_ptr->csp);
4229         }
4230
4231         if ((use_realm != p_ptr->realm1) && ((p_ptr->pclass == CLASS_MAGE) || (p_ptr->pclass == CLASS_PRIEST))) chance += 5;
4232
4233         /* Extract the minimum failure rate */
4234         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
4235
4236         /*
4237          * Non mage/priest characters never get too good
4238          * (added high mage, mindcrafter)
4239          */
4240         if (mp_ptr->spell_xtra & MAGIC_FAIL_5PERCENT)
4241         {
4242                 if (minfail < 5) minfail = 5;
4243         }
4244
4245         /* Hack -- Priest prayer penalty for "edged" weapons  -DGK */
4246         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[0]) chance += 25;
4247         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[1]) chance += 25;
4248
4249         chance = mod_spell_chance_1(chance);
4250
4251         if ((use_realm == REALM_NATURE) && ((p_ptr->align > 50) || (p_ptr->align < -50))) chance += penalty;
4252         if (((use_realm == REALM_LIFE) || (use_realm == REALM_CRUSADE)) && (p_ptr->align < -20)) chance += penalty;
4253         if (((use_realm == REALM_DEATH) || (use_realm == REALM_DAEMON)) && (p_ptr->align > 20)) chance += penalty;
4254
4255         /* Minimum failure rate */
4256         if (chance < minfail) chance = minfail;
4257
4258         /* Stunning makes spells harder */
4259         if (p_ptr->stun > 50) chance += 25;
4260         else if (p_ptr->stun) chance += 15;
4261
4262         /* Always a 5 percent chance of working */
4263         if (chance > 95) chance = 95;
4264
4265         if ((use_realm == p_ptr->realm1) || (use_realm == p_ptr->realm2)
4266             || (p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4267         {
4268                 s16b exp = experience_of_spell(spell, use_realm);
4269                 if (exp >= SPELL_EXP_EXPERT) chance--;
4270                 if (exp >= SPELL_EXP_MASTER) chance--;
4271         }
4272
4273         /* Return the chance */
4274         return mod_spell_chance_2(chance);
4275 }
4276
4277
4278
4279 /*
4280  * Determine if a spell is "okay" for the player to cast or study
4281  * The spell must be legible, not forgotten, and also, to cast,
4282  * it must be known, and to study, it must not be known.
4283  */
4284 bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
4285 {
4286         magic_type *s_ptr;
4287
4288         /* Access the spell */
4289         if (!is_magic(use_realm))
4290         {
4291                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4292         }
4293         else
4294         {
4295                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
4296         }
4297
4298         /* Spell is illegal */
4299         if (s_ptr->slevel > p_ptr->lev) return (FALSE);
4300
4301         /* Spell is forgotten */
4302         if ((use_realm == p_ptr->realm2) ?
4303             (p_ptr->spell_forgotten2 & (1L << spell)) :
4304             (p_ptr->spell_forgotten1 & (1L << spell)))
4305         {
4306                 /* Never okay */
4307                 return (FALSE);
4308         }
4309
4310         if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
4311         if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
4312
4313         /* Spell is learned */
4314         if ((use_realm == p_ptr->realm2) ?
4315             (p_ptr->spell_learned2 & (1L << spell)) :
4316             (p_ptr->spell_learned1 & (1L << spell)))
4317         {
4318                 /* Always true */
4319                 return (!study_pray);
4320         }
4321
4322         /* Okay to study, not to cast */
4323         return (!learned);
4324 }
4325
4326
4327
4328 /*
4329  * Extra information on a spell -DRS-
4330  *
4331  * We can use up to 14 characters of the buffer 'p'
4332  *
4333  * The strings in this function were extracted from the code in the
4334  * functions "do_cmd_cast()" and "do_cmd_pray()" and may be dated.
4335  */
4336 static void spell_info(char *p, int spell, int use_realm)
4337 {
4338         int plev = p_ptr->lev;
4339
4340         /* See below */
4341         int orb = plev + (plev / ((p_ptr->pclass == CLASS_PRIEST ||
4342                             p_ptr->pclass == CLASS_HIGH_MAGE ||
4343                             p_ptr->pclass == CLASS_SORCERER) ? 2 : 4));
4344
4345         int burst = plev + (plev / ((p_ptr->pclass == CLASS_MAGE ||
4346                                      p_ptr->pclass == CLASS_HIGH_MAGE ||
4347                                      p_ptr->pclass == CLASS_SORCERER) ? 2 : 4));
4348 #ifdef JP
4349         cptr s_dam = "»½ý:";
4350         cptr s_dur = "´ü´Ö:";
4351         cptr s_range = "ÈÏ°Ï:";
4352         cptr s_heal = "²óÉü:";
4353         cptr s_random = "¥é¥ó¥À¥à";
4354         cptr s_delay = "ÃÙ±ä:";
4355 #else
4356         cptr s_dam = "dam ";
4357         cptr s_dur = "dur ";
4358         cptr s_range = "range ";
4359         cptr s_heal = "heal ";
4360         cptr s_random = "random";
4361         cptr s_delay = "delay ";
4362 #endif
4363         /* Default */
4364         strcpy(p, "");
4365
4366         /* Analyze the spell */
4367         switch (use_realm)
4368         {
4369         case REALM_LIFE: /* Life */
4370                 switch (spell)
4371                 {
4372                 case  0: sprintf(p, " %s2d10", s_heal); break;
4373                 case  1: sprintf(p, " %s12+d12", s_dur); break;
4374                 case  2: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4375                 case  3: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4376                 case  5: sprintf(p, " %s4d10", s_heal); break;
4377                 case  9: sprintf(p, " %s%dd8", s_dam, 8 + ((plev - 1) / 5)); break;
4378                 case 10: sprintf(p, " %s8d10", s_heal); break;
4379                 case 11: sprintf(p, " %s20+d20", s_dur); break;
4380                 case 14: sprintf(p, " %s300", s_heal); break;
4381                 case 18: sprintf(p, " %sd%d", s_dam, 5 * plev); break;
4382                 case 20: sprintf(p, " %s%dd15", s_dam, 5 + ((plev - 1) / 3)); break;
4383                 case 21: sprintf(p, " %s15+d21", s_delay); break;
4384                 case 29: sprintf(p, " %s2000", s_heal); break;
4385                 case 31: sprintf(p, " %s%d+d%d", s_dur,(plev/2), (plev/2)); break;
4386                 }
4387                 break;
4388                 
4389         case REALM_SORCERY: /* Sorcery */
4390                 switch (spell)
4391                 {
4392                 case  1: sprintf(p, " %s10", s_range); break;
4393                 case  3: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4394                 case  5: sprintf(p, " %s%d", s_range, plev * 5); break;
4395                 case 13: sprintf(p, " %s%d+d%d", s_dur, plev, plev + 20); break;
4396                 case 18: sprintf(p, " %s25+d30", s_dur); break;
4397                 case 22: sprintf(p, " %s15+d21", s_delay); break;
4398                 case 23: sprintf(p, " %s%d", s_range, plev / 2 + 10); break;
4399                 case 25: sprintf(p, " %s7d7+%d", s_dam, plev); break;
4400 #ifdef JP
4401                 case 26: sprintf(p, " ºÇÂç½ÅÎÌ:%d.%dkg", lbtokg1(plev * 15),lbtokg2(plev * 15)); break;
4402 #else
4403                 case 26: sprintf(p, " max wgt %d", plev * 15 / 10); break;
4404 #endif
4405                 case 27: sprintf(p, " %s25+d30", s_dur); break;
4406                 case 31: sprintf(p, " %s4+d4", s_dur); break;
4407                 }
4408                 break;
4409                 
4410         case REALM_NATURE: /* Nature */
4411                 switch (spell)
4412                 {
4413 #ifdef JP
4414                 case  1: sprintf(p, " %s%dd4 ¼ÍÄø%d", s_dam, (3 + ((plev - 1) / 5)), plev/6+2); break;
4415 #else
4416                 case  1: sprintf(p, " %s%dd4 rng %d", s_dam, (3 + ((plev - 1) / 5)), plev/6+2); break;
4417 #endif
4418                 case  4: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4419                 case  6: sprintf(p, " %s20+d20", s_dur); break;
4420                 case  7: sprintf(p, " %s2d8", s_heal); break;
4421                 case  9: sprintf(p, " %s%dd8", s_dam, (3 + ((plev - 5) / 4))); break;
4422                 case 11: sprintf(p, " %s%dd8", s_dam, (5 + ((plev - 5) / 4))); break;
4423                 case 12: sprintf(p, " %s6d8", s_dam); break;
4424                 case 15: sprintf(p, " %s500", s_heal); break;
4425                 case 17: sprintf(p, " %s20+d30", s_dur); break;
4426                 case 18: sprintf(p, " %s20+d20", s_dur); break;
4427 #ifdef JP
4428                 case 24: sprintf(p, " È¾·Â:10"); break;
4429 #else
4430                 case 24: sprintf(p, " rad 10"); break;
4431 #endif
4432                 case 26: sprintf(p, " %s%d", s_dam, 70 + plev * 3 / 2); break;
4433                 case 27: sprintf(p, " %s%d", s_dam, 90 + plev * 3 / 2); break;
4434                 case 28: sprintf(p, " %s%d", s_dam, 100 + plev * 3 / 2); break;
4435                 case 29: sprintf(p, " %s75", s_dam); break;
4436                 case 31: sprintf(p, " %s%d+%d", s_dam, 4 * plev, 100 + plev); break;
4437                 }
4438                 break;
4439                 
4440         case REALM_CHAOS: /* Chaos */
4441                 switch (spell)
4442                 {
4443                 case  0: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4444                 case  2: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4445                 case  4: sprintf(p, " %s3d5+%d", s_dam, burst); break;
4446                 case  5: sprintf(p, " %s%dd8", s_dam, (6 + ((plev - 5) / 4))); break;
4447                 case  6: sprintf(p, " %s%dd8", s_dam, (8 + ((plev - 5) / 4))); break;
4448                 case  7: sprintf(p, " %s%d", s_range, plev * 5); break;
4449                 case  8: sprintf(p, " %s", s_random); break;
4450                 case  9: sprintf(p, " %s%dd8", s_dam, (10 + ((plev - 5) / 4))); break;
4451                 case 10: sprintf(p, " %s%d", s_dam, (60 + plev)/2); break;
4452                 case 11: sprintf(p, " %s%dd8", s_dam, (11 + ((plev - 5) / 4))); break;
4453                 case 12: sprintf(p, " %s%d", s_dam, 55 + plev); break;
4454                 case 15: sprintf(p, " %s%d", s_dam, 99 + plev*2); break;
4455                 case 17: sprintf(p, " %s%dd8", s_dam, (5 + (plev / 10))); break;
4456                 case 19: sprintf(p, " %s%d", s_dam, 70 + plev); break;
4457                 case 21: sprintf(p, " %s%d", s_dam, 120 + plev*2); break;
4458                 case 24: sprintf(p, " %s%dd8", s_dam, (9 + (plev / 10))); break;
4459 #ifdef JP
4460                 case 25: sprintf(p, " %s³Æ%d", s_dam, plev * 2); break;
4461 #else
4462                 case 25: sprintf(p, " dam %d each", plev * 2); break;
4463 #endif
4464                 case 26: sprintf(p, " %s%d", s_dam, 150 + plev*3/2); break;
4465                 case 27: sprintf(p, " %s150 / 250", s_dam); break;
4466                 case 29: sprintf(p, " %s%d", s_dam, 300 + (plev * 4)); break;
4467                 case 30: sprintf(p, " %s%ld", s_dam, p_ptr->chp); break;
4468                 case 31: sprintf(p, " %s3 * 175", s_dam); break;
4469                 }
4470                 break;
4471                 
4472         case REALM_DEATH: /* Death */
4473                 switch (spell)
4474                 {
4475                 case  1: sprintf(p, " %s%dd3", s_dam, (3 + ((plev - 1) / 5))); break;
4476                 case  3: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4477                 case  5: sprintf(p, " %s20+d20", s_dur); break;
4478                 case  8: sprintf(p, " %s3d6+%d", s_dam, burst); break;
4479                 case  9: sprintf(p, " %s%dd8", s_dam, (8 + ((plev - 5) / 4))); break;
4480                 case 10: sprintf(p, " %s%d", s_dam, 30+plev); break;
4481 #ifdef JP
4482                 case 13: sprintf(p, " »:%d+d%d", plev * 2, plev * 2); break;
4483 #else
4484                 case 13: sprintf(p, " d %d+d%d", plev * 2, plev * 2); break;
4485 #endif
4486                 case 16: sprintf(p, " %s25+d25", s_dur); break;
4487                 case 17: sprintf(p, " %s", s_random); break;
4488                 case 18: sprintf(p, " %s%dd8", s_dam, (4 + ((plev - 5) / 4))); break;
4489                 case 19: sprintf(p, " %s25+d25", s_dur); break;
4490                 case 21: sprintf(p, " %s3*100", s_dam); break;
4491                 case 22: sprintf(p, " %sd%d", s_dam, plev * 3); break;
4492                 case 23: sprintf(p, " %s%d", s_dam, 100 + plev * 2); break;
4493                 case 27: sprintf(p, " %s%d+d%d", s_dur,10+plev/2, 10+plev/2); break;
4494                 case 30: sprintf(p, " %s666", s_dam); break;
4495                 case 31: sprintf(p, " %s%d+d%d", s_dur, (plev / 2), (plev / 2)); break;
4496                 }
4497                 break;
4498                 
4499         case REALM_TRUMP: /* Trump */
4500                 switch (spell)
4501                 {
4502                 case  0: sprintf(p, " %s10", s_range); break;
4503                 case  2: sprintf(p, " %s", s_random); break;
4504                 case  4: sprintf(p, " %s%d", s_range, plev * 4); break;
4505                 case  5: sprintf(p, " %s25+d30", s_dur); break;
4506 #ifdef JP
4507                 case  8: sprintf(p, " ºÇÂç½ÅÎÌ:%d.%d", lbtokg1(plev * 15 / 10),lbtokg2(plev * 15 / 10)); break;
4508 #else
4509                 case  8: sprintf(p, " max wgt %d", plev * 15 / 10); break;
4510 #endif
4511                 case 13: sprintf(p, " %s%d", s_range, plev / 2 + 10); break;
4512                 case 14: sprintf(p, " %s15+d21", s_delay); break;
4513                 case 26: sprintf(p, " %s%d", s_heal, plev * 10 + 200); break;
4514 #ifdef JP
4515                 case 28: sprintf(p, " %s³Æ%d", s_dam, plev * 2); break;
4516 #else
4517                 case 28: sprintf(p, " %s%d each", s_dam, plev * 2); break;
4518 #endif
4519                 }
4520                 break;
4521                 
4522         case REALM_ARCANE: /* Arcane */
4523                 switch (spell)
4524                 {
4525                 case  0: sprintf(p, " %s%dd3", s_dam, 3 + ((plev - 1) / 5)); break;
4526                 case  4: sprintf(p, " %s10", s_range); break;
4527                 case  5: sprintf(p, " %s2d%d", s_dam, plev / 2); break;
4528                 case  7: sprintf(p, " %s2d8", s_heal); break;
4529                 case 14:
4530                 case 15:
4531                 case 16:
4532                 case 17: sprintf(p, " %s20+d20", s_dur); break;
4533                 case 18: sprintf(p, " %s4d8", s_heal); break;
4534                 case 19: sprintf(p, " %s%d", s_range, plev * 5); break;
4535                 case 21: sprintf(p, " %s6d8", s_dam); break;
4536                 case 24: sprintf(p, " %s24+d24", s_dur); break;
4537                 case 28: sprintf(p, " %s%d", s_dam, 75 + plev); break;
4538                 case 30: sprintf(p, " %s15+d21", s_delay); break;
4539                 case 31: sprintf(p, " %s25+d30", s_dur); break;
4540                 }
4541                 break;
4542                 
4543         case REALM_ENCHANT: /* Craft */
4544                 switch (spell)
4545                 {
4546                 case 0: sprintf(p, " %s100+d100", s_dur); break;
4547                 case 1: sprintf(p, " %s80+d80", s_dur); break;
4548                 case 3:
4549                 case 4:
4550                 case 6:
4551                 case 7:
4552                 case 10:
4553                 case 18: sprintf(p, " %s20+d20", s_dur); break;
4554                 case 5: sprintf(p, " %s25+d25", s_dur); break;
4555                 case 8: sprintf(p, " %s24+d24", s_dur); break;
4556                 case 11: sprintf(p, " %s25+d25", s_dur); break;
4557                 case 13: sprintf(p, " %s%d+d25", s_dur, plev * 3); break;
4558                 case 15: sprintf(p, " %s%d+d%d", s_dur, plev/2, plev/2); break;
4559                 case 16: sprintf(p, " %s25+d30", s_dur); break;
4560                 case 17: sprintf(p, " %s30+d20", s_dur); break;
4561                 case 19: sprintf(p, " %s%d+d%d", s_dur, plev, plev+20); break;
4562                 case 20: sprintf(p, " %s50+d50", s_dur); break;
4563                 case 23: sprintf(p, " %s20+d20", s_dur); break;
4564                 case 31: sprintf(p, " %s13+d13", s_dur); break;
4565                 }
4566                 break;
4567                 
4568         case REALM_DAEMON: /* Daemon */
4569                 switch (spell)
4570                 {
4571                 case  0: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4572                 case  2: sprintf(p, " %s12+d12", s_dur); break;
4573                 case  3: sprintf(p, " %s20+d20", s_dur); break;
4574                 case  5: sprintf(p, " %s%dd8", s_dam, (6 + ((plev - 5) / 4))); break;
4575                 case  7: sprintf(p, " %s3d6+%d", s_dam, burst); break;
4576                 case 10: sprintf(p, " %s20+d20", s_dur); break;
4577                 case 11: sprintf(p, " %s%dd8", s_dam, (11 + ((plev - 5) / 4))); break;
4578                 case 12: sprintf(p, " %s%d", s_dam, 55 + plev); break;
4579                 case 14: sprintf(p, " %s%d", s_dam, 100 + plev*3/2); break;
4580                 case 16: sprintf(p, " %s30+d25", s_dur); break;
4581                 case 17: sprintf(p, " %s20+d20", s_dur); break;
4582                 case 18: sprintf(p, " %s%d", s_dam, 55 + plev); break;
4583                 case 19: sprintf(p, " %s%d", s_dam, 80 + plev*3/2); break;
4584                 case 20: sprintf(p, " %s%d+d%d", s_dur,10+plev/2, 10+plev/2); break;
4585                 case 21: sprintf(p, " %sd%d+d%d", s_dam, 2 * plev, 2 * plev); break;
4586                 case 22: sprintf(p, " %s%d", s_dam, 100 + plev*2); break;
4587                 case 24: sprintf(p, " %s25+d25", s_dur); break;
4588                 case 25: sprintf(p, " %s20+d20", s_dur); break;
4589                 case 26: sprintf(p, " %s%d+%d", s_dam, 25+plev/2, 25+plev/2); break;
4590                 case 29: sprintf(p, " %s%d", s_dam, plev*15); break;
4591                 case 30: sprintf(p, " %s600", s_dam); break;
4592                 case 31: sprintf(p, " %s15+d15", s_dur); break;
4593                 }
4594                 break;
4595                 
4596         case REALM_CRUSADE: /* Crusade */
4597                 switch (spell)
4598                 {
4599                 case  0: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4600                 case  5: sprintf(p, " %s%d", s_range, 25+plev/2); break;
4601 #ifdef JP
4602                 case  6: sprintf(p, " %s³Æ%dd2", s_dam, 3+((plev-1)/9)); break;
4603 #else
4604                 case  6: sprintf(p, " %s%dd2 each", s_dam, 3+((plev-1)/9)); break;
4605 #endif
4606                 case  9: sprintf(p, " %s3d6+%d", s_dam, orb); break;
4607                 case 10: sprintf(p, " %sd%d", s_dam, plev); break;
4608                 case 12: sprintf(p, " %s24+d24", s_dur); break;
4609                 case 13: sprintf(p, " %sd25+%d", s_dur, 3 * plev); break;
4610                 case 14: sprintf(p, " %s%d", s_dam, plev*5); break;
4611 #ifdef JP
4612                 case 15: sprintf(p, " Â»:d%d/²ó:100", 6 * plev); break;
4613 #else
4614                 case 15: sprintf(p, " dam:d%d/h100", 6 * plev); break;
4615 #endif
4616                 case 18: sprintf(p, " %s18+d18", s_dur); break;
4617                 case 19: sprintf(p, " %sd%d", s_dam, 4 * plev); break;
4618                 case 20: sprintf(p, " %sd%d", s_dam, 4 * plev); break;
4619                 case 22: sprintf(p, " %s%d", s_dam, 2 * plev+100); break;
4620                 case 24: sprintf(p, " %s25+d25", s_dur); break;
4621                 case 28: sprintf(p, " %s10+d10", s_dur); break;
4622 #ifdef JP
4623                 case 29: sprintf(p, " %s³Æ%d", s_dam, plev*3+25); break;
4624 #else
4625                 case 29: sprintf(p, " %s%d each", s_dam, plev*3+25); break;
4626 #endif
4627 #ifdef JP
4628                 case 30: sprintf(p, " ²ó100/»%d+%d", plev * 4, plev*11/2); break;
4629 #else
4630                 case 30: sprintf(p, " h100/dm%d+%d", plev * 4, plev*11/2); break;
4631 #endif
4632                 }
4633                 break;
4634
4635         case REALM_MUSIC: /* Music */
4636                 switch (spell)
4637                 {
4638                 case 2 : sprintf(p, " %s%dd4", s_dam, 4 + ((plev - 1) / 5)); break;
4639                 case 4 : sprintf(p, " %s2d6", s_heal); break;
4640                 case 9 : sprintf(p, " %sd%d", s_dam, plev * 3 / 2); break;
4641                 case 13: sprintf(p, " %s%dd7", s_dam, 10 + (plev / 5)); break;
4642                 case 20: sprintf(p, " %sd%d+d%d", s_dam, plev * 3, plev * 3); break;
4643                 case 22: sprintf(p, " %s%dd10", s_dam, 15 + ((plev - 1) / 2)); break;
4644                 case 27: sprintf(p, " %sd%d", s_dam, plev * 3); break;
4645                 case 28: sprintf(p, " %s15d10", s_heal); break;
4646                 case 30: sprintf(p, " %s%dd10", s_dam, 50 + plev); break;
4647                 }
4648                 break;
4649         default:
4650 #ifdef JP
4651                 sprintf(p, "̤ÃΤΥ¿¥¤¥×: %d", use_realm);
4652 #else
4653                 sprintf(p, "Unknown type: %d.", use_realm);
4654 #endif
4655         }
4656 }
4657
4658
4659 /*
4660  * Print a list of spells (for browsing or casting or viewing)
4661  */
4662 void print_spells(int target_spell, byte *spells, int num, int y, int x, int use_realm)
4663 {
4664         int             i, spell, exp_level, increment = 64;
4665         magic_type      *s_ptr;
4666         cptr            comment;
4667         char            info[80];
4668         char            out_val[160];
4669         byte            line_attr;
4670         int             need_mana;
4671         char            ryakuji[5];
4672         char            buf[256];
4673         bool max = FALSE;
4674
4675
4676         if (((use_realm <= REALM_NONE) || (use_realm > MAX_REALM)) && p_ptr->wizard)
4677 #ifdef JP
4678 msg_print("·Ù¹ð¡ª print_spell ¤¬Îΰè¤Ê¤·¤Ë¸Æ¤Ð¤ì¤¿");
4679 #else
4680                 msg_print("Warning! print_spells called with null realm");
4681 #endif
4682
4683
4684         /* Title the list */
4685         prt("", y, x);
4686         if (use_realm == REALM_HISSATSU)
4687 #ifdef JP
4688                 strcpy(buf,"  Lv   MP");
4689 #else
4690                 strcpy(buf,"  Lv   SP");
4691 #endif
4692         else
4693 #ifdef JP
4694                 strcpy(buf,"½ÏÎýÅÙ Lv   MP ¼ºÎ¨ ¸ú²Ì");
4695 #else
4696                 strcpy(buf,"Profic Lv   SP Fail Effect");
4697 #endif
4698
4699 #ifdef JP
4700 put_str("̾Á°", y, x + 5);
4701 put_str(buf, y, x + 29);
4702 #else
4703         put_str("Name", y, x + 5);
4704         put_str(buf, y, x + 29);
4705 #endif
4706
4707         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) increment = 0;
4708         else if (use_realm == p_ptr->realm1) increment = 0;
4709         else if (use_realm == p_ptr->realm2) increment = 32;
4710
4711         /* Dump the spells */
4712         for (i = 0; i < num; i++)
4713         {
4714                 /* Access the spell */
4715                 spell = spells[i];
4716
4717                 /* Access the spell */
4718                 if (!is_magic(use_realm))
4719                 {
4720                         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4721                 }
4722                 else
4723                 {
4724                         s_ptr = &mp_ptr->info[use_realm - 1][spell];
4725                 }
4726
4727                 if (use_realm == REALM_HISSATSU)
4728                         need_mana = s_ptr->smana;
4729                 else
4730                 {
4731                         s16b exp = experience_of_spell(spell, use_realm);
4732
4733                         /* Extract mana consumption rate */
4734                         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
4735
4736                         if ((increment == 64) || (s_ptr->slevel >= 99)) exp_level = EXP_LEVEL_UNSKILLED;
4737                         else exp_level = spell_exp_level(exp);
4738
4739                         max = FALSE;
4740                         if (!increment && (exp_level == EXP_LEVEL_MASTER)) max = TRUE;
4741                         else if ((increment == 32) && (exp_level >= EXP_LEVEL_EXPERT)) max = TRUE;
4742                         else if (s_ptr->slevel >= 99) max = TRUE;
4743                         else if ((p_ptr->pclass == CLASS_RED_MAGE) && (exp_level >= EXP_LEVEL_SKILLED)) max = TRUE;
4744
4745                         strncpy(ryakuji, exp_level_str[exp_level], 4);
4746                         ryakuji[3] = ']';
4747                         ryakuji[4] = '\0';
4748                 }
4749
4750                 if (use_menu && target_spell)
4751                 {
4752                         if (i == (target_spell-1))
4753 #ifdef JP
4754                                 strcpy(out_val, "  ¡Õ ");
4755 #else
4756                                 strcpy(out_val, "  >  ");
4757 #endif
4758                         else
4759                                 strcpy(out_val, "     ");
4760                 }
4761                 else sprintf(out_val, "  %c) ", I2A(i));
4762                 /* Skip illegible spells */
4763                 if (s_ptr->slevel >= 99)
4764                 {
4765 #ifdef JP
4766 strcat(out_val, format("%-30s", "(ȽÆÉÉÔǽ)"));
4767 #else
4768                                 strcat(out_val, format("%-30s", "(illegible)"));
4769 #endif
4770
4771                                 c_prt(TERM_L_DARK, out_val, y + i + 1, x);
4772                                 continue;
4773                 }
4774
4775                 /* XXX XXX Could label spells above the players level */
4776
4777                 /* Get extra info */
4778                 spell_info(info, spell, use_realm);
4779
4780                 /* Use that info */
4781                 comment = info;
4782
4783                 /* Assume spell is known and tried */
4784                 line_attr = TERM_WHITE;
4785
4786                 /* Analyze the spell */
4787                 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4788                 {
4789                         if (s_ptr->slevel > p_ptr->max_plv)
4790                         {
4791 #ifdef JP
4792 comment = " Ì¤ÃÎ";
4793 #else
4794                                 comment = " unknown";
4795 #endif
4796
4797                                 line_attr = TERM_L_BLUE;
4798                         }
4799                         else if (s_ptr->slevel > p_ptr->lev)
4800                         {
4801 #ifdef JP
4802 comment = " ËºµÑ";
4803 #else
4804                                 comment = " forgotten";
4805 #endif
4806
4807                                 line_attr = TERM_YELLOW;
4808                         }
4809                 }
4810                 else if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2))
4811                 {
4812 #ifdef JP
4813 comment = " Ì¤ÃÎ";
4814 #else
4815                         comment = " unknown";
4816 #endif
4817
4818                         line_attr = TERM_L_BLUE;
4819                 }
4820                 else if ((use_realm == p_ptr->realm1) ?
4821                     ((p_ptr->spell_forgotten1 & (1L << spell))) :
4822                     ((p_ptr->spell_forgotten2 & (1L << spell))))
4823                 {
4824 #ifdef JP
4825 comment = " ËºµÑ";
4826 #else
4827                         comment = " forgotten";
4828 #endif
4829
4830                         line_attr = TERM_YELLOW;
4831                 }
4832                 else if (!((use_realm == p_ptr->realm1) ?
4833                     (p_ptr->spell_learned1 & (1L << spell)) :
4834                     (p_ptr->spell_learned2 & (1L << spell))))
4835                 {
4836 #ifdef JP
4837 comment = " Ì¤ÃÎ";
4838 #else
4839                         comment = " unknown";
4840 #endif
4841
4842                         line_attr = TERM_L_BLUE;
4843                 }
4844                 else if (!((use_realm == p_ptr->realm1) ?
4845                     (p_ptr->spell_worked1 & (1L << spell)) :
4846                     (p_ptr->spell_worked2 & (1L << spell))))
4847                 {
4848 #ifdef JP
4849 comment = " Ì¤·Ð¸³";
4850 #else
4851                         comment = " untried";
4852 #endif
4853
4854                         line_attr = TERM_L_GREEN;
4855                 }
4856
4857                 /* Dump the spell --(-- */
4858                 if (use_realm == REALM_HISSATSU)
4859                 {
4860                         strcat(out_val, format("%-25s %2d %4d",
4861                             spell_names[technic2magic(use_realm)-1][spell], /* realm, spell */
4862                             s_ptr->slevel, need_mana));
4863                 }
4864                 else
4865                 {
4866                         strcat(out_val, format("%-25s%c%-4s %2d %4d %3d%%%s",
4867                             spell_names[technic2magic(use_realm)-1][spell], /* realm, spell */
4868                             (max ? '!' : ' '), ryakuji,
4869                             s_ptr->slevel, need_mana, spell_chance(spell, use_realm), comment));
4870                 }
4871                 c_prt(line_attr, out_val, y + i + 1, x);
4872         }
4873
4874         /* Clear the bottom line */
4875         prt("", y + i + 1, x);
4876 }
4877
4878
4879 /*
4880  * Note that amulets, rods, and high-level spell books are immune
4881  * to "inventory damage" of any kind.  Also sling ammo and shovels.
4882  */
4883
4884
4885 /*
4886  * Does a given class of objects (usually) hate acid?
4887  * Note that acid can either melt or corrode something.
4888  */
4889 bool hates_acid(object_type *o_ptr)
4890 {
4891         /* Analyze the type */
4892         switch (o_ptr->tval)
4893         {
4894                 /* Wearable items */
4895                 case TV_ARROW:
4896                 case TV_BOLT:
4897                 case TV_BOW:
4898                 case TV_SWORD:
4899                 case TV_HAFTED:
4900                 case TV_POLEARM:
4901                 case TV_HELM:
4902                 case TV_CROWN:
4903                 case TV_SHIELD:
4904                 case TV_BOOTS:
4905                 case TV_GLOVES:
4906                 case TV_CLOAK:
4907                 case TV_SOFT_ARMOR:
4908                 case TV_HARD_ARMOR:
4909                 case TV_DRAG_ARMOR:
4910                 {
4911                         return (TRUE);
4912                 }
4913
4914                 /* Staffs/Scrolls are wood/paper */
4915                 case TV_STAFF:
4916                 case TV_SCROLL:
4917                 {
4918                         return (TRUE);
4919                 }
4920
4921                 /* Ouch */
4922                 case TV_CHEST:
4923                 {
4924                         return (TRUE);
4925                 }
4926
4927                 /* Junk is useless */
4928                 case TV_SKELETON:
4929                 case TV_BOTTLE:
4930                 case TV_JUNK:
4931                 {
4932                         return (TRUE);
4933                 }
4934         }
4935
4936         return (FALSE);
4937 }
4938
4939
4940 /*
4941  * Does a given object (usually) hate electricity?
4942  */
4943 bool hates_elec(object_type *o_ptr)
4944 {
4945         switch (o_ptr->tval)
4946         {
4947                 case TV_RING:
4948                 case TV_WAND:
4949                 {
4950                         return (TRUE);
4951                 }
4952         }
4953
4954         return (FALSE);
4955 }
4956
4957
4958 /*
4959  * Does a given object (usually) hate fire?
4960  * Hafted/Polearm weapons have wooden shafts.
4961  * Arrows/Bows are mostly wooden.
4962  */
4963 bool hates_fire(object_type *o_ptr)
4964 {
4965         /* Analyze the type */
4966         switch (o_ptr->tval)
4967         {
4968                 /* Wearable */
4969                 case TV_LITE:
4970                 case TV_ARROW:
4971                 case TV_BOW:
4972                 case TV_HAFTED:
4973                 case TV_POLEARM:
4974                 case TV_BOOTS:
4975                 case TV_GLOVES:
4976                 case TV_CLOAK:
4977                 case TV_SOFT_ARMOR:
4978                 {
4979                         return (TRUE);
4980                 }
4981
4982                 /* Books */
4983                 case TV_LIFE_BOOK:
4984                 case TV_SORCERY_BOOK:
4985                 case TV_NATURE_BOOK:
4986                 case TV_CHAOS_BOOK:
4987                 case TV_DEATH_BOOK:
4988                 case TV_TRUMP_BOOK:
4989                 case TV_ARCANE_BOOK:
4990                 case TV_ENCHANT_BOOK:
4991                 case TV_DAEMON_BOOK:
4992                 case TV_CRUSADE_BOOK:
4993                 case TV_MUSIC_BOOK:
4994                 case TV_HISSATSU_BOOK:
4995                 {
4996                         return (TRUE);
4997                 }
4998
4999                 /* Chests */
5000                 case TV_CHEST:
5001                 {
5002                         return (TRUE);
5003                 }
5004
5005                 /* Staffs/Scrolls burn */
5006                 case TV_STAFF:
5007                 case TV_SCROLL:
5008                 {
5009                         return (TRUE);
5010                 }
5011         }
5012
5013         return (FALSE);
5014 }
5015
5016
5017 /*
5018  * Does a given object (usually) hate cold?
5019  */
5020 bool hates_cold(object_type *o_ptr)
5021 {
5022         switch (o_ptr->tval)
5023         {
5024                 case TV_POTION:
5025                 case TV_FLASK:
5026                 case TV_BOTTLE:
5027                 {
5028                         return (TRUE);
5029                 }
5030         }
5031
5032         return (FALSE);
5033 }
5034
5035
5036 /*
5037  * Melt something
5038  */
5039 int set_acid_destroy(object_type *o_ptr)
5040 {
5041         u32b flgs[TR_FLAG_SIZE];
5042         if (!hates_acid(o_ptr)) return (FALSE);
5043         object_flags(o_ptr, flgs);
5044         if (have_flag(flgs, TR_IGNORE_ACID)) return (FALSE);
5045         return (TRUE);
5046 }
5047
5048
5049 /*
5050  * Electrical damage
5051  */
5052 int set_elec_destroy(object_type *o_ptr)
5053 {
5054         u32b flgs[TR_FLAG_SIZE];
5055         if (!hates_elec(o_ptr)) return (FALSE);
5056         object_flags(o_ptr, flgs);
5057         if (have_flag(flgs, TR_IGNORE_ELEC)) return (FALSE);
5058         return (TRUE);
5059 }
5060
5061
5062 /*
5063  * Burn something
5064  */
5065 int set_fire_destroy(object_type *o_ptr)
5066 {
5067         u32b flgs[TR_FLAG_SIZE];
5068         if (!hates_fire(o_ptr)) return (FALSE);
5069         object_flags(o_ptr, flgs);
5070         if (have_flag(flgs, TR_IGNORE_FIRE)) return (FALSE);
5071         return (TRUE);
5072 }
5073
5074
5075 /*
5076  * Freeze things
5077  */
5078 int set_cold_destroy(object_type *o_ptr)
5079 {
5080         u32b flgs[TR_FLAG_SIZE];
5081         if (!hates_cold(o_ptr)) return (FALSE);
5082         object_flags(o_ptr, flgs);
5083         if (have_flag(flgs, TR_IGNORE_COLD)) return (FALSE);
5084         return (TRUE);
5085 }
5086
5087
5088 /*
5089  * Destroys a type of item on a given percent chance
5090  * Note that missiles are no longer necessarily all destroyed
5091  * Destruction taken from "melee.c" code for "stealing".
5092  * New-style wands and rods handled correctly. -LM-
5093  * Returns number of items destroyed.
5094  */
5095 int inven_damage(inven_func typ, int perc)
5096 {
5097         int         i, j, k, amt;
5098         object_type *o_ptr;
5099         char        o_name[MAX_NLEN];
5100
5101         /* Multishadow effects is determined by turn */
5102         if( p_ptr->multishadow && (turn & 1) )return 0;
5103
5104         if (p_ptr->inside_arena) return 0;
5105
5106         /* Count the casualties */
5107         k = 0;
5108
5109         /* Scan through the slots backwards */
5110         for (i = 0; i < INVEN_PACK; i++)
5111         {
5112                 o_ptr = &inventory[i];
5113
5114                 /* Skip non-objects */
5115                 if (!o_ptr->k_idx) continue;
5116
5117                 /* Hack -- for now, skip artifacts */
5118                 if (artifact_p(o_ptr) || o_ptr->art_name) continue;
5119
5120                 /* Give this item slot a shot at death */
5121                 if ((*typ)(o_ptr))
5122                 {
5123                         /* Count the casualties */
5124                         for (amt = j = 0; j < o_ptr->number; ++j)
5125                         {
5126                                 if (randint0(100) < perc) amt++;
5127                         }
5128
5129                         /* Some casualities */
5130                         if (amt)
5131                         {
5132                                 /* Get a description */
5133                                 object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
5134
5135                                 /* Message */
5136 #ifdef JP
5137 msg_format("%s(%c)¤¬%s²õ¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª",
5138 #else
5139                                 msg_format("%sour %s (%c) %s destroyed!",
5140 #endif
5141
5142 #ifdef JP
5143 o_name, index_to_label(i),
5144     ((o_ptr->number > 1) ?
5145     ((amt == o_ptr->number) ? "Á´Éô" :
5146     (amt > 1 ? "²¿¸Ä¤«" : "°ì¸Ä")) : "")    );
5147 #else
5148                                     ((o_ptr->number > 1) ?
5149                                     ((amt == o_ptr->number) ? "All of y" :
5150                                     (amt > 1 ? "Some of y" : "One of y")) : "Y"),
5151                                     o_name, index_to_label(i),
5152                                     ((amt > 1) ? "were" : "was"));
5153 #endif
5154
5155 #ifdef JP
5156                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
5157                                         msg_print("¤ä¤ê¤ä¤¬¤Ã¤¿¤Ê¡ª");
5158 #endif
5159
5160                                 /* Potions smash open */
5161                                 if (object_is_potion(o_ptr))
5162                                 {
5163                                         (void)potion_smash_effect(0, py, px, o_ptr->k_idx);
5164                                 }
5165
5166                                 /* Reduce the charges of rods/wands */
5167                                 reduce_charges(o_ptr, amt);
5168
5169                                 /* Destroy "amt" items */
5170                                 inven_item_increase(i, -amt);
5171                                 inven_item_optimize(i);
5172
5173                                 /* Count the casualties */
5174                                 k += amt;
5175                         }
5176                 }
5177         }
5178
5179         /* Return the casualty count */
5180         return (k);
5181 }
5182
5183
5184 /*
5185  * Acid has hit the player, attempt to affect some armor.
5186  *
5187  * Note that the "base armor" of an object never changes.
5188  *
5189  * If any armor is damaged (or resists), the player takes less damage.
5190  */
5191 static int minus_ac(void)
5192 {
5193         object_type *o_ptr = NULL;
5194         u32b flgs[TR_FLAG_SIZE];
5195         char        o_name[MAX_NLEN];
5196
5197
5198         /* Pick a (possibly empty) inventory slot */
5199         switch (randint1(7))
5200         {
5201                 case 1: o_ptr = &inventory[INVEN_RARM]; break;
5202                 case 2: o_ptr = &inventory[INVEN_LARM]; break;
5203                 case 3: o_ptr = &inventory[INVEN_BODY]; break;
5204                 case 4: o_ptr = &inventory[INVEN_OUTER]; break;
5205                 case 5: o_ptr = &inventory[INVEN_HANDS]; break;
5206                 case 6: o_ptr = &inventory[INVEN_HEAD]; break;
5207                 case 7: o_ptr = &inventory[INVEN_FEET]; break;
5208         }
5209
5210         /* Nothing to damage */
5211         if (!o_ptr->k_idx) return (FALSE);
5212
5213         if (o_ptr->tval <= TV_WEAPON_END) return (FALSE);
5214
5215         /* No damage left to be done */
5216         if (o_ptr->ac + o_ptr->to_a <= 0) return (FALSE);
5217
5218
5219         /* Describe */
5220         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
5221
5222         /* Extract the flags */
5223         object_flags(o_ptr, flgs);
5224
5225         /* Object resists */
5226         if (have_flag(flgs, TR_IGNORE_ACID))
5227         {
5228 #ifdef JP
5229 msg_format("¤·¤«¤·%s¤Ë¤Ï¸ú²Ì¤¬¤Ê¤«¤Ã¤¿¡ª", o_name);
5230 #else
5231                 msg_format("Your %s is unaffected!", o_name);
5232 #endif
5233
5234
5235                 return (TRUE);
5236         }
5237
5238         /* Message */
5239 #ifdef JP
5240 msg_format("%s¤¬¥À¥á¡¼¥¸¤ò¼õ¤±¤¿¡ª", o_name);
5241 #else
5242         msg_format("Your %s is damaged!", o_name);
5243 #endif
5244
5245
5246         /* Damage the item */
5247         o_ptr->to_a--;
5248
5249         /* Calculate bonuses */
5250         p_ptr->update |= (PU_BONUS);
5251
5252         /* Window stuff */
5253         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
5254
5255         calc_android_exp();
5256
5257         /* Item was damaged */
5258         return (TRUE);
5259 }
5260
5261
5262 /*
5263  * Hurt the player with Acid
5264  */
5265 int acid_dam(int dam, cptr kb_str, int monspell)
5266 {
5267         int get_damage;  
5268         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5269         bool double_resist = IS_OPPOSE_ACID();
5270
5271         /* Total Immunity */
5272         if (p_ptr->immune_acid || (dam <= 0))
5273         {
5274                 learn_spell(monspell);
5275                 return 0;
5276         }
5277
5278         /* Vulnerability (Ouch!) */
5279         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5280         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5281
5282         /* Resist the damage */
5283         if (p_ptr->resist_acid) dam = (dam + 2) / 3;
5284         if (double_resist) dam = (dam + 2) / 3;
5285
5286         if ((!(double_resist || p_ptr->resist_acid)) &&
5287             one_in_(HURT_CHANCE))
5288                 (void)do_dec_stat(A_CHR);
5289
5290         /* If any armor gets hit, defend the player */
5291         if (minus_ac()) dam = (dam + 1) / 2;
5292
5293         /* Take damage */
5294         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5295
5296         /* Inventory damage */
5297         if (!(double_resist && p_ptr->resist_acid))
5298                 inven_damage(set_acid_destroy, inv);
5299         return get_damage;
5300 }
5301
5302
5303 /*
5304  * Hurt the player with electricity
5305  */
5306 int elec_dam(int dam, cptr kb_str, int monspell)
5307 {
5308         int get_damage;  
5309         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5310         bool double_resist = IS_OPPOSE_ELEC();
5311
5312         /* Total immunity */
5313         if (p_ptr->immune_elec || (dam <= 0))
5314         {
5315                 learn_spell(monspell);
5316                 return 0;
5317         }
5318
5319         /* Vulnerability (Ouch!) */
5320         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5321         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5322         if (prace_is_(RACE_ANDROID)) dam += dam / 3;
5323
5324         /* Resist the damage */
5325         if (p_ptr->resist_elec) dam = (dam + 2) / 3;
5326         if (double_resist) dam = (dam + 2) / 3;
5327
5328         if ((!(double_resist || p_ptr->resist_elec)) &&
5329             one_in_(HURT_CHANCE))
5330                 (void)do_dec_stat(A_DEX);
5331
5332         /* Take damage */
5333         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5334
5335         /* Inventory damage */
5336         if (!(double_resist && p_ptr->resist_elec))
5337                 inven_damage(set_elec_destroy, inv);
5338
5339         return get_damage;
5340 }
5341
5342
5343 /*
5344  * Hurt the player with Fire
5345  */
5346 int fire_dam(int dam, cptr kb_str, int monspell)
5347 {
5348         int get_damage;  
5349         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5350         bool double_resist = IS_OPPOSE_FIRE();
5351
5352         /* Totally immune */
5353         if (p_ptr->immune_fire || (dam <= 0))
5354         {
5355                 learn_spell(monspell);
5356                 return 0;
5357         }
5358
5359         /* Vulnerability (Ouch!) */
5360         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5361         if (prace_is_(RACE_ENT)) dam += dam / 3;
5362         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5363
5364         /* Resist the damage */
5365         if (p_ptr->resist_fire) dam = (dam + 2) / 3;
5366         if (double_resist) dam = (dam + 2) / 3;
5367
5368         if ((!(double_resist || p_ptr->resist_fire)) &&
5369             one_in_(HURT_CHANCE))
5370                 (void)do_dec_stat(A_STR);
5371
5372         /* Take damage */
5373         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5374
5375         /* Inventory damage */
5376         if (!(double_resist && p_ptr->resist_fire))
5377                 inven_damage(set_fire_destroy, inv);
5378
5379         return get_damage;
5380 }
5381
5382
5383 /*
5384  * Hurt the player with Cold
5385  */
5386 int cold_dam(int dam, cptr kb_str, int monspell)
5387 {
5388         int get_damage;  
5389         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5390         bool double_resist = IS_OPPOSE_COLD();
5391
5392         /* Total immunity */
5393         if (p_ptr->immune_cold || (dam <= 0))
5394         {
5395                 learn_spell(monspell);
5396                 return 0;
5397         }
5398
5399         /* Vulnerability (Ouch!) */
5400         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5401         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5402
5403         /* Resist the damage */
5404         if (p_ptr->resist_cold) dam = (dam + 2) / 3;
5405         if (double_resist) dam = (dam + 2) / 3;
5406
5407         if ((!(double_resist || p_ptr->resist_cold)) &&
5408             one_in_(HURT_CHANCE))
5409                 (void)do_dec_stat(A_STR);
5410
5411         /* Take damage */
5412         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5413
5414         /* Inventory damage */
5415         if (!(double_resist && p_ptr->resist_cold))
5416                 inven_damage(set_cold_destroy, inv);
5417
5418         return get_damage;
5419 }
5420
5421
5422 bool rustproof(void)
5423 {
5424         int         item;
5425         object_type *o_ptr;
5426         char        o_name[MAX_NLEN];
5427         cptr        q, s;
5428
5429         item_tester_no_ryoute = TRUE;
5430         /* Select a piece of armour */
5431         item_tester_hook = item_tester_hook_armour;
5432
5433         /* Get an item */
5434 #ifdef JP
5435 q = "¤É¤ÎËɶñ¤Ë»¬»ß¤á¤ò¤·¤Þ¤¹¤«¡©";
5436 s = "»¬»ß¤á¤Ç¤­¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£";
5437 #else
5438         q = "Rustproof which piece of armour? ";
5439         s = "You have nothing to rustproof.";
5440 #endif
5441
5442         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return FALSE;
5443
5444         /* Get the item (in the pack) */
5445         if (item >= 0)
5446         {
5447                 o_ptr = &inventory[item];
5448         }
5449
5450         /* Get the item (on the floor) */
5451         else
5452         {
5453                 o_ptr = &o_list[0 - item];
5454         }
5455
5456
5457         /* Description */
5458         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
5459
5460         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
5461
5462         if ((o_ptr->to_a < 0) && !cursed_p(o_ptr))
5463         {
5464 #ifdef JP
5465 msg_format("%s¤Ï¿·ÉÊƱÍͤˤʤä¿¡ª",o_name);
5466 #else
5467                 msg_format("%s %s look%s as good as new!",
5468                         ((item >= 0) ? "Your" : "The"), o_name,
5469                         ((o_ptr->number > 1) ? "" : "s"));
5470 #endif
5471
5472                 o_ptr->to_a = 0;
5473         }
5474
5475 #ifdef JP
5476 msg_format("%s¤ÏÉå¿©¤·¤Ê¤¯¤Ê¤Ã¤¿¡£", o_name);
5477 #else
5478         msg_format("%s %s %s now protected against corrosion.",
5479                 ((item >= 0) ? "Your" : "The"), o_name,
5480                 ((o_ptr->number > 1) ? "are" : "is"));
5481 #endif
5482
5483
5484         calc_android_exp();
5485
5486         return TRUE;
5487 }
5488
5489
5490 /*
5491  * Curse the players armor
5492  */
5493 bool curse_armor(void)
5494 {
5495         int i;
5496         object_type *o_ptr;
5497
5498         char o_name[MAX_NLEN];
5499
5500
5501         /* Curse the body armor */
5502         o_ptr = &inventory[INVEN_BODY];
5503
5504         /* Nothing to curse */
5505         if (!o_ptr->k_idx) return (FALSE);
5506
5507
5508         /* Describe */
5509         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
5510
5511         /* Attempt a saving throw for artifacts */
5512         if ((o_ptr->art_name || artifact_p(o_ptr)) && (randint0(100) < 50))
5513         {
5514                 /* Cool */
5515 #ifdef JP
5516 msg_format("%s¤¬%s¤òÊñ¤ß¹þ¤â¤¦¤È¤·¤¿¤¬¡¢%s¤Ï¤½¤ì¤òÄ·¤ÍÊÖ¤·¤¿¡ª",
5517 "¶²ÉݤΰŹõ¥ª¡¼¥é", "Ëɶñ", o_name);
5518 #else
5519                 msg_format("A %s tries to %s, but your %s resists the effects!",
5520                            "terrible black aura", "surround your armor", o_name);
5521 #endif
5522
5523         }
5524
5525         /* not artifact or failed save... */
5526         else
5527         {
5528                 /* Oops */
5529 #ifdef JP
5530 msg_format("¶²ÉݤΰŹõ¥ª¡¼¥é¤¬¤¢¤Ê¤¿¤Î%s¤òÊñ¤ß¹þ¤ó¤À¡ª", o_name);
5531 #else
5532                 msg_format("A terrible black aura blasts your %s!", o_name);
5533 #endif
5534
5535                 chg_virtue(V_ENCHANT, -5);
5536
5537                 /* Blast the armor */
5538                 o_ptr->name1 = 0;
5539                 o_ptr->name2 = EGO_BLASTED;
5540                 o_ptr->to_a = 0 - randint1(5) - randint1(5);
5541                 o_ptr->to_h = 0;
5542                 o_ptr->to_d = 0;
5543                 o_ptr->ac = 0;
5544                 o_ptr->dd = 0;
5545                 o_ptr->ds = 0;
5546
5547                 for (i = 0; i < TR_FLAG_SIZE; i++)
5548                         o_ptr->art_flags[i] = 0;
5549
5550                 /* Curse it */
5551                 o_ptr->curse_flags = TRC_CURSED;
5552
5553                 /* Break it */
5554                 o_ptr->ident |= (IDENT_BROKEN);
5555
5556                 /* Recalculate bonuses */
5557                 p_ptr->update |= (PU_BONUS);
5558
5559                 /* Recalculate mana */
5560                 p_ptr->update |= (PU_MANA);
5561
5562                 /* Window stuff */
5563                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
5564         }
5565
5566         return (TRUE);
5567 }
5568
5569
5570 /*
5571  * Curse the players weapon
5572  */
5573 bool curse_weapon(bool force, int slot)
5574 {
5575         int i;
5576
5577         object_type *o_ptr;
5578
5579         char o_name[MAX_NLEN];
5580
5581
5582         /* Curse the weapon */
5583         o_ptr = &inventory[slot];
5584
5585         /* Nothing to curse */
5586         if (!o_ptr->k_idx) return (FALSE);
5587
5588
5589         /* Describe */
5590         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
5591
5592         /* Attempt a saving throw */
5593         if ((artifact_p(o_ptr) || o_ptr->art_name) && (randint0(100) < 50) && !force)
5594         {
5595                 /* Cool */
5596 #ifdef JP
5597 msg_format("%s¤¬%s¤òÊñ¤ß¹þ¤â¤¦¤È¤·¤¿¤¬¡¢%s¤Ï¤½¤ì¤òÄ·¤ÍÊÖ¤·¤¿¡ª",
5598 "¶²ÉݤΰŹõ¥ª¡¼¥é", "Éð´ï", o_name);
5599 #else
5600                 msg_format("A %s tries to %s, but your %s resists the effects!",
5601                            "terrible black aura", "surround your weapon", o_name);
5602 #endif
5603
5604         }
5605
5606         /* not artifact or failed save... */
5607         else
5608         {
5609                 /* Oops */
5610 #ifdef JP
5611 if (!force) msg_format("¶²ÉݤΰŹõ¥ª¡¼¥é¤¬¤¢¤Ê¤¿¤Î%s¤òÊñ¤ß¹þ¤ó¤À¡ª", o_name);
5612 #else
5613                 if (!force) msg_format("A terrible black aura blasts your %s!", o_name);
5614 #endif
5615
5616                 chg_virtue(V_ENCHANT, -5);
5617
5618                 /* Shatter the weapon */
5619                 o_ptr->name1 = 0;
5620                 o_ptr->name2 = EGO_SHATTERED;
5621                 o_ptr->to_h = 0 - randint1(5) - randint1(5);
5622                 o_ptr->to_d = 0 - randint1(5) - randint1(5);
5623                 o_ptr->to_a = 0;
5624                 o_ptr->ac = 0;
5625                 o_ptr->dd = 0;
5626                 o_ptr->ds = 0;
5627
5628                 for (i = 0; i < TR_FLAG_SIZE; i++)
5629                         o_ptr->art_flags[i] = 0;
5630
5631
5632                 /* Curse it */
5633                 o_ptr->curse_flags = TRC_CURSED;
5634
5635                 /* Break it */
5636                 o_ptr->ident |= (IDENT_BROKEN);
5637
5638                 /* Recalculate bonuses */
5639                 p_ptr->update |= (PU_BONUS);
5640
5641                 /* Recalculate mana */
5642                 p_ptr->update |= (PU_MANA);
5643
5644                 /* Window stuff */
5645                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
5646         }
5647
5648         /* Notice */
5649         return (TRUE);
5650 }
5651
5652
5653 /*
5654  * Enchant some bolts
5655  */
5656 bool brand_bolts(void)
5657 {
5658         int i;
5659
5660         /* Use the first acceptable bolts */
5661         for (i = 0; i < INVEN_PACK; i++)
5662         {
5663                 object_type *o_ptr = &inventory[i];
5664
5665                 /* Skip non-bolts */
5666                 if (o_ptr->tval != TV_BOLT) continue;
5667
5668                 /* Skip artifacts and ego-items */
5669                 if (o_ptr->art_name || artifact_p(o_ptr) || ego_item_p(o_ptr))
5670                         continue;
5671
5672                 /* Skip cursed/broken items */
5673                 if (cursed_p(o_ptr) || broken_p(o_ptr)) continue;
5674
5675                 /* Randomize */
5676                 if (randint0(100) < 75) continue;
5677
5678                 /* Message */
5679 #ifdef JP
5680 msg_print("¥¯¥í¥¹¥Ü¥¦¤ÎÌ𤬱ê¤Î¥ª¡¼¥é¤ËÊñ¤Þ¤ì¤¿¡ª");
5681 #else
5682                 msg_print("Your bolts are covered in a fiery aura!");
5683 #endif
5684
5685
5686                 /* Ego-item */
5687                 o_ptr->name2 = EGO_FLAME;
5688
5689                 /* Enchant */
5690                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
5691
5692                 /* Notice */
5693                 return (TRUE);
5694         }
5695
5696         /* Flush */
5697         if (flush_failure) flush();
5698
5699         /* Fail */
5700 #ifdef JP
5701 msg_print("±ê¤Ç¶¯²½¤¹¤ë¤Î¤Ë¼ºÇÔ¤·¤¿¡£");
5702 #else
5703         msg_print("The fiery enchantment failed.");
5704 #endif
5705
5706
5707         /* Notice */
5708         return (TRUE);
5709 }
5710
5711
5712 /*
5713  * Helper function -- return a "nearby" race for polymorphing
5714  *
5715  * Note that this function is one of the more "dangerous" ones...
5716  */
5717 static s16b poly_r_idx(int r_idx)
5718 {
5719         monster_race *r_ptr = &r_info[r_idx];
5720
5721         int i, r, lev1, lev2;
5722
5723         /* Hack -- Uniques/Questors never polymorph */
5724         if ((r_ptr->flags1 & RF1_UNIQUE) ||
5725             (r_ptr->flags1 & RF1_QUESTOR))
5726                 return (r_idx);
5727
5728         /* Allowable range of "levels" for resulting monster */
5729         lev1 = r_ptr->level - ((randint1(20) / randint1(9)) + 1);
5730         lev2 = r_ptr->level + ((randint1(20) / randint1(9)) + 1);
5731
5732         /* Pick a (possibly new) non-unique race */
5733         for (i = 0; i < 1000; i++)
5734         {
5735                 /* Pick a new race, using a level calculation */
5736                 r = get_mon_num((dun_level + r_ptr->level) / 2 + 5);
5737
5738                 /* Handle failure */
5739                 if (!r) break;
5740
5741                 /* Obtain race */
5742                 r_ptr = &r_info[r];
5743
5744                 /* Ignore unique monsters */
5745                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
5746
5747                 /* Ignore monsters with incompatible levels */
5748                 if ((r_ptr->level < lev1) || (r_ptr->level > lev2)) continue;
5749
5750                 /* Use that index */
5751                 r_idx = r;
5752
5753                 /* Done */
5754                 break;
5755         }
5756
5757         /* Result */
5758         return (r_idx);
5759 }
5760
5761
5762 bool polymorph_monster(int y, int x)
5763 {
5764         cave_type *c_ptr = &cave[y][x];
5765         monster_type *m_ptr = &m_list[c_ptr->m_idx];
5766         bool polymorphed = FALSE;
5767         int new_r_idx;
5768         int old_r_idx = m_ptr->r_idx;
5769         bool targeted = (target_who == c_ptr->m_idx) ? TRUE : FALSE;
5770         bool health_tracked = (p_ptr->health_who == c_ptr->m_idx) ? TRUE : FALSE;
5771         monster_type back_m;
5772
5773         if (p_ptr->inside_arena || p_ptr->inside_battle) return (FALSE);
5774
5775         if ((p_ptr->riding == c_ptr->m_idx) || (m_ptr->mflag2 & MFLAG2_KAGE)) return (FALSE);
5776
5777         /* Memorize the monster before polymorphing */
5778         back_m = *m_ptr;
5779
5780         /* Pick a "new" monster race */
5781         new_r_idx = poly_r_idx(old_r_idx);
5782
5783         /* Handle polymorph */
5784         if (new_r_idx != old_r_idx)
5785         {
5786                 u32b mode = 0L;
5787
5788                 /* Get the monsters attitude */
5789                 if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
5790                 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
5791                 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
5792
5793                 /* "Kill" the "old" monster */
5794                 delete_monster_idx(c_ptr->m_idx);
5795
5796                 /* Create a new monster (no groups) */
5797                 if (place_monster_aux(0, y, x, new_r_idx, mode))
5798                 {
5799                         /* Success */
5800                         polymorphed = TRUE;
5801                 }
5802                 else
5803                 {
5804                         /* Placing the new monster failed */
5805                         if (place_monster_aux(0, y, x, old_r_idx, (mode | PM_NO_KAGE | PM_IGNORE_TERRAIN)))
5806                                 m_list[hack_m_idx_ii] = back_m;
5807                 }
5808
5809                 if (targeted) target_who = hack_m_idx_ii;
5810                 if (health_tracked) health_track(hack_m_idx_ii);
5811         }
5812
5813         return polymorphed;
5814 }
5815
5816
5817 /*
5818  * Dimension Door
5819  */
5820 static bool dimension_door_aux(int x, int y)
5821 {
5822         int     plev = p_ptr->lev;
5823
5824         p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
5825
5826         if (!cave_teleportable_bold(y, x) ||
5827             (distance(y, x, py, px) > plev / 2 + 10) ||
5828             (!randint0(plev / 10 + 10)))
5829         {
5830                 p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
5831                 teleport_player((plev+2)*2);
5832
5833                 /* Failed */
5834                 return FALSE;
5835         }
5836         else
5837         {
5838                 teleport_player_to(y, x, TRUE);
5839
5840                 /* Success */
5841                 return TRUE;
5842         }
5843 }
5844
5845
5846 /*
5847  * Dimension Door
5848  */
5849 bool dimension_door(void)
5850 {
5851         int x = 0, y = 0;
5852
5853         /* Rerutn FALSE if cancelled */
5854         if (!tgt_pt(&x, &y)) return FALSE;
5855
5856         if (dimension_door_aux(x, y)) return TRUE;
5857
5858 #ifdef JP
5859         msg_print("ÀºÎ¤«¤éʪ¼Á³¦¤ËÌá¤ë»þ¤¦¤Þ¤¯¤¤¤«¤Ê¤«¤Ã¤¿¡ª");
5860 #else
5861         msg_print("You fail to exit the astral plane correctly!");
5862 #endif
5863
5864         return TRUE;
5865 }
5866
5867
5868 /*
5869  * Mirror Master's Dimension Door
5870  */
5871 bool mirror_tunnel(void)
5872 {
5873         int x = 0, y = 0;
5874
5875         /* Rerutn FALSE if cancelled */
5876         if (!tgt_pt(&x, &y)) return FALSE;
5877
5878         if (dimension_door_aux(x, y)) return TRUE;
5879
5880 #ifdef JP
5881         msg_print("¶À¤ÎÀ¤³¦¤ò¤¦¤Þ¤¯Ä̤ì¤Ê¤«¤Ã¤¿¡ª");
5882 #else
5883         msg_print("You fail to pass the mirror plane correctly!");
5884 #endif
5885
5886         return TRUE;
5887 }
5888
5889
5890 bool eat_magic(int power)
5891 {
5892         object_type * o_ptr;
5893         object_kind *k_ptr;
5894         int lev, item;
5895         int recharge_strength = 0;
5896
5897         bool fail = FALSE;
5898         byte fail_type = 1;
5899
5900         cptr q, s;
5901         char o_name[MAX_NLEN];
5902
5903         item_tester_hook = item_tester_hook_recharge;
5904
5905         /* Get an item */
5906 #ifdef JP
5907 q = "¤É¤Î¥¢¥¤¥Æ¥à¤«¤éËâÎϤòµÛ¼ý¤·¤Þ¤¹¤«¡©";
5908 s = "ËâÎϤòµÛ¼ý¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
5909 #else
5910         q = "Drain which item? ";
5911         s = "You have nothing to drain.";
5912 #endif
5913
5914         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return FALSE;
5915
5916         if (item >= 0)
5917         {
5918                 o_ptr = &inventory[item];
5919         }
5920         else
5921         {
5922                 o_ptr = &o_list[0 - item];
5923         }
5924
5925         k_ptr = &k_info[o_ptr->k_idx];
5926         lev = get_object_level(o_ptr);
5927
5928         if (o_ptr->tval == TV_ROD)
5929         {
5930                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
5931
5932                 /* Back-fire */
5933                 if (one_in_(recharge_strength))
5934                 {
5935                         /* Activate the failure code. */
5936                         fail = TRUE;
5937                 }
5938                 else
5939                 {
5940                         if (o_ptr->timeout > (o_ptr->number - 1) * k_ptr->pval)
5941                         {
5942 #ifdef JP
5943 msg_print("½¼Å¶Ãæ¤Î¥í¥Ã¥É¤«¤éËâÎϤòµÛ¼ý¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£");
5944 #else
5945                                 msg_print("You can't absorb energy from a discharged rod.");
5946 #endif
5947
5948                         }
5949                         else
5950                         {
5951                                 p_ptr->csp += lev;
5952                                 o_ptr->timeout += k_ptr->pval;
5953                         }
5954                 }
5955         }
5956         else
5957         {
5958                 /* All staffs, wands. */
5959                 recharge_strength = (100 + power - lev) / 15;
5960
5961                 /* Paranoia */
5962                 if (recharge_strength < 0) recharge_strength = 0;
5963
5964                 /* Back-fire */
5965                 if (one_in_(recharge_strength))
5966                 {
5967                         /* Activate the failure code. */
5968                         fail = TRUE;
5969                 }
5970                 else
5971                 {
5972                         if (o_ptr->pval > 0)
5973                         {
5974                                 p_ptr->csp += lev / 2;
5975                                 o_ptr->pval --;
5976
5977                                 /* XXX Hack -- unstack if necessary */
5978                                 if ((o_ptr->tval == TV_STAFF) && (item >= 0) && (o_ptr->number > 1))
5979                                 {
5980                                         object_type forge;
5981                                         object_type *q_ptr;
5982
5983                                         /* Get local object */
5984                                         q_ptr = &forge;
5985
5986                                         /* Obtain a local object */
5987                                         object_copy(q_ptr, o_ptr);
5988
5989                                         /* Modify quantity */
5990                                         q_ptr->number = 1;
5991
5992                                         /* Restore the charges */
5993                                         o_ptr->pval++;
5994
5995                                         /* Unstack the used item */
5996                                         o_ptr->number--;
5997                                         p_ptr->total_weight -= q_ptr->weight;
5998                                         item = inven_carry(q_ptr);
5999
6000                                         /* Message */
6001 #ifdef JP
6002                                         msg_print("¾ó¤ò¤Þ¤È¤á¤Ê¤ª¤·¤¿¡£");
6003 #else
6004                                         msg_print("You unstack your staff.");
6005 #endif
6006
6007                                 }
6008                         }
6009                         else
6010                         {
6011 #ifdef JP
6012 msg_print("µÛ¼ý¤Ç¤­¤ëËâÎϤ¬¤¢¤ê¤Þ¤»¤ó¡ª");
6013 #else
6014                                 msg_print("There's no energy there to absorb!");
6015 #endif
6016
6017                         }
6018                         if (!o_ptr->pval) o_ptr->ident |= IDENT_EMPTY;
6019                 }
6020         }
6021
6022         /* Inflict the penalties for failing a recharge. */
6023         if (fail)
6024         {
6025                 /* Artifacts are never destroyed. */
6026                 if (artifact_p(o_ptr))
6027                 {
6028                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
6029 #ifdef JP
6030 msg_format("ËâÎϤ¬µÕή¤·¤¿¡ª%s¤Ï´°Á´¤ËËâÎϤò¼º¤Ã¤¿¡£", o_name);
6031 #else
6032                         msg_format("The recharging backfires - %s is completely drained!", o_name);
6033 #endif
6034
6035
6036                         /* Artifact rods. */
6037                         if (o_ptr->tval == TV_ROD)
6038                                 o_ptr->timeout = k_ptr->pval * o_ptr->number;
6039
6040                         /* Artifact wands and staffs. */
6041                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
6042                                 o_ptr->pval = 0;
6043                 }
6044                 else
6045                 {
6046                         /* Get the object description */
6047                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
6048
6049                         /*** Determine Seriousness of Failure ***/
6050
6051                         /* Mages recharge objects more safely. */
6052                         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)
6053                         {
6054                                 /* 10% chance to blow up one rod, otherwise draining. */
6055                                 if (o_ptr->tval == TV_ROD)
6056                                 {
6057                                         if (one_in_(10)) fail_type = 2;
6058                                         else fail_type = 1;
6059                                 }
6060                                 /* 75% chance to blow up one wand, otherwise draining. */
6061                                 else if (o_ptr->tval == TV_WAND)
6062                                 {
6063                                         if (!one_in_(3)) fail_type = 2;
6064                                         else fail_type = 1;
6065                                 }
6066                                 /* 50% chance to blow up one staff, otherwise no effect. */
6067                                 else if (o_ptr->tval == TV_STAFF)
6068                                 {
6069                                         if (one_in_(2)) fail_type = 2;
6070                                         else fail_type = 0;
6071                                 }
6072                         }
6073
6074                         /* All other classes get no special favors. */
6075                         else
6076                         {
6077                                 /* 33% chance to blow up one rod, otherwise draining. */
6078                                 if (o_ptr->tval == TV_ROD)
6079                                 {
6080                                         if (one_in_(3)) fail_type = 2;
6081                                         else fail_type = 1;
6082                                 }
6083                                 /* 20% chance of the entire stack, else destroy one wand. */
6084                                 else if (o_ptr->tval == TV_WAND)
6085                                 {
6086                                         if (one_in_(5)) fail_type = 3;
6087                                         else fail_type = 2;
6088                                 }
6089                                 /* Blow up one staff. */
6090                                 else if (o_ptr->tval == TV_STAFF)
6091                                 {
6092                                         fail_type = 2;
6093                                 }
6094                         }
6095
6096                         /*** Apply draining and destruction. ***/
6097
6098                         /* Drain object or stack of objects. */
6099                         if (fail_type == 1)
6100                         {
6101                                 if (o_ptr->tval == TV_ROD)
6102                                 {
6103 #ifdef JP
6104 msg_print("¥í¥Ã¥É¤ÏÇË»¤òÌȤ줿¤¬¡¢ËâÎϤÏÁ´¤Æ¼º¤Ê¤ï¤ì¤¿¡£");
6105 #else
6106                                         msg_format("You save your rod from destruction, but all charges are lost.", o_name);
6107 #endif
6108
6109                                         o_ptr->timeout = k_ptr->pval * o_ptr->number;
6110                                 }
6111                                 else if (o_ptr->tval == TV_WAND)
6112                                 {
6113 #ifdef JP
6114 msg_format("%s¤ÏÇË»¤òÌȤ줿¤¬¡¢ËâÎϤ¬Á´¤Æ¼º¤ï¤ì¤¿¡£", o_name);
6115 #else
6116                                         msg_format("You save your %s from destruction, but all charges are lost.", o_name);
6117 #endif
6118
6119                                         o_ptr->pval = 0;
6120                                 }
6121                                 /* Staffs aren't drained. */
6122                         }
6123
6124                         /* Destroy an object or one in a stack of objects. */
6125                         if (fail_type == 2)
6126                         {
6127                                 if (o_ptr->number > 1)
6128                                 {
6129 #ifdef JP
6130 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬°ìËܲõ¤ì¤¿¡ª", o_name);
6131 #else
6132                                         msg_format("Wild magic consumes one of your %s!", o_name);
6133 #endif
6134
6135                                         /* Reduce rod stack maximum timeout, drain wands. */
6136                                         if (o_ptr->tval == TV_ROD) o_ptr->timeout = MIN(o_ptr->timeout, k_ptr->pval * (o_ptr->number - 1));
6137                                         else if (o_ptr->tval == TV_WAND) o_ptr->pval = o_ptr->pval * (o_ptr->number - 1) / o_ptr->number;
6138
6139                                 }
6140                                 else
6141 #ifdef JP
6142 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²¿Ëܤ«²õ¤ì¤¿¡ª", o_name);
6143 #else
6144                                         msg_format("Wild magic consumes your %s!", o_name);
6145 #endif
6146
6147                                 /* Reduce and describe inventory */
6148                                 if (item >= 0)
6149                                 {
6150                                         inven_item_increase(item, -1);
6151                                         inven_item_describe(item);
6152                                         inven_item_optimize(item);
6153                                 }
6154
6155                                 /* Reduce and describe floor item */
6156                                 else
6157                                 {
6158                                         floor_item_increase(0 - item, -1);
6159                                         floor_item_describe(0 - item);
6160                                         floor_item_optimize(0 - item);
6161                                 }
6162                         }
6163
6164                         /* Destroy all members of a stack of objects. */
6165                         if (fail_type == 3)
6166                         {
6167                                 if (o_ptr->number > 1)
6168 #ifdef JP
6169 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬Á´¤Æ²õ¤ì¤¿¡ª", o_name);
6170 #else
6171                                         msg_format("Wild magic consumes all your %s!", o_name);
6172 #endif
6173
6174                                 else
6175 #ifdef JP
6176 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²õ¤ì¤¿¡ª", o_name);
6177 #else
6178                                         msg_format("Wild magic consumes your %s!", o_name);
6179 #endif
6180
6181
6182
6183                                 /* Reduce and describe inventory */
6184                                 if (item >= 0)
6185                                 {
6186                                         inven_item_increase(item, -999);
6187                                         inven_item_describe(item);
6188                                         inven_item_optimize(item);
6189                                 }
6190
6191                                 /* Reduce and describe floor item */
6192                                 else
6193                                 {
6194                                         floor_item_increase(0 - item, -999);
6195                                         floor_item_describe(0 - item);
6196                                         floor_item_optimize(0 - item);
6197                                 }
6198                         }
6199                 }
6200         }
6201
6202         if (p_ptr->csp > p_ptr->msp)
6203         {
6204                 p_ptr->csp = p_ptr->msp;
6205         }
6206
6207         /* Redraw mana and hp */
6208         p_ptr->redraw |= (PR_MANA);
6209
6210         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
6211         p_ptr->window |= (PW_INVEN);
6212
6213         return TRUE;
6214 }
6215
6216
6217 bool summon_kin_player(int level, int y, int x, u32b mode)
6218 {
6219         bool pet = (bool)(mode & PM_FORCE_PET);
6220         if (!pet) mode |= PM_NO_PET;
6221
6222         switch (p_ptr->mimic_form)
6223         {
6224         case MIMIC_NONE:
6225                 switch (p_ptr->prace)
6226                 {
6227                         case RACE_HUMAN:
6228                         case RACE_AMBERITE:
6229                         case RACE_BARBARIAN:
6230                         case RACE_BEASTMAN:
6231                         case RACE_DUNADAN:
6232                                 summon_kin_type = 'p';
6233                                 break;
6234                         case RACE_HALF_ELF:
6235                         case RACE_ELF:
6236                         case RACE_HOBBIT:
6237                         case RACE_GNOME:
6238                         case RACE_DWARF:
6239                         case RACE_HIGH_ELF:
6240                         case RACE_NIBELUNG:
6241                         case RACE_DARK_ELF:
6242                         case RACE_MIND_FLAYER:
6243                         case RACE_KUTA:
6244                         case RACE_S_FAIRY:
6245                                 summon_kin_type = 'h';
6246                                 break;
6247                         case RACE_HALF_ORC:
6248                                 summon_kin_type = 'o';
6249                                 break;
6250                         case RACE_HALF_TROLL:
6251                                 summon_kin_type = 'T';
6252                                 break;
6253                         case RACE_HALF_OGRE:
6254                                 summon_kin_type = 'O';
6255                                 break;
6256                         case RACE_HALF_GIANT:
6257                         case RACE_HALF_TITAN:
6258                         case RACE_CYCLOPS:
6259                                 summon_kin_type = 'P';
6260                                 break;
6261                         case RACE_YEEK:
6262                                 summon_kin_type = 'y';
6263                                 break;
6264                         case RACE_KLACKON:
6265                                 summon_kin_type = 'K';
6266                                 break;
6267                         case RACE_KOBOLD:
6268                                 summon_kin_type = 'k';
6269                                 break;
6270                         case RACE_IMP:
6271                                 if (one_in_(13)) summon_kin_type = 'U';
6272                                 else summon_kin_type = 'u';
6273                                 break;
6274                         case RACE_DRACONIAN:
6275                                 summon_kin_type = 'd';
6276                                 break;
6277                         case RACE_GOLEM:
6278                         case RACE_ANDROID:
6279                                 summon_kin_type = 'g';
6280                                 break;
6281                         case RACE_SKELETON:
6282                                 if (one_in_(13)) summon_kin_type = 'L';
6283                                 else summon_kin_type = 's';
6284                                 break;
6285                         case RACE_ZOMBIE:
6286                                 summon_kin_type = 'z';
6287                                 break;
6288                         case RACE_VAMPIRE:
6289                                 summon_kin_type = 'V';
6290                                 break;
6291                         case RACE_SPECTRE:
6292                                 summon_kin_type = 'G';
6293                                 break;
6294                         case RACE_SPRITE:
6295                                 summon_kin_type = 'I';
6296                                 break;
6297                         case RACE_ENT:
6298                                 summon_kin_type = '#';
6299                                 break;
6300                         case RACE_ANGEL:
6301                                 summon_kin_type = 'A';
6302                                 break;
6303                         case RACE_DEMON:
6304                                 summon_kin_type = 'U';
6305                                 break;
6306                         default:
6307                                 summon_kin_type = 'p';
6308                                 break;
6309                 }
6310                 break;
6311         case MIMIC_DEMON:
6312                 if (one_in_(13)) summon_kin_type = 'U';
6313                 else summon_kin_type = 'u';
6314                 break;
6315         case MIMIC_DEMON_LORD:
6316                 summon_kin_type = 'U';
6317                 break;
6318         case MIMIC_VAMPIRE:
6319                 summon_kin_type = 'V';
6320                 break;
6321         }       
6322         return summon_specific((pet ? -1 : 0), y, x, level, SUMMON_KIN, mode);
6323 }