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