OSDN Git Service

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