OSDN Git Service

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