OSDN Git Service

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