OSDN Git Service

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