OSDN Git Service

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