OSDN Git Service

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