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