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