OSDN Git Service

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