OSDN Git Service

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