OSDN Git Service

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