OSDN Git Service

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