OSDN Git Service

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