OSDN Git Service

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