OSDN Git Service

地形フラグ参照に関して, have_flag(f_flags_*(), フラグ)として使われて
[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)
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 teleporting into vaults and such */
266         if (c_ptr->info & CAVE_ICKY) return FALSE;
267
268         if (c_ptr->m_idx) 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)) 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 && !passive) break;
462
463                 /* Accept teleportable floor grids */
464                 if (cave_player_teleportable_bold(y, x, passive)) 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 = m_ptr->ml;
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 (m_ptr->ml)
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                                         /* Redraw the health bar */
1507                                         if (p_ptr->health_who == c_ptr->m_idx) p_ptr->redraw |= (PR_HEALTH);
1508                                         if (p_ptr->riding == c_ptr->m_idx) p_ptr->redraw |= (PR_UHEALTH);
1509                                 }
1510                         }
1511
1512                         /* Process all walls, doors and patterns */
1513                         if (have_flag(f_ptr->flags, FF_HURT_DISI)) cave_alter_feat(y, x, FF_HURT_DISI);
1514                 }
1515         }
1516
1517         /* Special boundary walls -- Top and bottom */
1518         for (x = 0; x < cur_wid; x++)
1519         {
1520                 c_ptr = &cave[0][x];
1521                 f_ptr = &f_info[c_ptr->mimic];
1522
1523                 /* Lose room and vault */
1524                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1525
1526                 /* Set boundary mimic if needed */
1527                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1528                 {
1529                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1530
1531                         /* Check for change to boring grid */
1532                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1533                 }
1534
1535                 c_ptr = &cave[cur_hgt - 1][x];
1536                 f_ptr = &f_info[c_ptr->mimic];
1537
1538                 /* Lose room and vault */
1539                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1540
1541                 /* Set boundary mimic if needed */
1542                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1543                 {
1544                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1545
1546                         /* Check for change to boring grid */
1547                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1548                 }
1549         }
1550
1551         /* Special boundary walls -- Left and right */
1552         for (y = 1; y < (cur_hgt - 1); y++)
1553         {
1554                 c_ptr = &cave[y][0];
1555                 f_ptr = &f_info[c_ptr->mimic];
1556
1557                 /* Lose room and vault */
1558                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1559
1560                 /* Set boundary mimic if needed */
1561                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1562                 {
1563                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1564
1565                         /* Check for change to boring grid */
1566                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1567                 }
1568
1569                 c_ptr = &cave[y][cur_wid - 1];
1570                 f_ptr = &f_info[c_ptr->mimic];
1571
1572                 /* Lose room and vault */
1573                 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1574
1575                 /* Set boundary mimic if needed */
1576                 if (c_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1577                 {
1578                         c_ptr->mimic = feat_state(c_ptr->mimic, FF_HURT_DISI);
1579
1580                         /* Check for change to boring grid */
1581                         if (!have_flag(f_info[c_ptr->mimic].flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
1582                 }
1583         }
1584
1585         /* Mega-Hack -- Forget the view and lite */
1586         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1587
1588         /* Update stuff */
1589         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
1590
1591         /* Update the monsters */
1592         p_ptr->update |= (PU_MONSTERS);
1593
1594         /* Redraw map */
1595         p_ptr->redraw |= (PR_MAP);
1596
1597         /* Window stuff */
1598         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1599
1600         return TRUE;
1601 }
1602
1603
1604 void call_the_(void)
1605 {
1606         int i;
1607         cave_type *c_ptr;
1608         bool do_call = TRUE;
1609
1610         for (i = 0; i < 9; i++)
1611         {
1612                 c_ptr = &cave[py + ddy_ddd[i]][px + ddx_ddd[i]];
1613
1614                 if (!cave_have_flag_grid(c_ptr, FF_PROJECT))
1615                 {
1616                         if (!c_ptr->mimic || !have_flag(f_info[c_ptr->mimic].flags, FF_PROJECT) ||
1617                             !permanent_wall(&f_info[c_ptr->feat]))
1618                         {
1619                                 do_call = FALSE;
1620                                 break;
1621                         }
1622                 }
1623         }
1624
1625         if (do_call)
1626         {
1627                 for (i = 1; i < 10; i++)
1628                 {
1629                         if (i - 5) fire_ball(GF_ROCKET, i, 175, 2);
1630                 }
1631
1632                 for (i = 1; i < 10; i++)
1633                 {
1634                         if (i - 5) fire_ball(GF_MANA, i, 175, 3);
1635                 }
1636
1637                 for (i = 1; i < 10; i++)
1638                 {
1639                         if (i - 5) fire_ball(GF_NUKE, i, 175, 4);
1640                 }
1641         }
1642
1643         /* Prevent destruction of quest levels and town */
1644         else if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !dun_level)
1645         {
1646 #ifdef JP
1647                 msg_print("ÃÏÌ̤¬Íɤ줿¡£");
1648 #else
1649                 msg_print("The ground trembles.");
1650 #endif
1651         }
1652
1653         else
1654         {
1655 #ifdef JP
1656                 msg_format("¤¢¤Ê¤¿¤Ï%s¤òÊɤ˶᤹¤®¤ë¾ì½ê¤Ç¾§¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª",
1657                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "µ§¤ê" : "¼öʸ"));
1658                 msg_print("Â礭¤ÊÇúȯ²»¤¬¤¢¤Ã¤¿¡ª");
1659 #else
1660                 msg_format("You %s the %s too close to a wall!",
1661                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1662                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "prayer" : "spell"));
1663                 msg_print("There is a loud explosion!");
1664 #endif
1665
1666                 if (one_in_(666))
1667                 {
1668 #ifdef JP
1669                         if (!vanish_dungeon()) msg_print("¥À¥ó¥¸¥ç¥ó¤Ï°ì½ÖÀŤޤêÊ֤ä¿¡£");
1670 #else
1671                         if (!vanish_dungeon()) msg_print("The dungeon silences a moment.");
1672 #endif
1673                 }
1674                 else
1675                 {
1676                         if (destroy_area(py, px, 15 + p_ptr->lev + randint0(11), FALSE))
1677 #ifdef JP
1678                                 msg_print("¥À¥ó¥¸¥ç¥ó¤¬Êø²õ¤·¤¿...");
1679 #else
1680                                 msg_print("The dungeon collapses...");
1681 #endif
1682
1683                         else
1684 #ifdef JP
1685                                 msg_print("¥À¥ó¥¸¥ç¥ó¤ÏÂ礭¤¯Íɤ줿¡£");
1686 #else
1687                                 msg_print("The dungeon trembles.");
1688 #endif
1689                 }
1690
1691 #ifdef JP
1692                 take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), "¼«»¦Åª¤Êµõ̵¾·Íè", -1);
1693 #else
1694                 take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), "a suicidal Call the Void", -1);
1695 #endif
1696         }
1697 }
1698
1699
1700 /*
1701  * Fetch an item (teleport it right underneath the caster)
1702  */
1703 void fetch(int dir, int wgt, bool require_los)
1704 {
1705         int             ty, tx, i;
1706         cave_type       *c_ptr;
1707         object_type     *o_ptr;
1708         char            o_name[MAX_NLEN];
1709
1710         /* Check to see if an object is already there */
1711         if (cave[py][px].o_idx)
1712         {
1713 #ifdef JP
1714 msg_print("¼«Ê¬¤Î­¤Î²¼¤Ë¤¢¤ëʪ¤Ï¼è¤ì¤Þ¤»¤ó¡£");
1715 #else
1716                 msg_print("You can't fetch when you're already standing on something.");
1717 #endif
1718
1719                 return;
1720         }
1721
1722         /* Use a target */
1723         if (dir == 5 && target_okay())
1724         {
1725                 tx = target_col;
1726                 ty = target_row;
1727
1728                 if (distance(py, px, ty, tx) > MAX_RANGE)
1729                 {
1730 #ifdef JP
1731 msg_print("¤½¤ó¤Ê¤Ë±ó¤¯¤Ë¤¢¤ëʪ¤Ï¼è¤ì¤Þ¤»¤ó¡ª");
1732 #else
1733                         msg_print("You can't fetch something that far away!");
1734 #endif
1735
1736                         return;
1737                 }
1738
1739                 c_ptr = &cave[ty][tx];
1740
1741                 /* We need an item to fetch */
1742                 if (!c_ptr->o_idx)
1743                 {
1744 #ifdef JP
1745 msg_print("¤½¤³¤Ë¤Ï²¿¤â¤¢¤ê¤Þ¤»¤ó¡£");
1746 #else
1747                         msg_print("There is no object at this place.");
1748 #endif
1749
1750                         return;
1751                 }
1752
1753                 /* No fetching from vault */
1754                 if (c_ptr->info & CAVE_ICKY)
1755                 {
1756 #ifdef JP
1757 msg_print("¥¢¥¤¥Æ¥à¤¬¥³¥ó¥È¥í¡¼¥ë¤ò³°¤ì¤ÆÍî¤Á¤¿¡£");
1758 #else
1759                         msg_print("The item slips from your control.");
1760 #endif
1761
1762                         return;
1763                 }
1764
1765                 /* We need to see the item */
1766                 if (require_los)
1767                 {
1768                         if (!player_has_los_bold(ty, tx))
1769                         {
1770 #ifdef JP
1771                                 msg_print("¤½¤³¤Ï¤¢¤Ê¤¿¤Î»ë³¦¤ËÆþ¤Ã¤Æ¤¤¤Þ¤»¤ó¡£");
1772 #else
1773                                 msg_print("You have no direct line of sight to that location.");
1774 #endif
1775
1776                                 return;
1777                         }
1778                         else if (!projectable(py, px, ty, tx))
1779                         {
1780 #ifdef JP
1781                                 msg_print("¤½¤³¤ÏÊɤθþ¤³¤¦¤Ç¤¹¡£");
1782 #else
1783                                 msg_print("You have no direct line of sight to that location.");
1784 #endif
1785
1786                                 return;
1787                         }
1788                 }
1789         }
1790         else
1791         {
1792                 /* Use a direction */
1793                 ty = py; /* Where to drop the item */
1794                 tx = px;
1795
1796                 do
1797                 {
1798                         ty += ddy[dir];
1799                         tx += ddx[dir];
1800                         c_ptr = &cave[ty][tx];
1801
1802                         if ((distance(py, px, ty, tx) > MAX_RANGE) ||
1803                                 !cave_have_flag_bold(ty, tx, FF_PROJECT)) return;
1804                 }
1805                 while (!c_ptr->o_idx);
1806         }
1807
1808         o_ptr = &o_list[c_ptr->o_idx];
1809
1810         if (o_ptr->weight > wgt)
1811         {
1812                 /* Too heavy to 'fetch' */
1813 #ifdef JP
1814 msg_print("¤½¤Î¥¢¥¤¥Æ¥à¤Ï½Å²á¤®¤Þ¤¹¡£");
1815 #else
1816                 msg_print("The object is too heavy.");
1817 #endif
1818
1819                 return;
1820         }
1821
1822         i = c_ptr->o_idx;
1823         c_ptr->o_idx = o_ptr->next_o_idx;
1824         cave[py][px].o_idx = i; /* 'move' it */
1825         o_ptr->next_o_idx = 0;
1826         o_ptr->iy = (byte)py;
1827         o_ptr->ix = (byte)px;
1828
1829         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1830 #ifdef JP
1831 msg_format("%^s¤¬¤¢¤Ê¤¿¤Î­¸µ¤ËÈô¤ó¤Ç¤­¤¿¡£", o_name);
1832 #else
1833         msg_format("%^s flies through the air to your feet.", o_name);
1834 #endif
1835
1836
1837         note_spot(py, px);
1838         p_ptr->redraw |= PR_MAP;
1839 }
1840
1841
1842 void alter_reality(void)
1843 {
1844         /* Ironman option */
1845         if (p_ptr->inside_arena || ironman_downward)
1846         {
1847 #ifdef JP
1848                 msg_print("²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
1849 #else
1850                 msg_print("Nothing happens.");
1851 #endif
1852                 return;
1853         }
1854
1855         if (!p_ptr->alter_reality)
1856         {
1857                 int turns = randint0(21) + 15;
1858
1859                 p_ptr->alter_reality = turns;
1860 #ifdef JP
1861                 msg_print("²ó¤ê¤Î·Ê¿§¤¬ÊѤï¤ê»Ï¤á¤¿...");
1862 #else
1863                 msg_print("The view around you begins to change...");
1864 #endif
1865
1866                 p_ptr->redraw |= (PR_STATUS);
1867         }
1868         else
1869         {
1870                 p_ptr->alter_reality = 0;
1871 #ifdef JP
1872                 msg_print("·Ê¿§¤¬¸µ¤ËÌá¤Ã¤¿...");
1873 #else
1874                 msg_print("The view around you got back...");
1875 #endif
1876
1877                 p_ptr->redraw |= (PR_STATUS);
1878         }
1879         return;
1880 }
1881
1882
1883 /*
1884  * Leave a "glyph of warding" which prevents monster movement
1885  */
1886 bool warding_glyph(void)
1887 {
1888         /* XXX XXX XXX */
1889         if (!cave_clean_bold(py, px))
1890         {
1891 #ifdef JP
1892 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1893 #else
1894                 msg_print("The object resists the spell.");
1895 #endif
1896
1897                 return FALSE;
1898         }
1899
1900         /* Create a glyph */
1901         cave[py][px].info |= CAVE_OBJECT;
1902         cave[py][px].mimic = FEAT_GLYPH;
1903
1904         /* Notice */
1905         note_spot(py, px);
1906
1907         /* Redraw */
1908         lite_spot(py, px);
1909
1910         return TRUE;
1911 }
1912
1913 bool place_mirror(void)
1914 {
1915         /* XXX XXX XXX */
1916         if (!cave_clean_bold(py, px))
1917         {
1918 #ifdef JP
1919 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1920 #else
1921                 msg_print("The object resists the spell.");
1922 #endif
1923
1924                 return FALSE;
1925         }
1926
1927         /* Create a mirror */
1928         cave[py][px].info |= CAVE_OBJECT;
1929         cave[py][px].mimic = FEAT_MIRROR;
1930
1931         /* Turn on the light */
1932         cave[py][px].info |= CAVE_GLOW;
1933
1934         /* Notice */
1935         note_spot(py, px);
1936
1937         /* Redraw */
1938         lite_spot(py, px);
1939
1940         update_local_illumination(py, px);
1941
1942         return TRUE;
1943 }
1944
1945
1946 /*
1947  * Leave an "explosive rune" which prevents monster movement
1948  */
1949 bool explosive_rune(void)
1950 {
1951         /* XXX XXX XXX */
1952         if (!cave_clean_bold(py, px))
1953         {
1954 #ifdef JP
1955 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1956 #else
1957                 msg_print("The object resists the spell.");
1958 #endif
1959
1960                 return FALSE;
1961         }
1962
1963         /* Create a glyph */
1964         cave[py][px].info |= CAVE_OBJECT;
1965         cave[py][px].mimic = FEAT_MINOR_GLYPH;
1966
1967         /* Notice */
1968         note_spot(py, px);
1969         
1970         /* Redraw */
1971         lite_spot(py, px);
1972
1973         return TRUE;
1974 }
1975
1976
1977 /*
1978  * Identify everything being carried.
1979  * Done by a potion of "self knowledge".
1980  */
1981 void identify_pack(void)
1982 {
1983         int i;
1984
1985         /* Simply identify and know every item */
1986         for (i = 0; i < INVEN_TOTAL; i++)
1987         {
1988                 object_type *o_ptr = &inventory[i];
1989
1990                 /* Skip non-objects */
1991                 if (!o_ptr->k_idx) continue;
1992
1993                 /* Identify it */
1994                 identify_item(o_ptr);
1995
1996                 /* Auto-inscription */
1997                 autopick_alter_item(i, FALSE);
1998         }
1999 }
2000
2001
2002 /*
2003  * Used by the "enchant" function (chance of failure)
2004  * (modified for Zangband, we need better stuff there...) -- TY
2005  */
2006 static int enchant_table[16] =
2007 {
2008         0, 10,  50, 100, 200,
2009         300, 400, 500, 650, 800,
2010         950, 987, 993, 995, 998,
2011         1000
2012 };
2013
2014
2015 /*
2016  * Removes curses from items in inventory
2017  *
2018  * Note that Items which are "Perma-Cursed" (The One Ring,
2019  * The Crown of Morgoth) can NEVER be uncursed.
2020  *
2021  * Note that if "all" is FALSE, then Items which are
2022  * "Heavy-Cursed" (Mormegil, Calris, and Weapons of Morgul)
2023  * will not be uncursed.
2024  */
2025 static int remove_curse_aux(int all)
2026 {
2027         int i, cnt = 0;
2028
2029         /* Attempt to uncurse items being worn */
2030         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2031         {
2032                 object_type *o_ptr = &inventory[i];
2033
2034                 /* Skip non-objects */
2035                 if (!o_ptr->k_idx) continue;
2036
2037                 /* Uncursed already */
2038                 if (!object_is_cursed(o_ptr)) continue;
2039
2040                 /* Heavily Cursed Items need a special spell */
2041                 if (!all && (o_ptr->curse_flags & TRC_HEAVY_CURSE)) continue;
2042
2043                 /* Perma-Cursed Items can NEVER be uncursed */
2044                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
2045                 {
2046                         /* Uncurse it */
2047                         o_ptr->curse_flags &= (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE);
2048                         continue;
2049                 }
2050
2051                 /* Uncurse it */
2052                 o_ptr->curse_flags = 0L;
2053
2054                 /* Hack -- Assume felt */
2055                 o_ptr->ident |= (IDENT_SENSE);
2056
2057                 /* Take note */
2058                 o_ptr->feeling = FEEL_NONE;
2059
2060                 /* Recalculate the bonuses */
2061                 p_ptr->update |= (PU_BONUS);
2062
2063                 /* Window stuff */
2064                 p_ptr->window |= (PW_EQUIP);
2065
2066                 /* Count the uncursings */
2067                 cnt++;
2068         }
2069
2070         /* Return "something uncursed" */
2071         return (cnt);
2072 }
2073
2074
2075 /*
2076  * Remove most curses
2077  */
2078 bool remove_curse(void)
2079 {
2080         return (remove_curse_aux(FALSE));
2081 }
2082
2083 /*
2084  * Remove all curses
2085  */
2086 bool remove_all_curse(void)
2087 {
2088         return (remove_curse_aux(TRUE));
2089 }
2090
2091
2092 /*
2093  * Turns an object into gold, gain some of its value in a shop
2094  */
2095 bool alchemy(void)
2096 {
2097         int item, amt = 1;
2098         int old_number;
2099         long price;
2100         bool force = FALSE;
2101         object_type *o_ptr;
2102         char o_name[MAX_NLEN];
2103         char out_val[MAX_NLEN+40];
2104
2105         cptr q, s;
2106
2107         /* Hack -- force destruction */
2108         if (command_arg > 0) force = TRUE;
2109
2110         /* Get an item */
2111 #ifdef JP
2112 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶â¤ËÊѤ¨¤Þ¤¹¤«¡©";
2113 s = "¶â¤ËÊѤ¨¤é¤ì¤ëʪ¤¬¤¢¤ê¤Þ¤»¤ó¡£";
2114 #else
2115         q = "Turn which item to gold? ";
2116         s = "You have nothing to turn to gold.";
2117 #endif
2118
2119         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
2120
2121         /* Get the item (in the pack) */
2122         if (item >= 0)
2123         {
2124                 o_ptr = &inventory[item];
2125         }
2126
2127         /* Get the item (on the floor) */
2128         else
2129         {
2130                 o_ptr = &o_list[0 - item];
2131         }
2132
2133
2134         /* See how many items */
2135         if (o_ptr->number > 1)
2136         {
2137                 /* Get a quantity */
2138                 amt = get_quantity(NULL, o_ptr->number);
2139
2140                 /* Allow user abort */
2141                 if (amt <= 0) return FALSE;
2142         }
2143
2144
2145         /* Describe the object */
2146         old_number = o_ptr->number;
2147         o_ptr->number = amt;
2148         object_desc(o_name, o_ptr, 0);
2149         o_ptr->number = old_number;
2150
2151         /* Verify unless quantity given */
2152         if (!force)
2153         {
2154                 if (confirm_destroy || (object_value(o_ptr) > 0))
2155                 {
2156                         /* Make a verification */
2157 #ifdef JP
2158 sprintf(out_val, "ËÜÅö¤Ë%s¤ò¶â¤ËÊѤ¨¤Þ¤¹¤«¡©", o_name);
2159 #else
2160                         sprintf(out_val, "Really turn %s to gold? ", o_name);
2161 #endif
2162
2163                         if (!get_check(out_val)) return FALSE;
2164                 }
2165         }
2166
2167         /* Artifacts cannot be destroyed */
2168         if (!can_player_destroy_object(o_ptr))
2169         {
2170                 /* Message */
2171 #ifdef JP
2172                 msg_format("%s¤ò¶â¤ËÊѤ¨¤ë¤³¤È¤Ë¼ºÇÔ¤·¤¿¡£", o_name);
2173 #else
2174                 msg_format("You fail to turn %s to gold!", o_name);
2175 #endif
2176
2177                 /* Done */
2178                 return FALSE;
2179         }
2180
2181         price = object_value_real(o_ptr);
2182
2183         if (price <= 0)
2184         {
2185                 /* Message */
2186 #ifdef JP
2187 msg_format("%s¤ò¥Ë¥»¤Î¶â¤ËÊѤ¨¤¿¡£", o_name);
2188 #else
2189                 msg_format("You turn %s to fool's gold.", o_name);
2190 #endif
2191
2192         }
2193         else
2194         {
2195                 price /= 3;
2196
2197                 if (amt > 1) price *= amt;
2198
2199                 if (price > 30000) price = 30000;
2200 #ifdef JP
2201 msg_format("%s¤ò¡ð%d ¤Î¶â¤ËÊѤ¨¤¿¡£", o_name, price);
2202 #else
2203                 msg_format("You turn %s to %ld coins worth of gold.", o_name, price);
2204 #endif
2205
2206                 p_ptr->au += price;
2207
2208                 /* Redraw gold */
2209                 p_ptr->redraw |= (PR_GOLD);
2210
2211                 /* Window stuff */
2212                 p_ptr->window |= (PW_PLAYER);
2213
2214         }
2215
2216         /* Eliminate the item (from the pack) */
2217         if (item >= 0)
2218         {
2219                 inven_item_increase(item, -amt);
2220                 inven_item_describe(item);
2221                 inven_item_optimize(item);
2222         }
2223
2224         /* Eliminate the item (from the floor) */
2225         else
2226         {
2227                 floor_item_increase(0 - item, -amt);
2228                 floor_item_describe(0 - item);
2229                 floor_item_optimize(0 - item);
2230         }
2231
2232         return TRUE;
2233 }
2234
2235
2236 /*
2237  * Break the curse of an item
2238  */
2239 static void break_curse(object_type *o_ptr)
2240 {
2241         if (object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
2242         {
2243 #ifdef JP
2244 msg_print("¤«¤±¤é¤ì¤Æ¤¤¤¿¼ö¤¤¤¬ÂǤÁÇˤé¤ì¤¿¡ª");
2245 #else
2246                 msg_print("The curse is broken!");
2247 #endif
2248
2249                 o_ptr->curse_flags = 0L;
2250
2251                 o_ptr->ident |= (IDENT_SENSE);
2252
2253                 o_ptr->feeling = FEEL_NONE;
2254         }
2255 }
2256
2257
2258 /*
2259  * Enchants a plus onto an item. -RAK-
2260  *
2261  * Revamped!  Now takes item pointer, number of times to try enchanting,
2262  * and a flag of what to try enchanting.  Artifacts resist enchantment
2263  * some of the time, and successful enchantment to at least +0 might
2264  * break a curse on the item. -CFT-
2265  *
2266  * Note that an item can technically be enchanted all the way to +15 if
2267  * you wait a very, very, long time.  Going from +9 to +10 only works
2268  * about 5% of the time, and from +10 to +11 only about 1% of the time.
2269  *
2270  * Note that this function can now be used on "piles" of items, and
2271  * the larger the pile, the lower the chance of success.
2272  */
2273 bool enchant(object_type *o_ptr, int n, int eflag)
2274 {
2275         int     i, chance, prob;
2276         bool    res = FALSE;
2277         bool    a = object_is_artifact(o_ptr);
2278         bool    force = (eflag & ENCH_FORCE);
2279
2280
2281         /* Large piles resist enchantment */
2282         prob = o_ptr->number * 100;
2283
2284         /* Missiles are easy to enchant */
2285         if ((o_ptr->tval == TV_BOLT) ||
2286             (o_ptr->tval == TV_ARROW) ||
2287             (o_ptr->tval == TV_SHOT))
2288         {
2289                 prob = prob / 20;
2290         }
2291
2292         /* Try "n" times */
2293         for (i = 0; i < n; i++)
2294         {
2295                 /* Hack -- Roll for pile resistance */
2296                 if (!force && randint0(prob) >= 100) continue;
2297
2298                 /* Enchant to hit */
2299                 if (eflag & ENCH_TOHIT)
2300                 {
2301                         if (o_ptr->to_h < 0) chance = 0;
2302                         else if (o_ptr->to_h > 15) chance = 1000;
2303                         else chance = enchant_table[o_ptr->to_h];
2304
2305                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2306                         {
2307                                 o_ptr->to_h++;
2308                                 res = TRUE;
2309
2310                                 /* only when you get it above -1 -CFT */
2311                                 if (o_ptr->to_h >= 0)
2312                                         break_curse(o_ptr);
2313                         }
2314                 }
2315
2316                 /* Enchant to damage */
2317                 if (eflag & ENCH_TODAM)
2318                 {
2319                         if (o_ptr->to_d < 0) chance = 0;
2320                         else if (o_ptr->to_d > 15) chance = 1000;
2321                         else chance = enchant_table[o_ptr->to_d];
2322
2323                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2324                         {
2325                                 o_ptr->to_d++;
2326                                 res = TRUE;
2327
2328                                 /* only when you get it above -1 -CFT */
2329                                 if (o_ptr->to_d >= 0)
2330                                         break_curse(o_ptr);
2331                         }
2332                 }
2333
2334                 /* Enchant to armor class */
2335                 if (eflag & ENCH_TOAC)
2336                 {
2337                         if (o_ptr->to_a < 0) chance = 0;
2338                         else if (o_ptr->to_a > 15) chance = 1000;
2339                         else chance = enchant_table[o_ptr->to_a];
2340
2341                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
2342                         {
2343                                 o_ptr->to_a++;
2344                                 res = TRUE;
2345
2346                                 /* only when you get it above -1 -CFT */
2347                                 if (o_ptr->to_a >= 0)
2348                                         break_curse(o_ptr);
2349                         }
2350                 }
2351         }
2352
2353         /* Failure */
2354         if (!res) return (FALSE);
2355
2356         /* Recalculate bonuses */
2357         p_ptr->update |= (PU_BONUS);
2358
2359         /* Combine / Reorder the pack (later) */
2360         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2361
2362         /* Window stuff */
2363         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2364
2365         calc_android_exp();
2366
2367         /* Success */
2368         return (TRUE);
2369 }
2370
2371
2372
2373 /*
2374  * Enchant an item (in the inventory or on the floor)
2375  * Note that "num_ac" requires armour, else weapon
2376  * Returns TRUE if attempted, FALSE if cancelled
2377  */
2378 bool enchant_spell(int num_hit, int num_dam, int num_ac)
2379 {
2380         int         item;
2381         bool        okay = FALSE;
2382         object_type *o_ptr;
2383         char        o_name[MAX_NLEN];
2384         cptr        q, s;
2385
2386
2387         /* Assume enchant weapon */
2388         item_tester_hook = object_allow_enchant_weapon;
2389         item_tester_no_ryoute = TRUE;
2390
2391         /* Enchant armor if requested */
2392         if (num_ac) item_tester_hook = object_is_armour;
2393
2394         /* Get an item */
2395 #ifdef JP
2396 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶¯²½¤·¤Þ¤¹¤«? ";
2397 s = "¶¯²½¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
2398 #else
2399         q = "Enchant which item? ";
2400         s = "You have nothing to enchant.";
2401 #endif
2402
2403         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2404
2405         /* Get the item (in the pack) */
2406         if (item >= 0)
2407         {
2408                 o_ptr = &inventory[item];
2409         }
2410
2411         /* Get the item (on the floor) */
2412         else
2413         {
2414                 o_ptr = &o_list[0 - item];
2415         }
2416
2417
2418         /* Description */
2419         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2420
2421         /* Describe */
2422 #ifdef JP
2423 msg_format("%s ¤ÏÌÀ¤ë¤¯µ±¤¤¤¿¡ª",
2424     o_name);
2425 #else
2426         msg_format("%s %s glow%s brightly!",
2427                    ((item >= 0) ? "Your" : "The"), o_name,
2428                    ((o_ptr->number > 1) ? "" : "s"));
2429 #endif
2430
2431
2432         /* Enchant */
2433         if (enchant(o_ptr, num_hit, ENCH_TOHIT)) okay = TRUE;
2434         if (enchant(o_ptr, num_dam, ENCH_TODAM)) okay = TRUE;
2435         if (enchant(o_ptr, num_ac, ENCH_TOAC)) okay = TRUE;
2436
2437         /* Failure */
2438         if (!okay)
2439         {
2440                 /* Flush */
2441                 if (flush_failure) flush();
2442
2443                 /* Message */
2444 #ifdef JP
2445 msg_print("¶¯²½¤Ë¼ºÇÔ¤·¤¿¡£");
2446 #else
2447                 msg_print("The enchantment failed.");
2448 #endif
2449
2450                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2451         }
2452         else
2453                 chg_virtue(V_ENCHANT, 1);
2454
2455         calc_android_exp();
2456
2457         /* Something happened */
2458         return (TRUE);
2459 }
2460
2461
2462 /*
2463  * Check if an object is nameless weapon or armour
2464  */
2465 static bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
2466 {
2467         /* Require weapon or armour */
2468         if (!object_is_weapon_armour_ammo(o_ptr)) return FALSE;
2469         
2470         /* Require nameless object if the object is well known */
2471         if (object_is_known(o_ptr) && !object_is_nameless(o_ptr))
2472                 return FALSE;
2473
2474         return TRUE;
2475 }
2476
2477
2478 bool artifact_scroll(void)
2479 {
2480         int             item;
2481         bool            okay = FALSE;
2482         object_type     *o_ptr;
2483         char            o_name[MAX_NLEN];
2484         cptr            q, s;
2485
2486
2487         item_tester_no_ryoute = TRUE;
2488
2489         /* Enchant weapon/armour */
2490         item_tester_hook = item_tester_hook_nameless_weapon_armour;
2491
2492         /* Get an item */
2493 #ifdef JP
2494         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶¯²½¤·¤Þ¤¹¤«? ";
2495         s = "¶¯²½¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
2496 #else
2497         q = "Enchant which item? ";
2498         s = "You have nothing to enchant.";
2499 #endif
2500
2501         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2502
2503         /* Get the item (in the pack) */
2504         if (item >= 0)
2505         {
2506                 o_ptr = &inventory[item];
2507         }
2508
2509         /* Get the item (on the floor) */
2510         else
2511         {
2512                 o_ptr = &o_list[0 - item];
2513         }
2514
2515
2516         /* Description */
2517         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2518
2519         /* Describe */
2520 #ifdef JP
2521         msg_format("%s ¤ÏâÁ¤¤¸÷¤òȯ¤·¤¿¡ª",o_name);
2522 #else
2523         msg_format("%s %s radiate%s a blinding light!",
2524                   ((item >= 0) ? "Your" : "The"), o_name,
2525                   ((o_ptr->number > 1) ? "" : "s"));
2526 #endif
2527
2528         if (object_is_artifact(o_ptr))
2529         {
2530 #ifdef JP
2531                 msg_format("%s¤Ï´û¤ËÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤Ç¤¹¡ª", o_name  );
2532 #else
2533                 msg_format("The %s %s already %s!",
2534                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2535                     ((o_ptr->number > 1) ? "artifacts" : "an artifact"));
2536 #endif
2537
2538                 okay = FALSE;
2539         }
2540
2541         else if (object_is_ego(o_ptr))
2542         {
2543 #ifdef JP
2544                 msg_format("%s¤Ï´û¤Ë̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¤Ç¤¹¡ª", o_name );
2545 #else
2546                 msg_format("The %s %s already %s!",
2547                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2548                     ((o_ptr->number > 1) ? "ego items" : "an ego item"));
2549 #endif
2550
2551                 okay = FALSE;
2552         }
2553
2554         else if (o_ptr->xtra3)
2555         {
2556 #ifdef JP
2557                 msg_format("%s¤Ï´û¤Ë¶¯²½¤µ¤ì¤Æ¤¤¤Þ¤¹¡ª", o_name );
2558 #else
2559                 msg_format("The %s %s already %s!",
2560                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2561                     ((o_ptr->number > 1) ? "customized items" : "a customized item"));
2562 #endif
2563         }
2564
2565         else
2566         {
2567                 if (o_ptr->number > 1)
2568                 {
2569 #ifdef JP
2570                         msg_print("Ê£¿ô¤Î¥¢¥¤¥Æ¥à¤ËËâË¡¤ò¤«¤±¤ë¤À¤±¤Î¥¨¥Í¥ë¥®¡¼¤Ï¤¢¤ê¤Þ¤»¤ó¡ª");
2571                         msg_format("%d ¸Ä¤Î%s¤¬²õ¤ì¤¿¡ª",(o_ptr->number)-1, o_name);
2572 #else
2573                         msg_print("Not enough enough energy to enchant more than one object!");
2574                         msg_format("%d of your %s %s destroyed!",(o_ptr->number)-1, o_name, (o_ptr->number>2?"were":"was"));
2575 #endif
2576
2577                         if (item >= 0)
2578                         {
2579                                 inven_item_increase(item, 1-(o_ptr->number));
2580                         }
2581                         else
2582                         {
2583                                 floor_item_increase(0-item, 1-(o_ptr->number));
2584                         }
2585                 }
2586                 okay = create_artifact(o_ptr, TRUE);
2587         }
2588
2589         /* Failure */
2590         if (!okay)
2591         {
2592                 /* Flush */
2593                 if (flush_failure) flush();
2594
2595                 /* Message */
2596 #ifdef JP
2597                 msg_print("¶¯²½¤Ë¼ºÇÔ¤·¤¿¡£");
2598 #else
2599                 msg_print("The enchantment failed.");
2600 #endif
2601
2602                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2603         }
2604         else
2605                 chg_virtue(V_ENCHANT, 1);
2606
2607         calc_android_exp();
2608
2609         /* Something happened */
2610         return (TRUE);
2611 }
2612
2613
2614 /*
2615  * Identify an object
2616  */
2617 bool identify_item(object_type *o_ptr)
2618 {
2619         bool old_known = FALSE;
2620         char o_name[MAX_NLEN];
2621
2622         /* Description */
2623         object_desc(o_name, o_ptr, 0);
2624
2625         if (o_ptr->ident & IDENT_KNOWN)
2626                 old_known = TRUE;
2627
2628         if (!(o_ptr->ident & (IDENT_MENTAL)))
2629         {
2630                 if (object_is_artifact(o_ptr) || one_in_(5))
2631                         chg_virtue(V_KNOWLEDGE, 1);
2632         }
2633
2634         /* Identify it fully */
2635         object_aware(o_ptr);
2636         object_known(o_ptr);
2637
2638         /* Recalculate bonuses */
2639         p_ptr->update |= (PU_BONUS);
2640
2641         /* Combine / Reorder the pack (later) */
2642         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
2643
2644         /* Window stuff */
2645         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2646
2647         strcpy(record_o_name, o_name);
2648         record_turn = turn;
2649
2650         /* Description */
2651         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2652
2653         if(record_fix_art && !old_known && object_is_fixed_artifact(o_ptr))
2654                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2655         if(record_rand_art && !old_known && o_ptr->art_name)
2656                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2657
2658         return old_known;
2659 }
2660
2661
2662 static bool item_tester_hook_identify(object_type *o_ptr)
2663 {
2664         return (bool)!object_is_known(o_ptr);
2665 }
2666
2667 static bool item_tester_hook_identify_weapon_armour(object_type *o_ptr)
2668 {
2669         if (object_is_known(o_ptr))
2670                 return FALSE;
2671         return object_is_weapon_armour_ammo(o_ptr);
2672 }
2673
2674 /*
2675  * Identify an object in the inventory (or on the floor)
2676  * This routine does *not* automatically combine objects.
2677  * Returns TRUE if something was identified, else FALSE.
2678  */
2679 bool ident_spell(bool only_equip)
2680 {
2681         int             item;
2682         object_type     *o_ptr;
2683         char            o_name[MAX_NLEN];
2684         cptr            q, s;
2685         bool old_known;
2686
2687         item_tester_no_ryoute = TRUE;
2688
2689         if (only_equip)
2690                 item_tester_hook = item_tester_hook_identify_weapon_armour;
2691         else
2692                 item_tester_hook = item_tester_hook_identify;
2693
2694         if (!can_get_item())
2695         {
2696                 if (only_equip)
2697                 {
2698                         item_tester_hook = object_is_weapon_armour_ammo;
2699                 }
2700                 else
2701                 {
2702                         item_tester_hook = NULL;
2703                 }
2704         }
2705
2706         /* Get an item */
2707 #ifdef JP
2708 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò´ÕÄꤷ¤Þ¤¹¤«? ";
2709 s = "´ÕÄꤹ¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
2710 #else
2711         q = "Identify which item? ";
2712         s = "You have nothing to identify.";
2713 #endif
2714
2715         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2716
2717         /* Get the item (in the pack) */
2718         if (item >= 0)
2719         {
2720                 o_ptr = &inventory[item];
2721         }
2722
2723         /* Get the item (on the floor) */
2724         else
2725         {
2726                 o_ptr = &o_list[0 - item];
2727         }
2728
2729         /* Identify it */
2730         old_known = identify_item(o_ptr);
2731
2732         /* Description */
2733         object_desc(o_name, o_ptr, 0);
2734
2735         /* Describe */
2736         if (item >= INVEN_RARM)
2737         {
2738 #ifdef JP
2739                 msg_format("%^s: %s(%c)¡£", describe_use(item), o_name, index_to_label(item));
2740 #else
2741                 msg_format("%^s: %s (%c).", describe_use(item), o_name, index_to_label(item));
2742 #endif
2743         }
2744         else if (item >= 0)
2745         {
2746 #ifdef JP
2747                 msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£", o_name, index_to_label(item));
2748 #else
2749                 msg_format("In your pack: %s (%c).", o_name, index_to_label(item));
2750 #endif
2751         }
2752         else
2753         {
2754 #ifdef JP
2755                 msg_format("¾²¾å: %s¡£", o_name);
2756 #else
2757                 msg_format("On the ground: %s.", o_name);
2758 #endif
2759         }
2760
2761         /* Auto-inscription/destroy */
2762         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2763
2764         /* Something happened */
2765         return (TRUE);
2766 }
2767
2768
2769 /*
2770  * Mundanify an object in the inventory (or on the floor)
2771  * This routine does *not* automatically combine objects.
2772  * Returns TRUE if something was mundanified, else FALSE.
2773  */
2774 bool mundane_spell(bool only_equip)
2775 {
2776         int             item;
2777         object_type     *o_ptr;
2778         cptr            q, s;
2779
2780         if (only_equip) item_tester_hook = object_is_weapon_armour_ammo;
2781         item_tester_no_ryoute = TRUE;
2782
2783         /* Get an item */
2784 #ifdef JP
2785 q = "¤É¤ì¤ò»È¤¤¤Þ¤¹¤«¡©";
2786 s = "»È¤¨¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£";
2787 #else
2788         q = "Use which item? ";
2789         s = "You have nothing you can use.";
2790 #endif
2791
2792         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2793
2794         /* Get the item (in the pack) */
2795         if (item >= 0)
2796         {
2797                 o_ptr = &inventory[item];
2798         }
2799
2800         /* Get the item (on the floor) */
2801         else
2802         {
2803                 o_ptr = &o_list[0 - item];
2804         }
2805
2806         /* Oops */
2807 #ifdef JP
2808         msg_print("¤Þ¤Ð¤æ¤¤Á®¸÷¤¬Áö¤Ã¤¿¡ª");
2809 #else
2810         msg_print("There is a bright flash of light!");
2811 #endif
2812         {
2813                 byte iy = o_ptr->iy;                 /* Y-position on map, or zero */
2814                 byte ix = o_ptr->ix;                 /* X-position on map, or zero */
2815                 s16b next_o_idx = o_ptr->next_o_idx; /* Next object in stack (if any) */
2816                 byte marked = o_ptr->marked;         /* Object is marked */
2817                 s16b weight = o_ptr->number * o_ptr->weight;
2818                 u16b inscription = o_ptr->inscription;
2819
2820                 /* Wipe it clean */
2821                 object_prep(o_ptr, o_ptr->k_idx);
2822
2823                 o_ptr->iy = iy;
2824                 o_ptr->ix = ix;
2825                 o_ptr->next_o_idx = next_o_idx;
2826                 o_ptr->marked = marked;
2827                 o_ptr->inscription = inscription;
2828                 if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
2829         }
2830         calc_android_exp();
2831
2832         /* Something happened */
2833         return TRUE;
2834 }
2835
2836
2837
2838 static bool item_tester_hook_identify_fully(object_type *o_ptr)
2839 {
2840         return (bool)(!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL));
2841 }
2842
2843 static bool item_tester_hook_identify_fully_weapon_armour(object_type *o_ptr)
2844 {
2845         if (!item_tester_hook_identify_fully(o_ptr))
2846                 return FALSE;
2847         return object_is_weapon_armour_ammo(o_ptr);
2848 }
2849
2850 /*
2851  * Fully "identify" an object in the inventory  -BEN-
2852  * This routine returns TRUE if an item was identified.
2853  */
2854 bool identify_fully(bool only_equip)
2855 {
2856         int             item;
2857         object_type     *o_ptr;
2858         char            o_name[MAX_NLEN];
2859         cptr            q, s;
2860         bool old_known;
2861
2862         item_tester_no_ryoute = TRUE;
2863         if (only_equip)
2864                 item_tester_hook = item_tester_hook_identify_fully_weapon_armour;
2865         else
2866                 item_tester_hook = item_tester_hook_identify_fully;
2867
2868         if (!can_get_item())
2869         {
2870                 if (only_equip)
2871                         item_tester_hook = object_is_weapon_armour_ammo;
2872                 else
2873                         item_tester_hook = NULL;
2874         }
2875
2876         /* Get an item */
2877 #ifdef JP
2878 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò´ÕÄꤷ¤Þ¤¹¤«? ";
2879 s = "´ÕÄꤹ¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
2880 #else
2881         q = "Identify which item? ";
2882         s = "You have nothing to identify.";
2883 #endif
2884
2885         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
2886
2887         /* Get the item (in the pack) */
2888         if (item >= 0)
2889         {
2890                 o_ptr = &inventory[item];
2891         }
2892
2893         /* Get the item (on the floor) */
2894         else
2895         {
2896                 o_ptr = &o_list[0 - item];
2897         }
2898
2899         /* Identify it */
2900         old_known = identify_item(o_ptr);
2901
2902         /* Mark the item as fully known */
2903         o_ptr->ident |= (IDENT_MENTAL);
2904
2905         /* Handle stuff */
2906         handle_stuff();
2907
2908         /* Description */
2909         object_desc(o_name, o_ptr, 0);
2910
2911         /* Describe */
2912         if (item >= INVEN_RARM)
2913         {
2914 #ifdef JP
2915                 msg_format("%^s: %s(%c)¡£", describe_use(item), o_name, index_to_label(item));
2916 #else
2917                 msg_format("%^s: %s (%c).", describe_use(item), o_name, index_to_label(item));
2918 #endif
2919
2920
2921         }
2922         else if (item >= 0)
2923         {
2924 #ifdef JP
2925                 msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£", o_name, index_to_label(item));
2926 #else
2927                 msg_format("In your pack: %s (%c).", o_name, index_to_label(item));
2928 #endif
2929         }
2930         else
2931         {
2932 #ifdef JP
2933                 msg_format("¾²¾å: %s¡£", o_name);
2934 #else
2935                 msg_format("On the ground: %s.", o_name);
2936 #endif
2937         }
2938
2939         /* Describe it fully */
2940         (void)screen_object(o_ptr, TRUE);
2941
2942         /* Auto-inscription/destroy */
2943         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2944
2945         /* Success */
2946         return (TRUE);
2947 }
2948
2949
2950
2951
2952 /*
2953  * Hook for "get_item()".  Determine if something is rechargable.
2954  */
2955 bool item_tester_hook_recharge(object_type *o_ptr)
2956 {
2957         /* Recharge staffs */
2958         if (o_ptr->tval == TV_STAFF) return (TRUE);
2959
2960         /* Recharge wands */
2961         if (o_ptr->tval == TV_WAND) return (TRUE);
2962
2963         /* Hack -- Recharge rods */
2964         if (o_ptr->tval == TV_ROD) return (TRUE);
2965
2966         /* Nope */
2967         return (FALSE);
2968 }
2969
2970
2971 /*
2972  * Recharge a wand/staff/rod from the pack or on the floor.
2973  * This function has been rewritten in Oangband and ZAngband.
2974  *
2975  * Sorcery/Arcane -- Recharge  --> recharge(plev * 4)
2976  * Chaos -- Arcane Binding     --> recharge(90)
2977  *
2978  * Scroll of recharging        --> recharge(130)
2979  * Artifact activation/Thingol --> recharge(130)
2980  *
2981  * It is harder to recharge high level, and highly charged wands,
2982  * staffs, and rods.  The more wands in a stack, the more easily and
2983  * strongly they recharge.  Staffs, however, each get fewer charges if
2984  * stacked.
2985  *
2986  * XXX XXX XXX Beware of "sliding index errors".
2987  */
2988 bool recharge(int power)
2989 {
2990         int item, lev;
2991         int recharge_strength, recharge_amount;
2992
2993         object_type *o_ptr;
2994         object_kind *k_ptr;
2995
2996         bool fail = FALSE;
2997         byte fail_type = 1;
2998
2999         cptr q, s;
3000         char o_name[MAX_NLEN];
3001
3002         /* Only accept legal items */
3003         item_tester_hook = item_tester_hook_recharge;
3004
3005         /* Get an item */
3006 #ifdef JP
3007 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ËËâÎϤò½¼Å¶¤·¤Þ¤¹¤«? ";
3008 s = "ËâÎϤò½¼Å¶¤¹¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
3009 #else
3010         q = "Recharge which item? ";
3011         s = "You have nothing to recharge.";
3012 #endif
3013
3014         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return (FALSE);
3015
3016         /* Get the item (in the pack) */
3017         if (item >= 0)
3018         {
3019                 o_ptr = &inventory[item];
3020         }
3021
3022         /* Get the item (on the floor) */
3023         else
3024         {
3025                 o_ptr = &o_list[0 - item];
3026         }
3027
3028         /* Get the object kind. */
3029         k_ptr = &k_info[o_ptr->k_idx];
3030
3031         /* Extract the object "level" */
3032         lev = k_info[o_ptr->k_idx].level;
3033
3034
3035         /* Recharge a rod */
3036         if (o_ptr->tval == TV_ROD)
3037         {
3038                 /* Extract a recharge strength by comparing object level to power. */
3039                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
3040
3041
3042                 /* Back-fire */
3043                 if (one_in_(recharge_strength))
3044                 {
3045                         /* Activate the failure code. */
3046                         fail = TRUE;
3047                 }
3048
3049                 /* Recharge */
3050                 else
3051                 {
3052                         /* Recharge amount */
3053                         recharge_amount = (power * damroll(3, 2));
3054
3055                         /* Recharge by that amount */
3056                         if (o_ptr->timeout > recharge_amount)
3057                                 o_ptr->timeout -= recharge_amount;
3058                         else
3059                                 o_ptr->timeout = 0;
3060                 }
3061         }
3062
3063
3064         /* Recharge wand/staff */
3065         else
3066         {
3067                 /* Extract a recharge strength by comparing object level to power.
3068                  * Divide up a stack of wands' charges to calculate charge penalty.
3069                  */
3070                 if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
3071                         recharge_strength = (100 + power - lev -
3072                         (8 * o_ptr->pval / o_ptr->number)) / 15;
3073
3074                 /* All staffs, unstacked wands. */
3075                 else recharge_strength = (100 + power - lev -
3076                         (8 * o_ptr->pval)) / 15;
3077
3078                 /* Paranoia */
3079                 if (recharge_strength < 0) recharge_strength = 0;
3080
3081                 /* Back-fire */
3082                 if (one_in_(recharge_strength))
3083                 {
3084                         /* Activate the failure code. */
3085                         fail = TRUE;
3086                 }
3087
3088                 /* If the spell didn't backfire, recharge the wand or staff. */
3089                 else
3090                 {
3091                         /* Recharge based on the standard number of charges. */
3092                         recharge_amount = randint1(1 + k_ptr->pval / 2);
3093
3094                         /* Multiple wands in a stack increase recharging somewhat. */
3095                         if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
3096                         {
3097                                 recharge_amount +=
3098                                         (randint1(recharge_amount * (o_ptr->number - 1))) / 2;
3099                                 if (recharge_amount < 1) recharge_amount = 1;
3100                                 if (recharge_amount > 12) recharge_amount = 12;
3101                         }
3102
3103                         /* But each staff in a stack gets fewer additional charges,
3104                          * although always at least one.
3105                          */
3106                         if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1))
3107                         {
3108                                 recharge_amount /= o_ptr->number;
3109                                 if (recharge_amount < 1) recharge_amount = 1;
3110                         }
3111
3112                         /* Recharge the wand or staff. */
3113                         o_ptr->pval += recharge_amount;
3114
3115
3116                         /* Hack -- we no longer "know" the item */
3117                         o_ptr->ident &= ~(IDENT_KNOWN);
3118
3119                         /* Hack -- we no longer think the item is empty */
3120                         o_ptr->ident &= ~(IDENT_EMPTY);
3121                 }
3122         }
3123
3124
3125         /* Inflict the penalties for failing a recharge. */
3126         if (fail)
3127         {
3128                 /* Artifacts are never destroyed. */
3129                 if (object_is_fixed_artifact(o_ptr))
3130                 {
3131                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
3132 #ifdef JP
3133 msg_format("ËâÎϤ¬µÕή¤·¤¿¡ª%s¤Ï´°Á´¤ËËâÎϤò¼º¤Ã¤¿¡£", o_name);
3134 #else
3135                         msg_format("The recharging backfires - %s is completely drained!", o_name);
3136 #endif
3137
3138
3139                         /* Artifact rods. */
3140                         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout < 10000))
3141                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
3142
3143                         /* Artifact wands and staffs. */
3144                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
3145                                 o_ptr->pval = 0;
3146                 }
3147                 else
3148                 {
3149                         /* Get the object description */
3150                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3151
3152                         /*** Determine Seriousness of Failure ***/
3153
3154                         /* Mages recharge objects more safely. */
3155                         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)
3156                         {
3157                                 /* 10% chance to blow up one rod, otherwise draining. */
3158                                 if (o_ptr->tval == TV_ROD)
3159                                 {
3160                                         if (one_in_(10)) fail_type = 2;
3161                                         else fail_type = 1;
3162                                 }
3163                                 /* 75% chance to blow up one wand, otherwise draining. */
3164                                 else if (o_ptr->tval == TV_WAND)
3165                                 {
3166                                         if (!one_in_(3)) fail_type = 2;
3167                                         else fail_type = 1;
3168                                 }
3169                                 /* 50% chance to blow up one staff, otherwise no effect. */
3170                                 else if (o_ptr->tval == TV_STAFF)
3171                                 {
3172                                         if (one_in_(2)) fail_type = 2;
3173                                         else fail_type = 0;
3174                                 }
3175                         }
3176
3177                         /* All other classes get no special favors. */
3178                         else
3179                         {
3180                                 /* 33% chance to blow up one rod, otherwise draining. */
3181                                 if (o_ptr->tval == TV_ROD)
3182                                 {
3183                                         if (one_in_(3)) fail_type = 2;
3184                                         else fail_type = 1;
3185                                 }
3186                                 /* 20% chance of the entire stack, else destroy one wand. */
3187                                 else if (o_ptr->tval == TV_WAND)
3188                                 {
3189                                         if (one_in_(5)) fail_type = 3;
3190                                         else fail_type = 2;
3191                                 }
3192                                 /* Blow up one staff. */
3193                                 else if (o_ptr->tval == TV_STAFF)
3194                                 {
3195                                         fail_type = 2;
3196                                 }
3197                         }
3198
3199                         /*** Apply draining and destruction. ***/
3200
3201                         /* Drain object or stack of objects. */
3202                         if (fail_type == 1)
3203                         {
3204                                 if (o_ptr->tval == TV_ROD)
3205                                 {
3206 #ifdef JP
3207 msg_print("ËâÎϤ¬µÕÊ®¼Í¤·¤Æ¡¢¥í¥Ã¥É¤«¤é¤µ¤é¤ËËâÎϤòµÛ¤¤¼è¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
3208 #else
3209                                         msg_print("The recharge backfires, draining the rod further!");
3210 #endif
3211
3212                                         if (o_ptr->timeout < 10000)
3213                                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
3214                                 }
3215                                 else if (o_ptr->tval == TV_WAND)
3216                                 {
3217 #ifdef JP
3218 msg_format("%s¤ÏÇË»¤òÌȤ줿¤¬¡¢ËâÎϤ¬Á´¤Æ¼º¤ï¤ì¤¿¡£", o_name);
3219 #else
3220                                         msg_format("You save your %s from destruction, but all charges are lost.", o_name);
3221 #endif
3222
3223                                         o_ptr->pval = 0;
3224                                 }
3225                                 /* Staffs aren't drained. */
3226                         }
3227
3228                         /* Destroy an object or one in a stack of objects. */
3229                         if (fail_type == 2)
3230                         {
3231                                 if (o_ptr->number > 1)
3232 #ifdef JP
3233 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬°ìËܲõ¤ì¤¿¡ª", o_name);
3234 #else
3235                                         msg_format("Wild magic consumes one of your %s!", o_name);
3236 #endif
3237
3238                                 else
3239 #ifdef JP
3240 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²õ¤ì¤¿¡ª", o_name);
3241 #else
3242                                         msg_format("Wild magic consumes your %s!", o_name);
3243 #endif
3244
3245
3246                                 /* Reduce rod stack maximum timeout, drain wands. */
3247                                 if (o_ptr->tval == TV_ROD) o_ptr->timeout = (o_ptr->number - 1) * k_ptr->pval;
3248                                 if (o_ptr->tval == TV_WAND) o_ptr->pval = 0;
3249
3250                                 /* Reduce and describe inventory */
3251                                 if (item >= 0)
3252                                 {
3253                                         inven_item_increase(item, -1);
3254                                         inven_item_describe(item);
3255                                         inven_item_optimize(item);
3256                                 }
3257
3258                                 /* Reduce and describe floor item */
3259                                 else
3260                                 {
3261                                         floor_item_increase(0 - item, -1);
3262                                         floor_item_describe(0 - item);
3263                                         floor_item_optimize(0 - item);
3264                                 }
3265                         }
3266
3267                         /* Destroy all members of a stack of objects. */
3268                         if (fail_type == 3)
3269                         {
3270                                 if (o_ptr->number > 1)
3271 #ifdef JP
3272 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬Á´¤Æ²õ¤ì¤¿¡ª", o_name);
3273 #else
3274                                         msg_format("Wild magic consumes all your %s!", o_name);
3275 #endif
3276
3277                                 else
3278 #ifdef JP
3279 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²õ¤ì¤¿¡ª", o_name);
3280 #else
3281                                         msg_format("Wild magic consumes your %s!", o_name);
3282 #endif
3283
3284
3285
3286                                 /* Reduce and describe inventory */
3287                                 if (item >= 0)
3288                                 {
3289                                         inven_item_increase(item, -999);
3290                                         inven_item_describe(item);
3291                                         inven_item_optimize(item);
3292                                 }
3293
3294                                 /* Reduce and describe floor item */
3295                                 else
3296                                 {
3297                                         floor_item_increase(0 - item, -999);
3298                                         floor_item_describe(0 - item);
3299                                         floor_item_optimize(0 - item);
3300                                 }
3301                         }
3302                 }
3303         }
3304
3305         /* Combine / Reorder the pack (later) */
3306         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
3307
3308         /* Window stuff */
3309         p_ptr->window |= (PW_INVEN);
3310
3311         /* Something was done */
3312         return (TRUE);
3313 }
3314
3315
3316 /*
3317  * Bless a weapon
3318  */
3319 bool bless_weapon(void)
3320 {
3321         int             item;
3322         object_type     *o_ptr;
3323         u32b flgs[TR_FLAG_SIZE];
3324         char            o_name[MAX_NLEN];
3325         cptr            q, s;
3326
3327         item_tester_no_ryoute = TRUE;
3328
3329         /* Bless only weapons */
3330         item_tester_hook = object_is_weapon;
3331
3332         /* Get an item */
3333 #ifdef JP
3334 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò½ËÊ¡¤·¤Þ¤¹¤«¡©";
3335 s = "½ËÊ¡¤Ç¤­¤ëÉð´ï¤¬¤¢¤ê¤Þ¤»¤ó¡£";
3336 #else
3337         q = "Bless which weapon? ";
3338         s = "You have weapon to bless.";
3339 #endif
3340
3341         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3342                 return FALSE;
3343
3344         /* Get the item (in the pack) */
3345         if (item >= 0)
3346         {
3347                 o_ptr = &inventory[item];
3348         }
3349
3350         /* Get the item (on the floor) */
3351         else
3352         {
3353                 o_ptr = &o_list[0 - item];
3354         }
3355
3356
3357         /* Description */
3358         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3359
3360         /* Extract the flags */
3361         object_flags(o_ptr, flgs);
3362
3363         if (object_is_cursed(o_ptr))
3364         {
3365                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) ||
3366                     (o_ptr->curse_flags & TRC_PERMA_CURSE))
3367                 {
3368 #ifdef JP
3369 msg_format("%s¤òʤ¤¦¹õ¤¤¥ª¡¼¥é¤Ï½ËÊ¡¤òÄ·¤ÍÊÖ¤·¤¿¡ª",
3370     o_name);
3371 #else
3372                         msg_format("The black aura on %s %s disrupts the blessing!",
3373                             ((item >= 0) ? "your" : "the"), o_name);
3374 #endif
3375
3376                         return TRUE;
3377                 }
3378
3379 #ifdef JP
3380 msg_format("%s ¤«¤é¼Ù°­¤Ê¥ª¡¼¥é¤¬¾Ã¤¨¤¿¡£",
3381     o_name);
3382 #else
3383                 msg_format("A malignant aura leaves %s %s.",
3384                     ((item >= 0) ? "your" : "the"), o_name);
3385 #endif
3386
3387
3388                 /* Uncurse it */
3389                 o_ptr->curse_flags = 0L;
3390
3391                 /* Hack -- Assume felt */
3392                 o_ptr->ident |= (IDENT_SENSE);
3393
3394                 /* Take note */
3395                 o_ptr->feeling = FEEL_NONE;
3396
3397                 /* Recalculate the bonuses */
3398                 p_ptr->update |= (PU_BONUS);
3399
3400                 /* Window stuff */
3401                 p_ptr->window |= (PW_EQUIP);
3402         }
3403
3404         /*
3405          * Next, we try to bless it. Artifacts have a 1/3 chance of
3406          * being blessed, otherwise, the operation simply disenchants
3407          * them, godly power negating the magic. Ok, the explanation
3408          * is silly, but otherwise priests would always bless every
3409          * artifact weapon they find. Ego weapons and normal weapons
3410          * can be blessed automatically.
3411          */
3412         if (have_flag(flgs, TR_BLESSED))
3413         {
3414 #ifdef JP
3415 msg_format("%s ¤Ï´û¤Ë½ËÊ¡¤µ¤ì¤Æ¤¤¤ë¡£",
3416     o_name    );
3417 #else
3418                 msg_format("%s %s %s blessed already.",
3419                     ((item >= 0) ? "Your" : "The"), o_name,
3420                     ((o_ptr->number > 1) ? "were" : "was"));
3421 #endif
3422
3423                 return TRUE;
3424         }
3425
3426         if (!(object_is_artifact(o_ptr) || object_is_ego(o_ptr)) || one_in_(3))
3427         {
3428                 /* Describe */
3429 #ifdef JP
3430 msg_format("%s¤Ïµ±¤¤¤¿¡ª",
3431      o_name);
3432 #else
3433                 msg_format("%s %s shine%s!",
3434                     ((item >= 0) ? "Your" : "The"), o_name,
3435                     ((o_ptr->number > 1) ? "" : "s"));
3436 #endif
3437
3438                 add_flag(o_ptr->art_flags, TR_BLESSED);
3439                 o_ptr->discount = 99;
3440         }
3441         else
3442         {
3443                 bool dis_happened = FALSE;
3444
3445 #ifdef JP
3446 msg_print("¤½¤ÎÉð´ï¤Ï½ËÊ¡¤ò·ù¤Ã¤Æ¤¤¤ë¡ª");
3447 #else
3448                 msg_print("The weapon resists your blessing!");
3449 #endif
3450
3451
3452                 /* Disenchant tohit */
3453                 if (o_ptr->to_h > 0)
3454                 {
3455                         o_ptr->to_h--;
3456                         dis_happened = TRUE;
3457                 }
3458
3459                 if ((o_ptr->to_h > 5) && (randint0(100) < 33)) o_ptr->to_h--;
3460
3461                 /* Disenchant todam */
3462                 if (o_ptr->to_d > 0)
3463                 {
3464                         o_ptr->to_d--;
3465                         dis_happened = TRUE;
3466                 }
3467
3468                 if ((o_ptr->to_d > 5) && (randint0(100) < 33)) o_ptr->to_d--;
3469
3470                 /* Disenchant toac */
3471                 if (o_ptr->to_a > 0)
3472                 {
3473                         o_ptr->to_a--;
3474                         dis_happened = TRUE;
3475                 }
3476
3477                 if ((o_ptr->to_a > 5) && (randint0(100) < 33)) o_ptr->to_a--;
3478
3479                 if (dis_happened)
3480                 {
3481 #ifdef JP
3482 msg_print("¼þ°Ï¤¬ËÞÍǤÊÊ·°Ïµ¤¤ÇËþ¤Á¤¿...");
3483 #else
3484                         msg_print("There is a static feeling in the air...");
3485 #endif
3486
3487 #ifdef JP
3488 msg_format("%s ¤ÏÎô²½¤·¤¿¡ª",
3489      o_name    );
3490 #else
3491                         msg_format("%s %s %s disenchanted!",
3492                             ((item >= 0) ? "Your" : "The"), o_name,
3493                             ((o_ptr->number > 1) ? "were" : "was"));
3494 #endif
3495
3496                 }
3497         }
3498
3499         /* Recalculate bonuses */
3500         p_ptr->update |= (PU_BONUS);
3501
3502         /* Window stuff */
3503         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
3504
3505         calc_android_exp();
3506
3507         return TRUE;
3508 }
3509
3510
3511 /*
3512  * pulish shield
3513  */
3514 bool pulish_shield(void)
3515 {
3516         int             item;
3517         object_type     *o_ptr;
3518         u32b flgs[TR_FLAG_SIZE];
3519         char            o_name[MAX_NLEN];
3520         cptr            q, s;
3521
3522         item_tester_no_ryoute = TRUE;
3523         /* Assume enchant weapon */
3524         item_tester_tval = TV_SHIELD;
3525
3526         /* Get an item */
3527 #ifdef JP
3528 q = "¤É¤Î½â¤òË᤭¤Þ¤¹¤«¡©";
3529 s = "Ë᤯½â¤¬¤¢¤ê¤Þ¤»¤ó¡£";
3530 #else
3531         q = "Pulish which weapon? ";
3532         s = "You have weapon to pulish.";
3533 #endif
3534
3535         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR)))
3536                 return FALSE;
3537
3538         /* Get the item (in the pack) */
3539         if (item >= 0)
3540         {
3541                 o_ptr = &inventory[item];
3542         }
3543
3544         /* Get the item (on the floor) */
3545         else
3546         {
3547                 o_ptr = &o_list[0 - item];
3548         }
3549
3550
3551         /* Description */
3552         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3553
3554         /* Extract the flags */
3555         object_flags(o_ptr, flgs);
3556
3557         if (o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) &&
3558             !object_is_cursed(o_ptr) && (o_ptr->sval != SV_MIRROR_SHIELD))
3559         {
3560 #ifdef JP
3561 msg_format("%s¤Ïµ±¤¤¤¿¡ª", o_name);
3562 #else
3563                 msg_format("%s %s shine%s!",
3564                     ((item >= 0) ? "Your" : "The"), o_name,
3565                     ((o_ptr->number > 1) ? "" : "s"));
3566 #endif
3567                 o_ptr->name2 = EGO_REFLECTION;
3568                 enchant(o_ptr, randint0(3) + 4, ENCH_TOAC);
3569
3570                 o_ptr->discount = 99;
3571                 chg_virtue(V_ENCHANT, 2);
3572
3573                 return TRUE;
3574         }
3575         else
3576         {
3577                 if (flush_failure) flush();
3578
3579 #ifdef JP
3580 msg_print("¼ºÇÔ¤·¤¿¡£");
3581 #else
3582                 msg_print("Failed.");
3583 #endif
3584
3585                 chg_virtue(V_ENCHANT, -2);
3586         }
3587         calc_android_exp();
3588
3589         return FALSE;
3590 }
3591
3592
3593 /*
3594  * Potions "smash open" and cause an area effect when
3595  * (1) they are shattered while in the player's inventory,
3596  * due to cold (etc) attacks;
3597  * (2) they are thrown at a monster, or obstacle;
3598  * (3) they are shattered by a "cold ball" or other such spell
3599  * while lying on the floor.
3600  *
3601  * Arguments:
3602  *    who   ---  who caused the potion to shatter (0=player)
3603  *          potions that smash on the floor are assumed to
3604  *          be caused by no-one (who = 1), as are those that
3605  *          shatter inside the player inventory.
3606  *          (Not anymore -- I changed this; TY)
3607  *    y, x  --- coordinates of the potion (or player if
3608  *          the potion was in her inventory);
3609  *    o_ptr --- pointer to the potion object.
3610  */
3611 bool potion_smash_effect(int who, int y, int x, int k_idx)
3612 {
3613         int     radius = 2;
3614         int     dt = 0;
3615         int     dam = 0;
3616         bool    angry = FALSE;
3617
3618         object_kind *k_ptr = &k_info[k_idx];
3619
3620         switch (k_ptr->sval)
3621         {
3622                 case SV_POTION_SALT_WATER:
3623                 case SV_POTION_SLIME_MOLD:
3624                 case SV_POTION_LOSE_MEMORIES:
3625                 case SV_POTION_DEC_STR:
3626                 case SV_POTION_DEC_INT:
3627                 case SV_POTION_DEC_WIS:
3628                 case SV_POTION_DEC_DEX:
3629                 case SV_POTION_DEC_CON:
3630                 case SV_POTION_DEC_CHR:
3631                 case SV_POTION_WATER:   /* perhaps a 'water' attack? */
3632                 case SV_POTION_APPLE_JUICE:
3633                         return TRUE;
3634
3635                 case SV_POTION_INFRAVISION:
3636                 case SV_POTION_DETECT_INVIS:
3637                 case SV_POTION_SLOW_POISON:
3638                 case SV_POTION_CURE_POISON:
3639                 case SV_POTION_BOLDNESS:
3640                 case SV_POTION_RESIST_HEAT:
3641                 case SV_POTION_RESIST_COLD:
3642                 case SV_POTION_HEROISM:
3643                 case SV_POTION_BESERK_STRENGTH:
3644                 case SV_POTION_RES_STR:
3645                 case SV_POTION_RES_INT:
3646                 case SV_POTION_RES_WIS:
3647                 case SV_POTION_RES_DEX:
3648                 case SV_POTION_RES_CON:
3649                 case SV_POTION_RES_CHR:
3650                 case SV_POTION_INC_STR:
3651                 case SV_POTION_INC_INT:
3652                 case SV_POTION_INC_WIS:
3653                 case SV_POTION_INC_DEX:
3654                 case SV_POTION_INC_CON:
3655                 case SV_POTION_INC_CHR:
3656                 case SV_POTION_AUGMENTATION:
3657                 case SV_POTION_ENLIGHTENMENT:
3658                 case SV_POTION_STAR_ENLIGHTENMENT:
3659                 case SV_POTION_SELF_KNOWLEDGE:
3660                 case SV_POTION_EXPERIENCE:
3661                 case SV_POTION_RESISTANCE:
3662                 case SV_POTION_INVULNERABILITY:
3663                 case SV_POTION_NEW_LIFE:
3664                         /* All of the above potions have no effect when shattered */
3665                         return FALSE;
3666                 case SV_POTION_SLOWNESS:
3667                         dt = GF_OLD_SLOW;
3668                         dam = 5;
3669                         angry = TRUE;
3670                         break;
3671                 case SV_POTION_POISON:
3672                         dt = GF_POIS;
3673                         dam = 3;
3674                         angry = TRUE;
3675                         break;
3676                 case SV_POTION_BLINDNESS:
3677                         dt = GF_DARK;
3678                         angry = TRUE;
3679                         break;
3680                 case SV_POTION_CONFUSION: /* Booze */
3681                         dt = GF_OLD_CONF;
3682                         angry = TRUE;
3683                         break;
3684                 case SV_POTION_SLEEP:
3685                         dt = GF_OLD_SLEEP;
3686                         angry = TRUE;
3687                         break;
3688                 case SV_POTION_RUINATION:
3689                 case SV_POTION_DETONATIONS:
3690                         dt = GF_SHARDS;
3691                         dam = damroll(25, 25);
3692                         angry = TRUE;
3693                         break;
3694                 case SV_POTION_DEATH:
3695                         dt = GF_DEATH_RAY;    /* !! */
3696                         dam = k_ptr->level * 10;
3697                         angry = TRUE;
3698                         radius = 1;
3699                         break;
3700                 case SV_POTION_SPEED:
3701                         dt = GF_OLD_SPEED;
3702                         break;
3703                 case SV_POTION_CURE_LIGHT:
3704                         dt = GF_OLD_HEAL;
3705                         dam = damroll(2, 3);
3706                         break;
3707                 case SV_POTION_CURE_SERIOUS:
3708                         dt = GF_OLD_HEAL;
3709                         dam = damroll(4, 3);
3710                         break;
3711                 case SV_POTION_CURE_CRITICAL:
3712                 case SV_POTION_CURING:
3713                         dt = GF_OLD_HEAL;
3714                         dam = damroll(6, 3);
3715                         break;
3716                 case SV_POTION_HEALING:
3717                         dt = GF_OLD_HEAL;
3718                         dam = damroll(10, 10);
3719                         break;
3720                 case SV_POTION_RESTORE_EXP:
3721                         dt = GF_STAR_HEAL;
3722                         dam = 0;
3723                         radius = 1;
3724                         break;
3725                 case SV_POTION_LIFE:
3726                         dt = GF_STAR_HEAL;
3727                         dam = damroll(50, 50);
3728                         radius = 1;
3729                         break;
3730                 case SV_POTION_STAR_HEALING:
3731                         dt = GF_OLD_HEAL;
3732                         dam = damroll(50, 50);
3733                         radius = 1;
3734                         break;
3735                 case SV_POTION_RESTORE_MANA:   /* MANA */
3736                         dt = GF_MANA;
3737                         dam = damroll(10, 10);
3738                         radius = 1;
3739                         break;
3740                 default:
3741                         /* Do nothing */  ;
3742         }
3743
3744         (void)project(who, radius, y, x, dam, dt,
3745             (PROJECT_JUMP | PROJECT_ITEM | PROJECT_KILL), -1);
3746
3747         /* XXX  those potions that explode need to become "known" */
3748         return angry;
3749 }
3750
3751
3752 /*
3753  * Hack -- Display all known spells in a window
3754  *
3755  * XXX XXX XXX Need to analyze size of the window.
3756  *
3757  * XXX XXX XXX Need more color coding.
3758  */
3759 void display_spell_list(void)
3760 {
3761         int             i, j;
3762         int             y, x;
3763         int             m[9];
3764         magic_type      *s_ptr;
3765         char            name[80];
3766         char            out_val[160];
3767
3768
3769         /* Erase window */
3770         clear_from(0);
3771
3772         /* They have too many spells to list */
3773         if (p_ptr->pclass == CLASS_SORCERER) return;
3774         if (p_ptr->pclass == CLASS_RED_MAGE) return;
3775
3776         /* mind.c type classes */
3777         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
3778             (p_ptr->pclass == CLASS_BERSERKER) ||
3779             (p_ptr->pclass == CLASS_NINJA) ||
3780             (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
3781             (p_ptr->pclass == CLASS_FORCETRAINER))
3782         {
3783                 int             i;
3784                 int             y = 1;
3785                 int             x = 1;
3786                 int             minfail = 0;
3787                 int             plev = p_ptr->lev;
3788                 int             chance = 0;
3789                 mind_type       spell;
3790                 char            comment[80];
3791                 char            psi_desc[80];
3792                 int             use_mind;
3793                 bool use_hp = FALSE;
3794
3795                 /* Display a list of spells */
3796                 prt("", y, x);
3797 #ifdef JP
3798 put_str("̾Á°", y, x + 5);
3799 put_str("Lv   MP ¼ºÎ¨ ¸ú²Ì", y, x + 35);
3800 #else
3801                 put_str("Name", y, x + 5);
3802                 put_str("Lv Mana Fail Info", y, x + 35);
3803 #endif
3804
3805                 switch(p_ptr->pclass)
3806                 {
3807                 case CLASS_MINDCRAFTER: use_mind = MIND_MINDCRAFTER;break;
3808                 case CLASS_FORCETRAINER:          use_mind = MIND_KI;break;
3809                 case CLASS_BERSERKER: use_mind = MIND_BERSERKER; use_hp = TRUE; break;
3810                 case CLASS_MIRROR_MASTER: use_mind = MIND_MIRROR_MASTER; break;
3811                 case CLASS_NINJA: use_mind = MIND_NINJUTSU; use_hp = TRUE; break;
3812                 default:                use_mind = 0;break;
3813                 }
3814
3815                 /* Dump the spells */
3816                 for (i = 0; i < MAX_MIND_POWERS; i++)
3817                 {
3818                         byte a = TERM_WHITE;
3819
3820                         /* Access the available spell */
3821                         spell = mind_powers[use_mind].info[i];
3822                         if (spell.min_lev > plev) break;
3823
3824                         /* Get the failure rate */
3825                         chance = spell.fail;
3826
3827                         /* Reduce failure rate by "effective" level adjustment */
3828                         chance -= 3 * (p_ptr->lev - spell.min_lev);
3829
3830                         /* Reduce failure rate by INT/WIS adjustment */
3831                         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
3832
3833                         if (!use_hp)
3834                         {
3835                                 /* Not enough mana to cast */
3836                                 if (spell.mana_cost > p_ptr->csp)
3837                                 {
3838                                         chance += 5 * (spell.mana_cost - p_ptr->csp);
3839                                         a = TERM_ORANGE;
3840                                 }
3841                         }
3842                         else
3843                         {
3844                                 /* Not enough hp to cast */
3845                                 if (spell.mana_cost > p_ptr->chp)
3846                                 {
3847                                         chance += 100;
3848                                         a = TERM_RED;
3849                                 }
3850                         }
3851
3852                         /* Extract the minimum failure rate */
3853                         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
3854
3855                         /* Minimum failure rate */
3856                         if (chance < minfail) chance = minfail;
3857
3858                         /* Stunning makes spells harder */
3859                         if (p_ptr->stun > 50) chance += 25;
3860                         else if (p_ptr->stun) chance += 15;
3861
3862                         /* Always a 5 percent chance of working */
3863                         if (chance > 95) chance = 95;
3864
3865                         /* Get info */
3866                         mindcraft_info(comment, use_mind, i);
3867
3868                         /* Dump the spell */
3869                         sprintf(psi_desc, "  %c) %-30s%2d %4d %3d%%%s",
3870                             I2A(i), spell.name,
3871                             spell.min_lev, spell.mana_cost, chance, comment);
3872
3873                         Term_putstr(x, y + i + 1, -1, a, psi_desc);
3874                 }
3875                 return;
3876         }
3877
3878         /* Cannot read spellbooks */
3879         if (REALM_NONE == p_ptr->realm1) return;
3880
3881         /* Normal spellcaster with books */
3882
3883         /* Scan books */
3884         for (j = 0; j < ((p_ptr->realm2 > REALM_NONE) ? 2 : 1); j++)
3885         {
3886                 int n = 0;
3887
3888                 /* Reset vertical */
3889                 m[j] = 0;
3890
3891                 /* Vertical location */
3892                 y = (j < 3) ? 0 : (m[j - 3] + 2);
3893
3894                 /* Horizontal location */
3895                 x = 27 * (j % 3);
3896
3897                 /* Scan spells */
3898                 for (i = 0; i < 32; i++)
3899                 {
3900                         byte a = TERM_WHITE;
3901
3902                         /* Access the spell */
3903                         if (!is_magic((j < 1) ? p_ptr->realm1 : p_ptr->realm2))
3904                         {
3905                                 s_ptr = &technic_info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - MIN_TECHNIC][i % 32];
3906                         }
3907                         else
3908                         {
3909                                 s_ptr = &mp_ptr->info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - 1][i % 32];
3910                         }
3911
3912                         strcpy(name, spell_names[technic2magic((j < 1) ? p_ptr->realm1 : p_ptr->realm2)-1][i % 32]);
3913
3914                         /* Illegible */
3915                         if (s_ptr->slevel >= 99)
3916                         {
3917                                 /* Illegible */
3918 #ifdef JP
3919 strcpy(name, "(ȽÆÉÉÔǽ)");
3920 #else
3921                                 strcpy(name, "(illegible)");
3922 #endif
3923
3924
3925                                 /* Unusable */
3926                                 a = TERM_L_DARK;
3927                         }
3928
3929                         /* Forgotten */
3930                         else if ((j < 1) ?
3931                                 ((p_ptr->spell_forgotten1 & (1L << i))) :
3932                                 ((p_ptr->spell_forgotten2 & (1L << (i % 32)))))
3933                         {
3934                                 /* Forgotten */
3935                                 a = TERM_ORANGE;
3936                         }
3937
3938                         /* Unknown */
3939                         else if (!((j < 1) ?
3940                                 (p_ptr->spell_learned1 & (1L << i)) :
3941                                 (p_ptr->spell_learned2 & (1L << (i % 32)))))
3942                         {
3943                                 /* Unknown */
3944                                 a = TERM_RED;
3945                         }
3946
3947                         /* Untried */
3948                         else if (!((j < 1) ?
3949                                 (p_ptr->spell_worked1 & (1L << i)) :
3950                                 (p_ptr->spell_worked2 & (1L << (i % 32)))))
3951                         {
3952                                 /* Untried */
3953                                 a = TERM_YELLOW;
3954                         }
3955
3956                         /* Dump the spell --(-- */
3957                         sprintf(out_val, "%c/%c) %-20.20s",
3958                                 I2A(n / 8), I2A(n % 8), name);
3959
3960                         /* Track maximum */
3961                         m[j] = y + n;
3962
3963                         /* Dump onto the window */
3964                         Term_putstr(x, m[j], -1, a, out_val);
3965
3966                         /* Next */
3967                         n++;
3968                 }
3969         }
3970 }
3971
3972
3973 /*
3974  * Returns experience of a spell
3975  */
3976 s16b experience_of_spell(int spell, int use_realm)
3977 {
3978         if (p_ptr->pclass == CLASS_SORCERER) return SPELL_EXP_MASTER;
3979         else if (p_ptr->pclass == CLASS_RED_MAGE) return SPELL_EXP_SKILLED;
3980         else if (use_realm == p_ptr->realm1) return p_ptr->spell_exp[spell];
3981         else if (use_realm == p_ptr->realm2) return p_ptr->spell_exp[spell + 32];
3982         else return 0;
3983 }
3984
3985
3986 /*
3987  * Modify mana consumption rate using spell exp and p_ptr->dec_mana
3988  */
3989 int mod_need_mana(int need_mana, int spell, int realm)
3990 {
3991 #define MANA_CONST   2400
3992 #define MANA_DIV        4
3993 #define DEC_MANA_DIV    3
3994
3995         /* Realm magic */
3996         if ((realm > REALM_NONE) && (realm <= MAX_REALM))
3997         {
3998                 /*
3999                  * need_mana defaults if spell exp equals SPELL_EXP_EXPERT and !p_ptr->dec_mana.
4000                  * MANA_CONST is used to calculate need_mana effected from spell proficiency.
4001                  */
4002                 need_mana = need_mana * (MANA_CONST + SPELL_EXP_EXPERT - experience_of_spell(spell, realm)) + (MANA_CONST - 1);
4003                 need_mana *= p_ptr->dec_mana ? DEC_MANA_DIV : MANA_DIV;
4004                 need_mana /= MANA_CONST * MANA_DIV;
4005                 if (need_mana < 1) need_mana = 1;
4006         }
4007
4008         /* Non-realm magic */
4009         else
4010         {
4011                 if (p_ptr->dec_mana) need_mana = (need_mana + 1) * DEC_MANA_DIV / MANA_DIV;
4012         }
4013
4014 #undef DEC_MANA_DIV
4015 #undef MANA_DIV
4016 #undef MANA_CONST
4017
4018         return need_mana;
4019 }
4020
4021
4022 /*
4023  * Modify spell fail rate
4024  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
4025  */
4026 int mod_spell_chance_1(int chance)
4027 {
4028         chance += p_ptr->to_m_chance;
4029
4030         if (p_ptr->heavy_spell) chance += 20;
4031
4032         if (p_ptr->dec_mana && p_ptr->easy_spell) chance -= 4;
4033         else if (p_ptr->easy_spell) chance -= 3;
4034         else if (p_ptr->dec_mana) chance -= 2;
4035
4036         return chance;
4037 }
4038
4039
4040 /*
4041  * Modify spell fail rate (as "suffix" process)
4042  * Using p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
4043  * Note: variable "chance" cannot be negative.
4044  */
4045 int mod_spell_chance_2(int chance)
4046 {
4047         if (p_ptr->dec_mana) chance--;
4048
4049         if (p_ptr->heavy_spell) chance += 5;
4050
4051         return MAX(chance, 0);
4052 }
4053
4054
4055 /*
4056  * Returns spell chance of failure for spell -RAK-
4057  */
4058 s16b spell_chance(int spell, int use_realm)
4059 {
4060         int             chance, minfail;
4061         magic_type      *s_ptr;
4062         int             need_mana;
4063         int penalty = (mp_ptr->spell_stat == A_WIS) ? 10 : 4;
4064
4065
4066         /* Paranoia -- must be literate */
4067         if (!mp_ptr->spell_book) return (100);
4068
4069         if (use_realm == REALM_HISSATSU) return 0;
4070
4071         /* Access the spell */
4072         if (!is_magic(use_realm))
4073         {
4074                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4075         }
4076         else
4077         {
4078                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
4079         }
4080
4081         /* Extract the base spell failure rate */
4082         chance = s_ptr->sfail;
4083
4084         /* Reduce failure rate by "effective" level adjustment */
4085         chance -= 3 * (p_ptr->lev - s_ptr->slevel);
4086
4087         /* Reduce failure rate by INT/WIS adjustment */
4088         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
4089
4090         if (p_ptr->riding)
4091                 chance += (MAX(r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 100 - 10, 0));
4092
4093         /* Extract mana consumption rate */
4094         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
4095
4096         /* Not enough mana to cast */
4097         if (need_mana > p_ptr->csp)
4098         {
4099                 chance += 5 * (need_mana - p_ptr->csp);
4100         }
4101
4102         if ((use_realm != p_ptr->realm1) && ((p_ptr->pclass == CLASS_MAGE) || (p_ptr->pclass == CLASS_PRIEST))) chance += 5;
4103
4104         /* Extract the minimum failure rate */
4105         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
4106
4107         /*
4108          * Non mage/priest characters never get too good
4109          * (added high mage, mindcrafter)
4110          */
4111         if (mp_ptr->spell_xtra & MAGIC_FAIL_5PERCENT)
4112         {
4113                 if (minfail < 5) minfail = 5;
4114         }
4115
4116         /* Hack -- Priest prayer penalty for "edged" weapons  -DGK */
4117         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[0]) chance += 25;
4118         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[1]) chance += 25;
4119
4120         chance = mod_spell_chance_1(chance);
4121
4122         if ((use_realm == REALM_NATURE) && ((p_ptr->align > 50) || (p_ptr->align < -50))) chance += penalty;
4123         if (((use_realm == REALM_LIFE) || (use_realm == REALM_CRUSADE)) && (p_ptr->align < -20)) chance += penalty;
4124         if (((use_realm == REALM_DEATH) || (use_realm == REALM_DAEMON)) && (p_ptr->align > 20)) chance += penalty;
4125
4126         /* Minimum failure rate */
4127         if (chance < minfail) chance = minfail;
4128
4129         /* Stunning makes spells harder */
4130         if (p_ptr->stun > 50) chance += 25;
4131         else if (p_ptr->stun) chance += 15;
4132
4133         /* Always a 5 percent chance of working */
4134         if (chance > 95) chance = 95;
4135
4136         if ((use_realm == p_ptr->realm1) || (use_realm == p_ptr->realm2)
4137             || (p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4138         {
4139                 s16b exp = experience_of_spell(spell, use_realm);
4140                 if (exp >= SPELL_EXP_EXPERT) chance--;
4141                 if (exp >= SPELL_EXP_MASTER) chance--;
4142         }
4143
4144         /* Return the chance */
4145         return mod_spell_chance_2(chance);
4146 }
4147
4148
4149
4150 /*
4151  * Determine if a spell is "okay" for the player to cast or study
4152  * The spell must be legible, not forgotten, and also, to cast,
4153  * it must be known, and to study, it must not be known.
4154  */
4155 bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
4156 {
4157         magic_type *s_ptr;
4158
4159         /* Access the spell */
4160         if (!is_magic(use_realm))
4161         {
4162                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4163         }
4164         else
4165         {
4166                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
4167         }
4168
4169         /* Spell is illegal */
4170         if (s_ptr->slevel > p_ptr->lev) return (FALSE);
4171
4172         /* Spell is forgotten */
4173         if ((use_realm == p_ptr->realm2) ?
4174             (p_ptr->spell_forgotten2 & (1L << spell)) :
4175             (p_ptr->spell_forgotten1 & (1L << spell)))
4176         {
4177                 /* Never okay */
4178                 return (FALSE);
4179         }
4180
4181         if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
4182         if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
4183
4184         /* Spell is learned */
4185         if ((use_realm == p_ptr->realm2) ?
4186             (p_ptr->spell_learned2 & (1L << spell)) :
4187             (p_ptr->spell_learned1 & (1L << spell)))
4188         {
4189                 /* Always true */
4190                 return (!study_pray);
4191         }
4192
4193         /* Okay to study, not to cast */
4194         return (!learned);
4195 }
4196
4197
4198
4199 /*
4200  * Extra information on a spell -DRS-
4201  *
4202  * We can use up to 14 characters of the buffer 'p'
4203  *
4204  * The strings in this function were extracted from the code in the
4205  * functions "do_cmd_cast()" and "do_cmd_pray()" and may be dated.
4206  */
4207 static void spell_info(char *p, int spell, int use_realm)
4208 {
4209         int plev = p_ptr->lev;
4210
4211         /* See below */
4212         int orb = plev + (plev / ((p_ptr->pclass == CLASS_PRIEST ||
4213                             p_ptr->pclass == CLASS_HIGH_MAGE ||
4214                             p_ptr->pclass == CLASS_SORCERER) ? 2 : 4));
4215
4216         int burst = plev + (plev / ((p_ptr->pclass == CLASS_MAGE ||
4217                                      p_ptr->pclass == CLASS_HIGH_MAGE ||
4218                                      p_ptr->pclass == CLASS_SORCERER) ? 2 : 4));
4219 #ifdef JP
4220         cptr s_dam = "»½ý:";
4221         cptr s_dur = "´ü´Ö:";
4222         cptr s_range = "ÈÏ°Ï:";
4223         cptr s_heal = "²óÉü:";
4224         cptr s_random = "¥é¥ó¥À¥à";
4225         cptr s_delay = "ÃÙ±ä:";
4226 #else
4227         cptr s_dam = "dam ";
4228         cptr s_dur = "dur ";
4229         cptr s_range = "range ";
4230         cptr s_heal = "heal ";
4231         cptr s_random = "random";
4232         cptr s_delay = "delay ";
4233 #endif
4234         /* Default */
4235         strcpy(p, "");
4236
4237         /* Analyze the spell */
4238         switch (use_realm)
4239         {
4240         case REALM_LIFE: /* Life */
4241                 switch (spell)
4242                 {
4243                 case  0: sprintf(p, " %s2d10", s_heal); break;
4244                 case  1: sprintf(p, " %s12+d12", s_dur); break;
4245                 case  2: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4246                 case  3: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4247                 case  5: sprintf(p, " %s4d10", s_heal); break;
4248                 case  9: sprintf(p, " %s%dd8", s_dam, 8 + ((plev - 1) / 5)); break;
4249                 case 10: sprintf(p, " %s8d10", s_heal); break;
4250                 case 11: sprintf(p, " %s20+d20", s_dur); break;
4251                 case 14: sprintf(p, " %s300", s_heal); break;
4252                 case 18: sprintf(p, " %sd%d", s_dam, 5 * plev); break;
4253                 case 20: sprintf(p, " %s%dd15", s_dam, 5 + ((plev - 1) / 3)); break;
4254                 case 21: sprintf(p, " %s15+d21", s_delay); break;
4255                 case 29: sprintf(p, " %s2000", s_heal); break;
4256                 case 31: sprintf(p, " %s%d+d%d", s_dur,(plev/2), (plev/2)); break;
4257                 }
4258                 break;
4259                 
4260         case REALM_SORCERY: /* Sorcery */
4261                 switch (spell)
4262                 {
4263                 case  1: sprintf(p, " %s10", s_range); break;
4264                 case  3: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4265                 case  5: sprintf(p, " %s%d", s_range, plev * 5); break;
4266                 case 13: sprintf(p, " %s%d+d%d", s_dur, plev, plev + 20); break;
4267                 case 18: sprintf(p, " %s25+d30", s_dur); break;
4268                 case 22: sprintf(p, " %s15+d21", s_delay); break;
4269                 case 23: sprintf(p, " %s%d", s_range, plev / 2 + 10); break;
4270                 case 25: sprintf(p, " %s7d7+%d", s_dam, plev); break;
4271 #ifdef JP
4272                 case 26: sprintf(p, " ºÇÂç½ÅÎÌ:%d.%dkg", lbtokg1(plev * 15),lbtokg2(plev * 15)); break;
4273 #else
4274                 case 26: sprintf(p, " max wgt %d", plev * 15 / 10); break;
4275 #endif
4276                 case 27: sprintf(p, " %s25+d30", s_dur); break;
4277                 case 31: sprintf(p, " %s4+d4", s_dur); break;
4278                 }
4279                 break;
4280                 
4281         case REALM_NATURE: /* Nature */
4282                 switch (spell)
4283                 {
4284 #ifdef JP
4285                 case  1: sprintf(p, " %s%dd4 ¼ÍÄø%d", s_dam, (3 + ((plev - 1) / 5)), plev/6+2); break;
4286 #else
4287                 case  1: sprintf(p, " %s%dd4 rng %d", s_dam, (3 + ((plev - 1) / 5)), plev/6+2); break;
4288 #endif
4289                 case  4: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4290                 case  6: sprintf(p, " %s20+d20", s_dur); break;
4291                 case  7: sprintf(p, " %s2d8", s_heal); break;
4292                 case  9: sprintf(p, " %s%dd8", s_dam, (3 + ((plev - 5) / 4))); break;
4293                 case 11: sprintf(p, " %s%dd8", s_dam, (5 + ((plev - 5) / 4))); break;
4294                 case 12: sprintf(p, " %s6d8", s_dam); break;
4295                 case 15: sprintf(p, " %s500", s_heal); break;
4296                 case 17: sprintf(p, " %s20+d30", s_dur); break;
4297                 case 18: sprintf(p, " %s20+d20", s_dur); break;
4298 #ifdef JP
4299                 case 24: sprintf(p, " È¾·Â:10"); break;
4300 #else
4301                 case 24: sprintf(p, " rad 10"); break;
4302 #endif
4303                 case 26: sprintf(p, " %s%d", s_dam, 70 + plev * 3 / 2); break;
4304                 case 27: sprintf(p, " %s%d", s_dam, 90 + plev * 3 / 2); break;
4305                 case 28: sprintf(p, " %s%d", s_dam, 100 + plev * 3 / 2); break;
4306                 case 29: sprintf(p, " %s75", s_dam); break;
4307                 case 31: sprintf(p, " %s%d+%d", s_dam, 4 * plev, 100 + plev); break;
4308                 }
4309                 break;
4310                 
4311         case REALM_CHAOS: /* Chaos */
4312                 switch (spell)
4313                 {
4314                 case  0: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4315                 case  2: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4316                 case  4: sprintf(p, " %s3d5+%d", s_dam, burst); break;
4317                 case  5: sprintf(p, " %s%dd8", s_dam, (6 + ((plev - 5) / 4))); break;
4318                 case  6: sprintf(p, " %s%dd8", s_dam, (8 + ((plev - 5) / 4))); break;
4319                 case  7: sprintf(p, " %s%d", s_range, plev * 5); break;
4320                 case  8: sprintf(p, " %s", s_random); break;
4321                 case  9: sprintf(p, " %s%dd8", s_dam, (10 + ((plev - 5) / 4))); break;
4322                 case 10: sprintf(p, " %s%d", s_dam, (60 + plev)/2); break;
4323                 case 11: sprintf(p, " %s%dd8", s_dam, (11 + ((plev - 5) / 4))); break;
4324                 case 12: sprintf(p, " %s%d", s_dam, 55 + plev); break;
4325                 case 15: sprintf(p, " %s%d", s_dam, 99 + plev*2); break;
4326                 case 17: sprintf(p, " %s%dd8", s_dam, (5 + (plev / 10))); break;
4327                 case 19: sprintf(p, " %s%d", s_dam, 70 + plev); break;
4328                 case 21: sprintf(p, " %s%d", s_dam, 120 + plev*2); break;
4329                 case 24: sprintf(p, " %s%dd8", s_dam, (9 + (plev / 10))); break;
4330 #ifdef JP
4331                 case 25: sprintf(p, " %s³Æ%d", s_dam, plev * 2); break;
4332 #else
4333                 case 25: sprintf(p, " dam %d each", plev * 2); break;
4334 #endif
4335                 case 26: sprintf(p, " %s%d", s_dam, 150 + plev*3/2); break;
4336                 case 27: sprintf(p, " %s150 / 250", s_dam); break;
4337                 case 29: sprintf(p, " %s%d", s_dam, 300 + (plev * 4)); break;
4338                 case 30: sprintf(p, " %s%ld", s_dam, p_ptr->chp); break;
4339                 case 31: sprintf(p, " %s3 * 175", s_dam); break;
4340                 }
4341                 break;
4342                 
4343         case REALM_DEATH: /* Death */
4344                 switch (spell)
4345                 {
4346                 case  1: sprintf(p, " %s%dd3", s_dam, (3 + ((plev - 1) / 5))); break;
4347                 case  3: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
4348                 case  5: sprintf(p, " %s20+d20", s_dur); break;
4349                 case  8: sprintf(p, " %s3d6+%d", s_dam, burst); break;
4350                 case  9: sprintf(p, " %s%dd8", s_dam, (8 + ((plev - 5) / 4))); break;
4351                 case 10: sprintf(p, " %s%d", s_dam, 30+plev); break;
4352 #ifdef JP
4353                 case 13: sprintf(p, " »:%d+d%d", plev * 2, plev * 2); break;
4354 #else
4355                 case 13: sprintf(p, " d %d+d%d", plev * 2, plev * 2); break;
4356 #endif
4357                 case 16: sprintf(p, " %s25+d25", s_dur); break;
4358                 case 17: sprintf(p, " %s", s_random); break;
4359                 case 18: sprintf(p, " %s%dd8", s_dam, (4 + ((plev - 5) / 4))); break;
4360                 case 19: sprintf(p, " %s25+d25", s_dur); break;
4361                 case 21: sprintf(p, " %s3*100", s_dam); break;
4362                 case 22: sprintf(p, " %sd%d", s_dam, plev * 3); break;
4363                 case 23: sprintf(p, " %s%d", s_dam, 100 + plev * 2); break;
4364                 case 27: sprintf(p, " %s%d+d%d", s_dur,10+plev/2, 10+plev/2); break;
4365                 case 30: sprintf(p, " %s666", s_dam); break;
4366                 case 31: sprintf(p, " %s%d+d%d", s_dur, (plev / 2), (plev / 2)); break;
4367                 }
4368                 break;
4369                 
4370         case REALM_TRUMP: /* Trump */
4371                 switch (spell)
4372                 {
4373                 case  0: sprintf(p, " %s10", s_range); break;
4374                 case  2: sprintf(p, " %s", s_random); break;
4375                 case  4: sprintf(p, " %s%d", s_range, plev * 4); break;
4376                 case  5: sprintf(p, " %s25+d30", s_dur); break;
4377 #ifdef JP
4378                 case  8: sprintf(p, " ºÇÂç½ÅÎÌ:%d.%d", lbtokg1(plev * 15 / 10),lbtokg2(plev * 15 / 10)); break;
4379 #else
4380                 case  8: sprintf(p, " max wgt %d", plev * 15 / 10); break;
4381 #endif
4382                 case 13: sprintf(p, " %s%d", s_range, plev / 2 + 10); break;
4383                 case 14: sprintf(p, " %s15+d21", s_delay); break;
4384                 case 26: sprintf(p, " %s%d", s_heal, plev * 10 + 200); break;
4385 #ifdef JP
4386                 case 28: sprintf(p, " %s³Æ%d", s_dam, plev * 2); break;
4387 #else
4388                 case 28: sprintf(p, " %s%d each", s_dam, plev * 2); break;
4389 #endif
4390                 }
4391                 break;
4392                 
4393         case REALM_ARCANE: /* Arcane */
4394                 switch (spell)
4395                 {
4396                 case  0: sprintf(p, " %s%dd3", s_dam, 3 + ((plev - 1) / 5)); break;
4397                 case  4: sprintf(p, " %s10", s_range); break;
4398                 case  5: sprintf(p, " %s2d%d", s_dam, plev / 2); break;
4399                 case  7: sprintf(p, " %s2d8", s_heal); break;
4400                 case 14:
4401                 case 15:
4402                 case 16:
4403                 case 17: sprintf(p, " %s20+d20", s_dur); break;
4404                 case 18: sprintf(p, " %s4d8", s_heal); break;
4405                 case 19: sprintf(p, " %s%d", s_range, plev * 5); break;
4406                 case 21: sprintf(p, " %s6d8", s_dam); break;
4407                 case 24: sprintf(p, " %s24+d24", s_dur); break;
4408                 case 28: sprintf(p, " %s%d", s_dam, 75 + plev); break;
4409                 case 30: sprintf(p, " %s15+d21", s_delay); break;
4410                 case 31: sprintf(p, " %s25+d30", s_dur); break;
4411                 }
4412                 break;
4413                 
4414         case REALM_ENCHANT: /* Craft */
4415                 switch (spell)
4416                 {
4417                 case 0: sprintf(p, " %s100+d100", s_dur); break;
4418                 case 1: sprintf(p, " %s80+d80", s_dur); break;
4419                 case 3:
4420                 case 4:
4421                 case 6:
4422                 case 7:
4423                 case 10:
4424                 case 18: sprintf(p, " %s20+d20", s_dur); break;
4425                 case 5: sprintf(p, " %s25+d25", s_dur); break;
4426                 case 8: sprintf(p, " %s24+d24", s_dur); break;
4427                 case 11: sprintf(p, " %s25+d25", s_dur); break;
4428                 case 13: sprintf(p, " %s%d+d25", s_dur, plev * 3); break;
4429                 case 15: sprintf(p, " %s%d+d%d", s_dur, plev/2, plev/2); break;
4430                 case 16: sprintf(p, " %s25+d30", s_dur); break;
4431                 case 17: sprintf(p, " %s30+d20", s_dur); break;
4432                 case 19: sprintf(p, " %s%d+d%d", s_dur, plev, plev+20); break;
4433                 case 20: sprintf(p, " %s50+d50", s_dur); break;
4434                 case 23: sprintf(p, " %s20+d20", s_dur); break;
4435                 case 31: sprintf(p, " %s13+d13", s_dur); break;
4436                 }
4437                 break;
4438                 
4439         case REALM_DAEMON: /* Daemon */
4440                 switch (spell)
4441                 {
4442                 case  0: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4443                 case  2: sprintf(p, " %s12+d12", s_dur); break;
4444                 case  3: sprintf(p, " %s20+d20", s_dur); break;
4445                 case  5: sprintf(p, " %s%dd8", s_dam, (6 + ((plev - 5) / 4))); break;
4446                 case  7: sprintf(p, " %s3d6+%d", s_dam, burst); break;
4447                 case 10: sprintf(p, " %s20+d20", s_dur); break;
4448                 case 11: sprintf(p, " %s%dd8", s_dam, (11 + ((plev - 5) / 4))); break;
4449                 case 12: sprintf(p, " %s%d", s_dam, 55 + plev); break;
4450                 case 14: sprintf(p, " %s%d", s_dam, 100 + plev*3/2); break;
4451                 case 16: sprintf(p, " %s30+d25", s_dur); break;
4452                 case 17: sprintf(p, " %s20+d20", s_dur); break;
4453                 case 18: sprintf(p, " %s%d", s_dam, 55 + plev); break;
4454                 case 19: sprintf(p, " %s%d", s_dam, 80 + plev*3/2); break;
4455                 case 20: sprintf(p, " %s%d+d%d", s_dur,10+plev/2, 10+plev/2); break;
4456                 case 21: sprintf(p, " %sd%d+d%d", s_dam, 2 * plev, 2 * plev); break;
4457                 case 22: sprintf(p, " %s%d", s_dam, 100 + plev*2); break;
4458                 case 24: sprintf(p, " %s25+d25", s_dur); break;
4459                 case 25: sprintf(p, " %s20+d20", s_dur); break;
4460                 case 26: sprintf(p, " %s%d+%d", s_dam, 25+plev/2, 25+plev/2); break;
4461                 case 29: sprintf(p, " %s%d", s_dam, plev*15); break;
4462                 case 30: sprintf(p, " %s600", s_dam); break;
4463                 case 31: sprintf(p, " %s15+d15", s_dur); break;
4464                 }
4465                 break;
4466                 
4467         case REALM_CRUSADE: /* Crusade */
4468                 switch (spell)
4469                 {
4470                 case  0: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
4471                 case  5: sprintf(p, " %s%d", s_range, 25+plev/2); break;
4472 #ifdef JP
4473                 case  6: sprintf(p, " %s³Æ%dd2", s_dam, 3+((plev-1)/9)); break;
4474 #else
4475                 case  6: sprintf(p, " %s%dd2 each", s_dam, 3+((plev-1)/9)); break;
4476 #endif
4477                 case  9: sprintf(p, " %s3d6+%d", s_dam, orb); break;
4478                 case 10: sprintf(p, " %sd%d", s_dam, plev); break;
4479                 case 12: sprintf(p, " %s24+d24", s_dur); break;
4480                 case 13: sprintf(p, " %sd25+%d", s_dur, 3 * plev); break;
4481                 case 14: sprintf(p, " %s%d", s_dam, plev*5); break;
4482 #ifdef JP
4483                 case 15: sprintf(p, " Â»:d%d/²ó:100", 6 * plev); break;
4484 #else
4485                 case 15: sprintf(p, " dam:d%d/h100", 6 * plev); break;
4486 #endif
4487                 case 18: sprintf(p, " %s18+d18", s_dur); break;
4488                 case 19: sprintf(p, " %sd%d", s_dam, 4 * plev); break;
4489                 case 20: sprintf(p, " %sd%d", s_dam, 4 * plev); break;
4490                 case 22: sprintf(p, " %s%d", s_dam, 2 * plev+100); break;
4491                 case 24: sprintf(p, " %s25+d25", s_dur); break;
4492                 case 28: sprintf(p, " %s10+d10", s_dur); break;
4493 #ifdef JP
4494                 case 29: sprintf(p, " %s³Æ%d", s_dam, plev*3+25); break;
4495 #else
4496                 case 29: sprintf(p, " %s%d each", s_dam, plev*3+25); break;
4497 #endif
4498 #ifdef JP
4499                 case 30: sprintf(p, " ²ó100/»%d+%d", plev * 4, plev*11/2); break;
4500 #else
4501                 case 30: sprintf(p, " h100/dm%d+%d", plev * 4, plev*11/2); break;
4502 #endif
4503                 }
4504                 break;
4505
4506         case REALM_MUSIC: /* Music */
4507                 switch (spell)
4508                 {
4509                 case 2 : sprintf(p, " %s%dd4", s_dam, 4 + ((plev - 1) / 5)); break;
4510                 case 4 : sprintf(p, " %s2d6", s_heal); break;
4511                 case 9 : sprintf(p, " %sd%d", s_dam, plev * 3 / 2); break;
4512                 case 13: sprintf(p, " %s%dd7", s_dam, 10 + (plev / 5)); break;
4513                 case 20: sprintf(p, " %sd%d+d%d", s_dam, plev * 3, plev * 3); break;
4514                 case 22: sprintf(p, " %s%dd10", s_dam, 15 + ((plev - 1) / 2)); break;
4515                 case 27: sprintf(p, " %sd%d", s_dam, plev * 3); break;
4516                 case 28: sprintf(p, " %s15d10", s_heal); break;
4517                 case 30: sprintf(p, " %s%dd10", s_dam, 50 + plev); break;
4518                 }
4519                 break;
4520         default:
4521 #ifdef JP
4522                 sprintf(p, "̤ÃΤΥ¿¥¤¥×: %d", use_realm);
4523 #else
4524                 sprintf(p, "Unknown type: %d.", use_realm);
4525 #endif
4526         }
4527 }
4528
4529
4530 /*
4531  * Print a list of spells (for browsing or casting or viewing)
4532  */
4533 void print_spells(int target_spell, byte *spells, int num, int y, int x, int use_realm)
4534 {
4535         int             i, spell, exp_level, increment = 64;
4536         magic_type      *s_ptr;
4537         cptr            comment;
4538         char            info[80];
4539         char            out_val[160];
4540         byte            line_attr;
4541         int             need_mana;
4542         char            ryakuji[5];
4543         char            buf[256];
4544         bool max = FALSE;
4545
4546
4547         if (((use_realm <= REALM_NONE) || (use_realm > MAX_REALM)) && p_ptr->wizard)
4548 #ifdef JP
4549 msg_print("·Ù¹ð¡ª print_spell ¤¬Îΰè¤Ê¤·¤Ë¸Æ¤Ð¤ì¤¿");
4550 #else
4551                 msg_print("Warning! print_spells called with null realm");
4552 #endif
4553
4554
4555         /* Title the list */
4556         prt("", y, x);
4557         if (use_realm == REALM_HISSATSU)
4558 #ifdef JP
4559                 strcpy(buf,"  Lv   MP");
4560 #else
4561                 strcpy(buf,"  Lv   SP");
4562 #endif
4563         else
4564 #ifdef JP
4565                 strcpy(buf,"½ÏÎýÅÙ Lv   MP ¼ºÎ¨ ¸ú²Ì");
4566 #else
4567                 strcpy(buf,"Profic Lv   SP Fail Effect");
4568 #endif
4569
4570 #ifdef JP
4571 put_str("̾Á°", y, x + 5);
4572 put_str(buf, y, x + 29);
4573 #else
4574         put_str("Name", y, x + 5);
4575         put_str(buf, y, x + 29);
4576 #endif
4577
4578         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) increment = 0;
4579         else if (use_realm == p_ptr->realm1) increment = 0;
4580         else if (use_realm == p_ptr->realm2) increment = 32;
4581
4582         /* Dump the spells */
4583         for (i = 0; i < num; i++)
4584         {
4585                 /* Access the spell */
4586                 spell = spells[i];
4587
4588                 /* Access the spell */
4589                 if (!is_magic(use_realm))
4590                 {
4591                         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
4592                 }
4593                 else
4594                 {
4595                         s_ptr = &mp_ptr->info[use_realm - 1][spell];
4596                 }
4597
4598                 if (use_realm == REALM_HISSATSU)
4599                         need_mana = s_ptr->smana;
4600                 else
4601                 {
4602                         s16b exp = experience_of_spell(spell, use_realm);
4603
4604                         /* Extract mana consumption rate */
4605                         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
4606
4607                         if ((increment == 64) || (s_ptr->slevel >= 99)) exp_level = EXP_LEVEL_UNSKILLED;
4608                         else exp_level = spell_exp_level(exp);
4609
4610                         max = FALSE;
4611                         if (!increment && (exp_level == EXP_LEVEL_MASTER)) max = TRUE;
4612                         else if ((increment == 32) && (exp_level >= EXP_LEVEL_EXPERT)) max = TRUE;
4613                         else if (s_ptr->slevel >= 99) max = TRUE;
4614                         else if ((p_ptr->pclass == CLASS_RED_MAGE) && (exp_level >= EXP_LEVEL_SKILLED)) max = TRUE;
4615
4616                         strncpy(ryakuji, exp_level_str[exp_level], 4);
4617                         ryakuji[3] = ']';
4618                         ryakuji[4] = '\0';
4619                 }
4620
4621                 if (use_menu && target_spell)
4622                 {
4623                         if (i == (target_spell-1))
4624 #ifdef JP
4625                                 strcpy(out_val, "  ¡Õ ");
4626 #else
4627                                 strcpy(out_val, "  >  ");
4628 #endif
4629                         else
4630                                 strcpy(out_val, "     ");
4631                 }
4632                 else sprintf(out_val, "  %c) ", I2A(i));
4633                 /* Skip illegible spells */
4634                 if (s_ptr->slevel >= 99)
4635                 {
4636 #ifdef JP
4637 strcat(out_val, format("%-30s", "(ȽÆÉÉÔǽ)"));
4638 #else
4639                                 strcat(out_val, format("%-30s", "(illegible)"));
4640 #endif
4641
4642                                 c_prt(TERM_L_DARK, out_val, y + i + 1, x);
4643                                 continue;
4644                 }
4645
4646                 /* XXX XXX Could label spells above the players level */
4647
4648                 /* Get extra info */
4649                 spell_info(info, spell, use_realm);
4650
4651                 /* Use that info */
4652                 comment = info;
4653
4654                 /* Assume spell is known and tried */
4655                 line_attr = TERM_WHITE;
4656
4657                 /* Analyze the spell */
4658                 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4659                 {
4660                         if (s_ptr->slevel > p_ptr->max_plv)
4661                         {
4662 #ifdef JP
4663 comment = " Ì¤ÃÎ";
4664 #else
4665                                 comment = " unknown";
4666 #endif
4667
4668                                 line_attr = TERM_L_BLUE;
4669                         }
4670                         else if (s_ptr->slevel > p_ptr->lev)
4671                         {
4672 #ifdef JP
4673 comment = " ËºµÑ";
4674 #else
4675                                 comment = " forgotten";
4676 #endif
4677
4678                                 line_attr = TERM_YELLOW;
4679                         }
4680                 }
4681                 else if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2))
4682                 {
4683 #ifdef JP
4684 comment = " Ì¤ÃÎ";
4685 #else
4686                         comment = " unknown";
4687 #endif
4688
4689                         line_attr = TERM_L_BLUE;
4690                 }
4691                 else if ((use_realm == p_ptr->realm1) ?
4692                     ((p_ptr->spell_forgotten1 & (1L << spell))) :
4693                     ((p_ptr->spell_forgotten2 & (1L << spell))))
4694                 {
4695 #ifdef JP
4696 comment = " ËºµÑ";
4697 #else
4698                         comment = " forgotten";
4699 #endif
4700
4701                         line_attr = TERM_YELLOW;
4702                 }
4703                 else if (!((use_realm == p_ptr->realm1) ?
4704                     (p_ptr->spell_learned1 & (1L << spell)) :
4705                     (p_ptr->spell_learned2 & (1L << spell))))
4706                 {
4707 #ifdef JP
4708 comment = " Ì¤ÃÎ";
4709 #else
4710                         comment = " unknown";
4711 #endif
4712
4713                         line_attr = TERM_L_BLUE;
4714                 }
4715                 else if (!((use_realm == p_ptr->realm1) ?
4716                     (p_ptr->spell_worked1 & (1L << spell)) :
4717                     (p_ptr->spell_worked2 & (1L << spell))))
4718                 {
4719 #ifdef JP
4720 comment = " Ì¤·Ð¸³";
4721 #else
4722                         comment = " untried";
4723 #endif
4724
4725                         line_attr = TERM_L_GREEN;
4726                 }
4727
4728                 /* Dump the spell --(-- */
4729                 if (use_realm == REALM_HISSATSU)
4730                 {
4731                         strcat(out_val, format("%-25s %2d %4d",
4732                             spell_names[technic2magic(use_realm)-1][spell], /* realm, spell */
4733                             s_ptr->slevel, need_mana));
4734                 }
4735                 else
4736                 {
4737                         strcat(out_val, format("%-25s%c%-4s %2d %4d %3d%%%s",
4738                             spell_names[technic2magic(use_realm)-1][spell], /* realm, spell */
4739                             (max ? '!' : ' '), ryakuji,
4740                             s_ptr->slevel, need_mana, spell_chance(spell, use_realm), comment));
4741                 }
4742                 c_prt(line_attr, out_val, y + i + 1, x);
4743         }
4744
4745         /* Clear the bottom line */
4746         prt("", y + i + 1, x);
4747 }
4748
4749
4750 /*
4751  * Note that amulets, rods, and high-level spell books are immune
4752  * to "inventory damage" of any kind.  Also sling ammo and shovels.
4753  */
4754
4755
4756 /*
4757  * Does a given class of objects (usually) hate acid?
4758  * Note that acid can either melt or corrode something.
4759  */
4760 bool hates_acid(object_type *o_ptr)
4761 {
4762         /* Analyze the type */
4763         switch (o_ptr->tval)
4764         {
4765                 /* Wearable items */
4766                 case TV_ARROW:
4767                 case TV_BOLT:
4768                 case TV_BOW:
4769                 case TV_SWORD:
4770                 case TV_HAFTED:
4771                 case TV_POLEARM:
4772                 case TV_HELM:
4773                 case TV_CROWN:
4774                 case TV_SHIELD:
4775                 case TV_BOOTS:
4776                 case TV_GLOVES:
4777                 case TV_CLOAK:
4778                 case TV_SOFT_ARMOR:
4779                 case TV_HARD_ARMOR:
4780                 case TV_DRAG_ARMOR:
4781                 {
4782                         return (TRUE);
4783                 }
4784
4785                 /* Staffs/Scrolls are wood/paper */
4786                 case TV_STAFF:
4787                 case TV_SCROLL:
4788                 {
4789                         return (TRUE);
4790                 }
4791
4792                 /* Ouch */
4793                 case TV_CHEST:
4794                 {
4795                         return (TRUE);
4796                 }
4797
4798                 /* Junk is useless */
4799                 case TV_SKELETON:
4800                 case TV_BOTTLE:
4801                 case TV_JUNK:
4802                 {
4803                         return (TRUE);
4804                 }
4805         }
4806
4807         return (FALSE);
4808 }
4809
4810
4811 /*
4812  * Does a given object (usually) hate electricity?
4813  */
4814 bool hates_elec(object_type *o_ptr)
4815 {
4816         switch (o_ptr->tval)
4817         {
4818                 case TV_RING:
4819                 case TV_WAND:
4820                 {
4821                         return (TRUE);
4822                 }
4823         }
4824
4825         return (FALSE);
4826 }
4827
4828
4829 /*
4830  * Does a given object (usually) hate fire?
4831  * Hafted/Polearm weapons have wooden shafts.
4832  * Arrows/Bows are mostly wooden.
4833  */
4834 bool hates_fire(object_type *o_ptr)
4835 {
4836         /* Analyze the type */
4837         switch (o_ptr->tval)
4838         {
4839                 /* Wearable */
4840                 case TV_LITE:
4841                 case TV_ARROW:
4842                 case TV_BOW:
4843                 case TV_HAFTED:
4844                 case TV_POLEARM:
4845                 case TV_BOOTS:
4846                 case TV_GLOVES:
4847                 case TV_CLOAK:
4848                 case TV_SOFT_ARMOR:
4849                 {
4850                         return (TRUE);
4851                 }
4852
4853                 /* Books */
4854                 case TV_LIFE_BOOK:
4855                 case TV_SORCERY_BOOK:
4856                 case TV_NATURE_BOOK:
4857                 case TV_CHAOS_BOOK:
4858                 case TV_DEATH_BOOK:
4859                 case TV_TRUMP_BOOK:
4860                 case TV_ARCANE_BOOK:
4861                 case TV_ENCHANT_BOOK:
4862                 case TV_DAEMON_BOOK:
4863                 case TV_CRUSADE_BOOK:
4864                 case TV_MUSIC_BOOK:
4865                 case TV_HISSATSU_BOOK:
4866                 {
4867                         return (TRUE);
4868                 }
4869
4870                 /* Chests */
4871                 case TV_CHEST:
4872                 {
4873                         return (TRUE);
4874                 }
4875
4876                 /* Staffs/Scrolls burn */
4877                 case TV_STAFF:
4878                 case TV_SCROLL:
4879                 {
4880                         return (TRUE);
4881                 }
4882         }
4883
4884         return (FALSE);
4885 }
4886
4887
4888 /*
4889  * Does a given object (usually) hate cold?
4890  */
4891 bool hates_cold(object_type *o_ptr)
4892 {
4893         switch (o_ptr->tval)
4894         {
4895                 case TV_POTION:
4896                 case TV_FLASK:
4897                 case TV_BOTTLE:
4898                 {
4899                         return (TRUE);
4900                 }
4901         }
4902
4903         return (FALSE);
4904 }
4905
4906
4907 /*
4908  * Melt something
4909  */
4910 int set_acid_destroy(object_type *o_ptr)
4911 {
4912         u32b flgs[TR_FLAG_SIZE];
4913         if (!hates_acid(o_ptr)) return (FALSE);
4914         object_flags(o_ptr, flgs);
4915         if (have_flag(flgs, TR_IGNORE_ACID)) return (FALSE);
4916         return (TRUE);
4917 }
4918
4919
4920 /*
4921  * Electrical damage
4922  */
4923 int set_elec_destroy(object_type *o_ptr)
4924 {
4925         u32b flgs[TR_FLAG_SIZE];
4926         if (!hates_elec(o_ptr)) return (FALSE);
4927         object_flags(o_ptr, flgs);
4928         if (have_flag(flgs, TR_IGNORE_ELEC)) return (FALSE);
4929         return (TRUE);
4930 }
4931
4932
4933 /*
4934  * Burn something
4935  */
4936 int set_fire_destroy(object_type *o_ptr)
4937 {
4938         u32b flgs[TR_FLAG_SIZE];
4939         if (!hates_fire(o_ptr)) return (FALSE);
4940         object_flags(o_ptr, flgs);
4941         if (have_flag(flgs, TR_IGNORE_FIRE)) return (FALSE);
4942         return (TRUE);
4943 }
4944
4945
4946 /*
4947  * Freeze things
4948  */
4949 int set_cold_destroy(object_type *o_ptr)
4950 {
4951         u32b flgs[TR_FLAG_SIZE];
4952         if (!hates_cold(o_ptr)) return (FALSE);
4953         object_flags(o_ptr, flgs);
4954         if (have_flag(flgs, TR_IGNORE_COLD)) return (FALSE);
4955         return (TRUE);
4956 }
4957
4958
4959 /*
4960  * Destroys a type of item on a given percent chance
4961  * Note that missiles are no longer necessarily all destroyed
4962  * Destruction taken from "melee.c" code for "stealing".
4963  * New-style wands and rods handled correctly. -LM-
4964  * Returns number of items destroyed.
4965  */
4966 int inven_damage(inven_func typ, int perc)
4967 {
4968         int         i, j, k, amt;
4969         object_type *o_ptr;
4970         char        o_name[MAX_NLEN];
4971
4972         /* Multishadow effects is determined by turn */
4973         if( p_ptr->multishadow && (turn & 1) )return 0;
4974
4975         if (p_ptr->inside_arena) return 0;
4976
4977         /* Count the casualties */
4978         k = 0;
4979
4980         /* Scan through the slots backwards */
4981         for (i = 0; i < INVEN_PACK; i++)
4982         {
4983                 o_ptr = &inventory[i];
4984
4985                 /* Skip non-objects */
4986                 if (!o_ptr->k_idx) continue;
4987
4988                 /* Hack -- for now, skip artifacts */
4989                 if (object_is_artifact(o_ptr)) continue;
4990
4991                 /* Give this item slot a shot at death */
4992                 if ((*typ)(o_ptr))
4993                 {
4994                         /* Count the casualties */
4995                         for (amt = j = 0; j < o_ptr->number; ++j)
4996                         {
4997                                 if (randint0(100) < perc) amt++;
4998                         }
4999
5000                         /* Some casualities */
5001                         if (amt)
5002                         {
5003                                 /* Get a description */
5004                                 object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
5005
5006                                 /* Message */
5007 #ifdef JP
5008 msg_format("%s(%c)¤¬%s²õ¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª",
5009 #else
5010                                 msg_format("%sour %s (%c) %s destroyed!",
5011 #endif
5012
5013 #ifdef JP
5014 o_name, index_to_label(i),
5015     ((o_ptr->number > 1) ?
5016     ((amt == o_ptr->number) ? "Á´Éô" :
5017     (amt > 1 ? "²¿¸Ä¤«" : "°ì¸Ä")) : "")    );
5018 #else
5019                                     ((o_ptr->number > 1) ?
5020                                     ((amt == o_ptr->number) ? "All of y" :
5021                                     (amt > 1 ? "Some of y" : "One of y")) : "Y"),
5022                                     o_name, index_to_label(i),
5023                                     ((amt > 1) ? "were" : "was"));
5024 #endif
5025
5026 #ifdef JP
5027                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
5028                                         msg_print("¤ä¤ê¤ä¤¬¤Ã¤¿¤Ê¡ª");
5029 #endif
5030
5031                                 /* Potions smash open */
5032                                 if (object_is_potion(o_ptr))
5033                                 {
5034                                         (void)potion_smash_effect(0, py, px, o_ptr->k_idx);
5035                                 }
5036
5037                                 /* Reduce the charges of rods/wands */
5038                                 reduce_charges(o_ptr, amt);
5039
5040                                 /* Destroy "amt" items */
5041                                 inven_item_increase(i, -amt);
5042                                 inven_item_optimize(i);
5043
5044                                 /* Count the casualties */
5045                                 k += amt;
5046                         }
5047                 }
5048         }
5049
5050         /* Return the casualty count */
5051         return (k);
5052 }
5053
5054
5055 /*
5056  * Acid has hit the player, attempt to affect some armor.
5057  *
5058  * Note that the "base armor" of an object never changes.
5059  *
5060  * If any armor is damaged (or resists), the player takes less damage.
5061  */
5062 static int minus_ac(void)
5063 {
5064         object_type *o_ptr = NULL;
5065         u32b flgs[TR_FLAG_SIZE];
5066         char        o_name[MAX_NLEN];
5067
5068
5069         /* Pick a (possibly empty) inventory slot */
5070         switch (randint1(7))
5071         {
5072                 case 1: o_ptr = &inventory[INVEN_RARM]; break;
5073                 case 2: o_ptr = &inventory[INVEN_LARM]; break;
5074                 case 3: o_ptr = &inventory[INVEN_BODY]; break;
5075                 case 4: o_ptr = &inventory[INVEN_OUTER]; break;
5076                 case 5: o_ptr = &inventory[INVEN_HANDS]; break;
5077                 case 6: o_ptr = &inventory[INVEN_HEAD]; break;
5078                 case 7: o_ptr = &inventory[INVEN_FEET]; break;
5079         }
5080
5081         /* Nothing to damage */
5082         if (!o_ptr->k_idx) return (FALSE);
5083
5084         if (!object_is_armour(o_ptr)) return (FALSE);
5085
5086         /* No damage left to be done */
5087         if (o_ptr->ac + o_ptr->to_a <= 0) return (FALSE);
5088
5089
5090         /* Describe */
5091         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
5092
5093         /* Extract the flags */
5094         object_flags(o_ptr, flgs);
5095
5096         /* Object resists */
5097         if (have_flag(flgs, TR_IGNORE_ACID))
5098         {
5099 #ifdef JP
5100 msg_format("¤·¤«¤·%s¤Ë¤Ï¸ú²Ì¤¬¤Ê¤«¤Ã¤¿¡ª", o_name);
5101 #else
5102                 msg_format("Your %s is unaffected!", o_name);
5103 #endif
5104
5105
5106                 return (TRUE);
5107         }
5108
5109         /* Message */
5110 #ifdef JP
5111 msg_format("%s¤¬¥À¥á¡¼¥¸¤ò¼õ¤±¤¿¡ª", o_name);
5112 #else
5113         msg_format("Your %s is damaged!", o_name);
5114 #endif
5115
5116
5117         /* Damage the item */
5118         o_ptr->to_a--;
5119
5120         /* Calculate bonuses */
5121         p_ptr->update |= (PU_BONUS);
5122
5123         /* Window stuff */
5124         p_ptr->window |= (PW_EQUIP | PW_PLAYER);
5125
5126         calc_android_exp();
5127
5128         /* Item was damaged */
5129         return (TRUE);
5130 }
5131
5132
5133 /*
5134  * Hurt the player with Acid
5135  */
5136 int acid_dam(int dam, cptr kb_str, int monspell)
5137 {
5138         int get_damage;  
5139         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5140         bool double_resist = IS_OPPOSE_ACID();
5141
5142         /* Total Immunity */
5143         if (p_ptr->immune_acid || (dam <= 0))
5144         {
5145                 learn_spell(monspell);
5146                 return 0;
5147         }
5148
5149         /* Vulnerability (Ouch!) */
5150         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5151         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5152
5153         /* Resist the damage */
5154         if (p_ptr->resist_acid) dam = (dam + 2) / 3;
5155         if (double_resist) dam = (dam + 2) / 3;
5156
5157         if ((!(double_resist || p_ptr->resist_acid)) &&
5158             one_in_(HURT_CHANCE))
5159                 (void)do_dec_stat(A_CHR);
5160
5161         /* If any armor gets hit, defend the player */
5162         if (minus_ac()) dam = (dam + 1) / 2;
5163
5164         /* Take damage */
5165         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5166
5167         /* Inventory damage */
5168         if (!(double_resist && p_ptr->resist_acid))
5169                 inven_damage(set_acid_destroy, inv);
5170         return get_damage;
5171 }
5172
5173
5174 /*
5175  * Hurt the player with electricity
5176  */
5177 int elec_dam(int dam, cptr kb_str, int monspell)
5178 {
5179         int get_damage;  
5180         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5181         bool double_resist = IS_OPPOSE_ELEC();
5182
5183         /* Total immunity */
5184         if (p_ptr->immune_elec || (dam <= 0))
5185         {
5186                 learn_spell(monspell);
5187                 return 0;
5188         }
5189
5190         /* Vulnerability (Ouch!) */
5191         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5192         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5193         if (prace_is_(RACE_ANDROID)) dam += dam / 3;
5194
5195         /* Resist the damage */
5196         if (p_ptr->resist_elec) dam = (dam + 2) / 3;
5197         if (double_resist) dam = (dam + 2) / 3;
5198
5199         if ((!(double_resist || p_ptr->resist_elec)) &&
5200             one_in_(HURT_CHANCE))
5201                 (void)do_dec_stat(A_DEX);
5202
5203         /* Take damage */
5204         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5205
5206         /* Inventory damage */
5207         if (!(double_resist && p_ptr->resist_elec))
5208                 inven_damage(set_elec_destroy, inv);
5209
5210         return get_damage;
5211 }
5212
5213
5214 /*
5215  * Hurt the player with Fire
5216  */
5217 int fire_dam(int dam, cptr kb_str, int monspell)
5218 {
5219         int get_damage;  
5220         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5221         bool double_resist = IS_OPPOSE_FIRE();
5222
5223         /* Totally immune */
5224         if (p_ptr->immune_fire || (dam <= 0))
5225         {
5226                 learn_spell(monspell);
5227                 return 0;
5228         }
5229
5230         /* Vulnerability (Ouch!) */
5231         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5232         if (prace_is_(RACE_ENT)) dam += dam / 3;
5233         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5234
5235         /* Resist the damage */
5236         if (p_ptr->resist_fire) dam = (dam + 2) / 3;
5237         if (double_resist) dam = (dam + 2) / 3;
5238
5239         if ((!(double_resist || p_ptr->resist_fire)) &&
5240             one_in_(HURT_CHANCE))
5241                 (void)do_dec_stat(A_STR);
5242
5243         /* Take damage */
5244         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5245
5246         /* Inventory damage */
5247         if (!(double_resist && p_ptr->resist_fire))
5248                 inven_damage(set_fire_destroy, inv);
5249
5250         return get_damage;
5251 }
5252
5253
5254 /*
5255  * Hurt the player with Cold
5256  */
5257 int cold_dam(int dam, cptr kb_str, int monspell)
5258 {
5259         int get_damage;  
5260         int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
5261         bool double_resist = IS_OPPOSE_COLD();
5262
5263         /* Total immunity */
5264         if (p_ptr->immune_cold || (dam <= 0))
5265         {
5266                 learn_spell(monspell);
5267                 return 0;
5268         }
5269
5270         /* Vulnerability (Ouch!) */
5271         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
5272         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
5273
5274         /* Resist the damage */
5275         if (p_ptr->resist_cold) dam = (dam + 2) / 3;
5276         if (double_resist) dam = (dam + 2) / 3;
5277
5278         if ((!(double_resist || p_ptr->resist_cold)) &&
5279             one_in_(HURT_CHANCE))
5280                 (void)do_dec_stat(A_STR);
5281
5282         /* Take damage */
5283         get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
5284
5285         /* Inventory damage */
5286         if (!(double_resist && p_ptr->resist_cold))
5287                 inven_damage(set_cold_destroy, inv);
5288
5289         return get_damage;
5290 }
5291
5292
5293 bool rustproof(void)
5294 {
5295         int         item;
5296         object_type *o_ptr;
5297         char        o_name[MAX_NLEN];
5298         cptr        q, s;
5299
5300         item_tester_no_ryoute = TRUE;
5301         /* Select a piece of armour */
5302         item_tester_hook = object_is_armour;
5303
5304         /* Get an item */
5305 #ifdef JP
5306 q = "¤É¤ÎËɶñ¤Ë»¬»ß¤á¤ò¤·¤Þ¤¹¤«¡©";
5307 s = "»¬»ß¤á¤Ç¤­¤ë¤â¤Î¤¬¤¢¤ê¤Þ¤»¤ó¡£";
5308 #else
5309         q = "Rustproof which piece of armour? ";
5310         s = "You have nothing to rustproof.";
5311 #endif
5312
5313         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return FALSE;
5314
5315         /* Get the item (in the pack) */
5316         if (item >= 0)
5317         {
5318                 o_ptr = &inventory[item];
5319         }
5320
5321         /* Get the item (on the floor) */
5322         else
5323         {
5324                 o_ptr = &o_list[0 - item];
5325         }
5326
5327
5328         /* Description */
5329         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
5330
5331         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
5332
5333         if ((o_ptr->to_a < 0) && !object_is_cursed(o_ptr))
5334         {
5335 #ifdef JP
5336 msg_format("%s¤Ï¿·ÉÊƱÍͤˤʤä¿¡ª",o_name);
5337 #else
5338                 msg_format("%s %s look%s as good as new!",
5339                         ((item >= 0) ? "Your" : "The"), o_name,
5340                         ((o_ptr->number > 1) ? "" : "s"));
5341 #endif
5342
5343                 o_ptr->to_a = 0;
5344         }
5345
5346 #ifdef JP
5347 msg_format("%s¤ÏÉå¿©¤·¤Ê¤¯¤Ê¤Ã¤¿¡£", o_name);
5348 #else
5349         msg_format("%s %s %s now protected against corrosion.",
5350                 ((item >= 0) ? "Your" : "The"), o_name,
5351                 ((o_ptr->number > 1) ? "are" : "is"));
5352 #endif
5353
5354
5355         calc_android_exp();
5356
5357         return TRUE;
5358 }
5359
5360
5361 /*
5362  * Curse the players armor
5363  */
5364 bool curse_armor(void)
5365 {
5366         int i;
5367         object_type *o_ptr;
5368
5369         char o_name[MAX_NLEN];
5370
5371
5372         /* Curse the body armor */
5373         o_ptr = &inventory[INVEN_BODY];
5374
5375         /* Nothing to curse */
5376         if (!o_ptr->k_idx) return (FALSE);
5377
5378
5379         /* Describe */
5380         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
5381
5382         /* Attempt a saving throw for artifacts */
5383         if (object_is_artifact(o_ptr) && (randint0(100) < 50))
5384         {
5385                 /* Cool */
5386 #ifdef JP
5387 msg_format("%s¤¬%s¤òÊñ¤ß¹þ¤â¤¦¤È¤·¤¿¤¬¡¢%s¤Ï¤½¤ì¤òÄ·¤ÍÊÖ¤·¤¿¡ª",
5388 "¶²ÉݤΰŹõ¥ª¡¼¥é", "Ëɶñ", o_name);
5389 #else
5390                 msg_format("A %s tries to %s, but your %s resists the effects!",
5391                            "terrible black aura", "surround your armor", o_name);
5392 #endif
5393
5394         }
5395
5396         /* not artifact or failed save... */
5397         else
5398         {
5399                 /* Oops */
5400 #ifdef JP
5401 msg_format("¶²ÉݤΰŹõ¥ª¡¼¥é¤¬¤¢¤Ê¤¿¤Î%s¤òÊñ¤ß¹þ¤ó¤À¡ª", o_name);
5402 #else
5403                 msg_format("A terrible black aura blasts your %s!", o_name);
5404 #endif
5405
5406                 chg_virtue(V_ENCHANT, -5);
5407
5408                 /* Blast the armor */
5409                 o_ptr->name1 = 0;
5410                 o_ptr->name2 = EGO_BLASTED;
5411                 o_ptr->to_a = 0 - randint1(5) - randint1(5);
5412                 o_ptr->to_h = 0;
5413                 o_ptr->to_d = 0;
5414                 o_ptr->ac = 0;
5415                 o_ptr->dd = 0;
5416                 o_ptr->ds = 0;
5417
5418                 for (i = 0; i < TR_FLAG_SIZE; i++)
5419                         o_ptr->art_flags[i] = 0;
5420
5421                 /* Curse it */
5422                 o_ptr->curse_flags = TRC_CURSED;
5423
5424                 /* Break it */
5425                 o_ptr->ident |= (IDENT_BROKEN);
5426
5427                 /* Recalculate bonuses */
5428                 p_ptr->update |= (PU_BONUS);
5429
5430                 /* Recalculate mana */
5431                 p_ptr->update |= (PU_MANA);
5432
5433                 /* Window stuff */
5434                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
5435         }
5436
5437         return (TRUE);
5438 }
5439
5440
5441 /*
5442  * Curse the players weapon
5443  */
5444 bool curse_weapon(bool force, int slot)
5445 {
5446         int i;
5447
5448         object_type *o_ptr;
5449
5450         char o_name[MAX_NLEN];
5451
5452
5453         /* Curse the weapon */
5454         o_ptr = &inventory[slot];
5455
5456         /* Nothing to curse */
5457         if (!o_ptr->k_idx) return (FALSE);
5458
5459
5460         /* Describe */
5461         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
5462
5463         /* Attempt a saving throw */
5464         if (object_is_artifact(o_ptr) && (randint0(100) < 50) && !force)
5465         {
5466                 /* Cool */
5467 #ifdef JP
5468 msg_format("%s¤¬%s¤òÊñ¤ß¹þ¤â¤¦¤È¤·¤¿¤¬¡¢%s¤Ï¤½¤ì¤òÄ·¤ÍÊÖ¤·¤¿¡ª",
5469 "¶²ÉݤΰŹõ¥ª¡¼¥é", "Éð´ï", o_name);
5470 #else
5471                 msg_format("A %s tries to %s, but your %s resists the effects!",
5472                            "terrible black aura", "surround your weapon", o_name);
5473 #endif
5474
5475         }
5476
5477         /* not artifact or failed save... */
5478         else
5479         {
5480                 /* Oops */
5481 #ifdef JP
5482 if (!force) msg_format("¶²ÉݤΰŹõ¥ª¡¼¥é¤¬¤¢¤Ê¤¿¤Î%s¤òÊñ¤ß¹þ¤ó¤À¡ª", o_name);
5483 #else
5484                 if (!force) msg_format("A terrible black aura blasts your %s!", o_name);
5485 #endif
5486
5487                 chg_virtue(V_ENCHANT, -5);
5488
5489                 /* Shatter the weapon */
5490                 o_ptr->name1 = 0;
5491                 o_ptr->name2 = EGO_SHATTERED;
5492                 o_ptr->to_h = 0 - randint1(5) - randint1(5);
5493                 o_ptr->to_d = 0 - randint1(5) - randint1(5);
5494                 o_ptr->to_a = 0;
5495                 o_ptr->ac = 0;
5496                 o_ptr->dd = 0;
5497                 o_ptr->ds = 0;
5498
5499                 for (i = 0; i < TR_FLAG_SIZE; i++)
5500                         o_ptr->art_flags[i] = 0;
5501
5502
5503                 /* Curse it */
5504                 o_ptr->curse_flags = TRC_CURSED;
5505
5506                 /* Break it */
5507                 o_ptr->ident |= (IDENT_BROKEN);
5508
5509                 /* Recalculate bonuses */
5510                 p_ptr->update |= (PU_BONUS);
5511
5512                 /* Recalculate mana */
5513                 p_ptr->update |= (PU_MANA);
5514
5515                 /* Window stuff */
5516                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
5517         }
5518
5519         /* Notice */
5520         return (TRUE);
5521 }
5522
5523
5524 /*
5525  * Enchant some bolts
5526  */
5527 bool brand_bolts(void)
5528 {
5529         int i;
5530
5531         /* Use the first acceptable bolts */
5532         for (i = 0; i < INVEN_PACK; i++)
5533         {
5534                 object_type *o_ptr = &inventory[i];
5535
5536                 /* Skip non-bolts */
5537                 if (o_ptr->tval != TV_BOLT) continue;
5538
5539                 /* Skip artifacts and ego-items */
5540                 if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
5541                         continue;
5542
5543                 /* Skip cursed/broken items */
5544                 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) continue;
5545
5546                 /* Randomize */
5547                 if (randint0(100) < 75) continue;
5548
5549                 /* Message */
5550 #ifdef JP
5551 msg_print("¥¯¥í¥¹¥Ü¥¦¤ÎÌ𤬱ê¤Î¥ª¡¼¥é¤ËÊñ¤Þ¤ì¤¿¡ª");
5552 #else
5553                 msg_print("Your bolts are covered in a fiery aura!");
5554 #endif
5555
5556
5557                 /* Ego-item */
5558                 o_ptr->name2 = EGO_FLAME;
5559
5560                 /* Enchant */
5561                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
5562
5563                 /* Notice */
5564                 return (TRUE);
5565         }
5566
5567         /* Flush */
5568         if (flush_failure) flush();
5569
5570         /* Fail */
5571 #ifdef JP
5572 msg_print("±ê¤Ç¶¯²½¤¹¤ë¤Î¤Ë¼ºÇÔ¤·¤¿¡£");
5573 #else
5574         msg_print("The fiery enchantment failed.");
5575 #endif
5576
5577
5578         /* Notice */
5579         return (TRUE);
5580 }
5581
5582
5583 /*
5584  * Helper function -- return a "nearby" race for polymorphing
5585  *
5586  * Note that this function is one of the more "dangerous" ones...
5587  */
5588 static s16b poly_r_idx(int r_idx)
5589 {
5590         monster_race *r_ptr = &r_info[r_idx];
5591
5592         int i, r, lev1, lev2;
5593
5594         /* Hack -- Uniques/Questors never polymorph */
5595         if ((r_ptr->flags1 & RF1_UNIQUE) ||
5596             (r_ptr->flags1 & RF1_QUESTOR))
5597                 return (r_idx);
5598
5599         /* Allowable range of "levels" for resulting monster */
5600         lev1 = r_ptr->level - ((randint1(20) / randint1(9)) + 1);
5601         lev2 = r_ptr->level + ((randint1(20) / randint1(9)) + 1);
5602
5603         /* Pick a (possibly new) non-unique race */
5604         for (i = 0; i < 1000; i++)
5605         {
5606                 /* Pick a new race, using a level calculation */
5607                 r = get_mon_num((dun_level + r_ptr->level) / 2 + 5);
5608
5609                 /* Handle failure */
5610                 if (!r) break;
5611
5612                 /* Obtain race */
5613                 r_ptr = &r_info[r];
5614
5615                 /* Ignore unique monsters */
5616                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
5617
5618                 /* Ignore monsters with incompatible levels */
5619                 if ((r_ptr->level < lev1) || (r_ptr->level > lev2)) continue;
5620
5621                 /* Use that index */
5622                 r_idx = r;
5623
5624                 /* Done */
5625                 break;
5626         }
5627
5628         /* Result */
5629         return (r_idx);
5630 }
5631
5632
5633 bool polymorph_monster(int y, int x)
5634 {
5635         cave_type *c_ptr = &cave[y][x];
5636         monster_type *m_ptr = &m_list[c_ptr->m_idx];
5637         bool polymorphed = FALSE;
5638         int new_r_idx;
5639         int old_r_idx = m_ptr->r_idx;
5640         bool targeted = (target_who == c_ptr->m_idx) ? TRUE : FALSE;
5641         bool health_tracked = (p_ptr->health_who == c_ptr->m_idx) ? TRUE : FALSE;
5642         monster_type back_m;
5643
5644         if (p_ptr->inside_arena || p_ptr->inside_battle) return (FALSE);
5645
5646         if ((p_ptr->riding == c_ptr->m_idx) || (m_ptr->mflag2 & MFLAG2_KAGE)) return (FALSE);
5647
5648         /* Memorize the monster before polymorphing */
5649         back_m = *m_ptr;
5650
5651         /* Pick a "new" monster race */
5652         new_r_idx = poly_r_idx(old_r_idx);
5653
5654         /* Handle polymorph */
5655         if (new_r_idx != old_r_idx)
5656         {
5657                 u32b mode = 0L;
5658
5659                 /* Get the monsters attitude */
5660                 if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
5661                 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
5662                 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
5663
5664                 /* "Kill" the "old" monster */
5665                 delete_monster_idx(c_ptr->m_idx);
5666
5667                 /* Create a new monster (no groups) */
5668                 if (place_monster_aux(0, y, x, new_r_idx, mode))
5669                 {
5670                         /* Success */
5671                         polymorphed = TRUE;
5672                 }
5673                 else
5674                 {
5675                         /* Placing the new monster failed */
5676                         if (place_monster_aux(0, y, x, old_r_idx, (mode | PM_NO_KAGE | PM_IGNORE_TERRAIN)))
5677                                 m_list[hack_m_idx_ii] = back_m;
5678                 }
5679
5680                 if (targeted) target_who = hack_m_idx_ii;
5681                 if (health_tracked) health_track(hack_m_idx_ii);
5682         }
5683
5684         return polymorphed;
5685 }
5686
5687
5688 /*
5689  * Dimension Door
5690  */
5691 static bool dimension_door_aux(int x, int y)
5692 {
5693         int     plev = p_ptr->lev;
5694
5695         p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
5696
5697         if (!cave_player_teleportable_bold(y, x, FALSE) ||
5698             (distance(y, x, py, px) > plev / 2 + 10) ||
5699             (!randint0(plev / 10 + 10)))
5700         {
5701                 p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
5702                 teleport_player((plev + 2) * 2, TRUE);
5703
5704                 /* Failed */
5705                 return FALSE;
5706         }
5707         else
5708         {
5709                 teleport_player_to(y, x, TRUE, FALSE);
5710
5711                 /* Success */
5712                 return TRUE;
5713         }
5714 }
5715
5716
5717 /*
5718  * Dimension Door
5719  */
5720 bool dimension_door(void)
5721 {
5722         int x = 0, y = 0;
5723
5724         /* Rerutn FALSE if cancelled */
5725         if (!tgt_pt(&x, &y)) return FALSE;
5726
5727         if (dimension_door_aux(x, y)) return TRUE;
5728
5729 #ifdef JP
5730         msg_print("ÀºÎ¤«¤éʪ¼Á³¦¤ËÌá¤ë»þ¤¦¤Þ¤¯¤¤¤«¤Ê¤«¤Ã¤¿¡ª");
5731 #else
5732         msg_print("You fail to exit the astral plane correctly!");
5733 #endif
5734
5735         return TRUE;
5736 }
5737
5738
5739 /*
5740  * Mirror Master's Dimension Door
5741  */
5742 bool mirror_tunnel(void)
5743 {
5744         int x = 0, y = 0;
5745
5746         /* Rerutn FALSE if cancelled */
5747         if (!tgt_pt(&x, &y)) return FALSE;
5748
5749         if (dimension_door_aux(x, y)) return TRUE;
5750
5751 #ifdef JP
5752         msg_print("¶À¤ÎÀ¤³¦¤ò¤¦¤Þ¤¯Ä̤ì¤Ê¤«¤Ã¤¿¡ª");
5753 #else
5754         msg_print("You fail to pass the mirror plane correctly!");
5755 #endif
5756
5757         return TRUE;
5758 }
5759
5760
5761 bool eat_magic(int power)
5762 {
5763         object_type * o_ptr;
5764         object_kind *k_ptr;
5765         int lev, item;
5766         int recharge_strength = 0;
5767
5768         bool fail = FALSE;
5769         byte fail_type = 1;
5770
5771         cptr q, s;
5772         char o_name[MAX_NLEN];
5773
5774         item_tester_hook = item_tester_hook_recharge;
5775
5776         /* Get an item */
5777 #ifdef JP
5778 q = "¤É¤Î¥¢¥¤¥Æ¥à¤«¤éËâÎϤòµÛ¼ý¤·¤Þ¤¹¤«¡©";
5779 s = "ËâÎϤòµÛ¼ý¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
5780 #else
5781         q = "Drain which item? ";
5782         s = "You have nothing to drain.";
5783 #endif
5784
5785         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return FALSE;
5786
5787         if (item >= 0)
5788         {
5789                 o_ptr = &inventory[item];
5790         }
5791         else
5792         {
5793                 o_ptr = &o_list[0 - item];
5794         }
5795
5796         k_ptr = &k_info[o_ptr->k_idx];
5797         lev = k_info[o_ptr->k_idx].level;
5798
5799         if (o_ptr->tval == TV_ROD)
5800         {
5801                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
5802
5803                 /* Back-fire */
5804                 if (one_in_(recharge_strength))
5805                 {
5806                         /* Activate the failure code. */
5807                         fail = TRUE;
5808                 }
5809                 else
5810                 {
5811                         if (o_ptr->timeout > (o_ptr->number - 1) * k_ptr->pval)
5812                         {
5813 #ifdef JP
5814 msg_print("½¼Å¶Ãæ¤Î¥í¥Ã¥É¤«¤éËâÎϤòµÛ¼ý¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£");
5815 #else
5816                                 msg_print("You can't absorb energy from a discharged rod.");
5817 #endif
5818
5819                         }
5820                         else
5821                         {
5822                                 p_ptr->csp += lev;
5823                                 o_ptr->timeout += k_ptr->pval;
5824                         }
5825                 }
5826         }
5827         else
5828         {
5829                 /* All staffs, wands. */
5830                 recharge_strength = (100 + power - lev) / 15;
5831
5832                 /* Paranoia */
5833                 if (recharge_strength < 0) recharge_strength = 0;
5834
5835                 /* Back-fire */
5836                 if (one_in_(recharge_strength))
5837                 {
5838                         /* Activate the failure code. */
5839                         fail = TRUE;
5840                 }
5841                 else
5842                 {
5843                         if (o_ptr->pval > 0)
5844                         {
5845                                 p_ptr->csp += lev / 2;
5846                                 o_ptr->pval --;
5847
5848                                 /* XXX Hack -- unstack if necessary */
5849                                 if ((o_ptr->tval == TV_STAFF) && (item >= 0) && (o_ptr->number > 1))
5850                                 {
5851                                         object_type forge;
5852                                         object_type *q_ptr;
5853
5854                                         /* Get local object */
5855                                         q_ptr = &forge;
5856
5857                                         /* Obtain a local object */
5858                                         object_copy(q_ptr, o_ptr);
5859
5860                                         /* Modify quantity */
5861                                         q_ptr->number = 1;
5862
5863                                         /* Restore the charges */
5864                                         o_ptr->pval++;
5865
5866                                         /* Unstack the used item */
5867                                         o_ptr->number--;
5868                                         p_ptr->total_weight -= q_ptr->weight;
5869                                         item = inven_carry(q_ptr);
5870
5871                                         /* Message */
5872 #ifdef JP
5873                                         msg_print("¾ó¤ò¤Þ¤È¤á¤Ê¤ª¤·¤¿¡£");
5874 #else
5875                                         msg_print("You unstack your staff.");
5876 #endif
5877
5878                                 }
5879                         }
5880                         else
5881                         {
5882 #ifdef JP
5883 msg_print("µÛ¼ý¤Ç¤­¤ëËâÎϤ¬¤¢¤ê¤Þ¤»¤ó¡ª");
5884 #else
5885                                 msg_print("There's no energy there to absorb!");
5886 #endif
5887
5888                         }
5889                         if (!o_ptr->pval) o_ptr->ident |= IDENT_EMPTY;
5890                 }
5891         }
5892
5893         /* Inflict the penalties for failing a recharge. */
5894         if (fail)
5895         {
5896                 /* Artifacts are never destroyed. */
5897                 if (object_is_fixed_artifact(o_ptr))
5898                 {
5899                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
5900 #ifdef JP
5901 msg_format("ËâÎϤ¬µÕή¤·¤¿¡ª%s¤Ï´°Á´¤ËËâÎϤò¼º¤Ã¤¿¡£", o_name);
5902 #else
5903                         msg_format("The recharging backfires - %s is completely drained!", o_name);
5904 #endif
5905
5906
5907                         /* Artifact rods. */
5908                         if (o_ptr->tval == TV_ROD)
5909                                 o_ptr->timeout = k_ptr->pval * o_ptr->number;
5910
5911                         /* Artifact wands and staffs. */
5912                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
5913                                 o_ptr->pval = 0;
5914                 }
5915                 else
5916                 {
5917                         /* Get the object description */
5918                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
5919
5920                         /*** Determine Seriousness of Failure ***/
5921
5922                         /* Mages recharge objects more safely. */
5923                         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)
5924                         {
5925                                 /* 10% chance to blow up one rod, otherwise draining. */
5926                                 if (o_ptr->tval == TV_ROD)
5927                                 {
5928                                         if (one_in_(10)) fail_type = 2;
5929                                         else fail_type = 1;
5930                                 }
5931                                 /* 75% chance to blow up one wand, otherwise draining. */
5932                                 else if (o_ptr->tval == TV_WAND)
5933                                 {
5934                                         if (!one_in_(3)) fail_type = 2;
5935                                         else fail_type = 1;
5936                                 }
5937                                 /* 50% chance to blow up one staff, otherwise no effect. */
5938                                 else if (o_ptr->tval == TV_STAFF)
5939                                 {
5940                                         if (one_in_(2)) fail_type = 2;
5941                                         else fail_type = 0;
5942                                 }
5943                         }
5944
5945                         /* All other classes get no special favors. */
5946                         else
5947                         {
5948                                 /* 33% chance to blow up one rod, otherwise draining. */
5949                                 if (o_ptr->tval == TV_ROD)
5950                                 {
5951                                         if (one_in_(3)) fail_type = 2;
5952                                         else fail_type = 1;
5953                                 }
5954                                 /* 20% chance of the entire stack, else destroy one wand. */
5955                                 else if (o_ptr->tval == TV_WAND)
5956                                 {
5957                                         if (one_in_(5)) fail_type = 3;
5958                                         else fail_type = 2;
5959                                 }
5960                                 /* Blow up one staff. */
5961                                 else if (o_ptr->tval == TV_STAFF)
5962                                 {
5963                                         fail_type = 2;
5964                                 }
5965                         }
5966
5967                         /*** Apply draining and destruction. ***/
5968
5969                         /* Drain object or stack of objects. */
5970                         if (fail_type == 1)
5971                         {
5972                                 if (o_ptr->tval == TV_ROD)
5973                                 {
5974 #ifdef JP
5975 msg_print("¥í¥Ã¥É¤ÏÇË»¤òÌȤ줿¤¬¡¢ËâÎϤÏÁ´¤Æ¼º¤Ê¤ï¤ì¤¿¡£");
5976 #else
5977                                         msg_format("You save your rod from destruction, but all charges are lost.", o_name);
5978 #endif
5979
5980                                         o_ptr->timeout = k_ptr->pval * o_ptr->number;
5981                                 }
5982                                 else if (o_ptr->tval == TV_WAND)
5983                                 {
5984 #ifdef JP
5985 msg_format("%s¤ÏÇË»¤òÌȤ줿¤¬¡¢ËâÎϤ¬Á´¤Æ¼º¤ï¤ì¤¿¡£", o_name);
5986 #else
5987                                         msg_format("You save your %s from destruction, but all charges are lost.", o_name);
5988 #endif
5989
5990                                         o_ptr->pval = 0;
5991                                 }
5992                                 /* Staffs aren't drained. */
5993                         }
5994
5995                         /* Destroy an object or one in a stack of objects. */
5996                         if (fail_type == 2)
5997                         {
5998                                 if (o_ptr->number > 1)
5999                                 {
6000 #ifdef JP
6001 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬°ìËܲõ¤ì¤¿¡ª", o_name);
6002 #else
6003                                         msg_format("Wild magic consumes one of your %s!", o_name);
6004 #endif
6005
6006                                         /* Reduce rod stack maximum timeout, drain wands. */
6007                                         if (o_ptr->tval == TV_ROD) o_ptr->timeout = MIN(o_ptr->timeout, k_ptr->pval * (o_ptr->number - 1));
6008                                         else if (o_ptr->tval == TV_WAND) o_ptr->pval = o_ptr->pval * (o_ptr->number - 1) / o_ptr->number;
6009
6010                                 }
6011                                 else
6012 #ifdef JP
6013 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²¿Ëܤ«²õ¤ì¤¿¡ª", o_name);
6014 #else
6015                                         msg_format("Wild magic consumes your %s!", o_name);
6016 #endif
6017
6018                                 /* Reduce and describe inventory */
6019                                 if (item >= 0)
6020                                 {
6021                                         inven_item_increase(item, -1);
6022                                         inven_item_describe(item);
6023                                         inven_item_optimize(item);
6024                                 }
6025
6026                                 /* Reduce and describe floor item */
6027                                 else
6028                                 {
6029                                         floor_item_increase(0 - item, -1);
6030                                         floor_item_describe(0 - item);
6031                                         floor_item_optimize(0 - item);
6032                                 }
6033                         }
6034
6035                         /* Destroy all members of a stack of objects. */
6036                         if (fail_type == 3)
6037                         {
6038                                 if (o_ptr->number > 1)
6039 #ifdef JP
6040 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬Á´¤Æ²õ¤ì¤¿¡ª", o_name);
6041 #else
6042                                         msg_format("Wild magic consumes all your %s!", o_name);
6043 #endif
6044
6045                                 else
6046 #ifdef JP
6047 msg_format("Íð˽¤ÊËâË¡¤Î¤¿¤á¤Ë%s¤¬²õ¤ì¤¿¡ª", o_name);
6048 #else
6049                                         msg_format("Wild magic consumes your %s!", o_name);
6050 #endif
6051
6052
6053
6054                                 /* Reduce and describe inventory */
6055                                 if (item >= 0)
6056                                 {
6057                                         inven_item_increase(item, -999);
6058                                         inven_item_describe(item);
6059                                         inven_item_optimize(item);
6060                                 }
6061
6062                                 /* Reduce and describe floor item */
6063                                 else
6064                                 {
6065                                         floor_item_increase(0 - item, -999);
6066                                         floor_item_describe(0 - item);
6067                                         floor_item_optimize(0 - item);
6068                                 }
6069                         }
6070                 }
6071         }
6072
6073         if (p_ptr->csp > p_ptr->msp)
6074         {
6075                 p_ptr->csp = p_ptr->msp;
6076         }
6077
6078         /* Redraw mana and hp */
6079         p_ptr->redraw |= (PR_MANA);
6080
6081         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
6082         p_ptr->window |= (PW_INVEN);
6083
6084         return TRUE;
6085 }
6086
6087
6088 bool summon_kin_player(int level, int y, int x, u32b mode)
6089 {
6090         bool pet = (bool)(mode & PM_FORCE_PET);
6091         if (!pet) mode |= PM_NO_PET;
6092
6093         switch (p_ptr->mimic_form)
6094         {
6095         case MIMIC_NONE:
6096                 switch (p_ptr->prace)
6097                 {
6098                         case RACE_HUMAN:
6099                         case RACE_AMBERITE:
6100                         case RACE_BARBARIAN:
6101                         case RACE_BEASTMAN:
6102                         case RACE_DUNADAN:
6103                                 summon_kin_type = 'p';
6104                                 break;
6105                         case RACE_HALF_ELF:
6106                         case RACE_ELF:
6107                         case RACE_HOBBIT:
6108                         case RACE_GNOME:
6109                         case RACE_DWARF:
6110                         case RACE_HIGH_ELF:
6111                         case RACE_NIBELUNG:
6112                         case RACE_DARK_ELF:
6113                         case RACE_MIND_FLAYER:
6114                         case RACE_KUTA:
6115                         case RACE_S_FAIRY:
6116                                 summon_kin_type = 'h';
6117                                 break;
6118                         case RACE_HALF_ORC:
6119                                 summon_kin_type = 'o';
6120                                 break;
6121                         case RACE_HALF_TROLL:
6122                                 summon_kin_type = 'T';
6123                                 break;
6124                         case RACE_HALF_OGRE:
6125                                 summon_kin_type = 'O';
6126                                 break;
6127                         case RACE_HALF_GIANT:
6128                         case RACE_HALF_TITAN:
6129                         case RACE_CYCLOPS:
6130                                 summon_kin_type = 'P';
6131                                 break;
6132                         case RACE_YEEK:
6133                                 summon_kin_type = 'y';
6134                                 break;
6135                         case RACE_KLACKON:
6136                                 summon_kin_type = 'K';
6137                                 break;
6138                         case RACE_KOBOLD:
6139                                 summon_kin_type = 'k';
6140                                 break;
6141                         case RACE_IMP:
6142                                 if (one_in_(13)) summon_kin_type = 'U';
6143                                 else summon_kin_type = 'u';
6144                                 break;
6145                         case RACE_DRACONIAN:
6146                                 summon_kin_type = 'd';
6147                                 break;
6148                         case RACE_GOLEM:
6149                         case RACE_ANDROID:
6150                                 summon_kin_type = 'g';
6151                                 break;
6152                         case RACE_SKELETON:
6153                                 if (one_in_(13)) summon_kin_type = 'L';
6154                                 else summon_kin_type = 's';
6155                                 break;
6156                         case RACE_ZOMBIE:
6157                                 summon_kin_type = 'z';
6158                                 break;
6159                         case RACE_VAMPIRE:
6160                                 summon_kin_type = 'V';
6161                                 break;
6162                         case RACE_SPECTRE:
6163                                 summon_kin_type = 'G';
6164                                 break;
6165                         case RACE_SPRITE:
6166                                 summon_kin_type = 'I';
6167                                 break;
6168                         case RACE_ENT:
6169                                 summon_kin_type = '#';
6170                                 break;
6171                         case RACE_ANGEL:
6172                                 summon_kin_type = 'A';
6173                                 break;
6174                         case RACE_DEMON:
6175                                 summon_kin_type = 'U';
6176                                 break;
6177                         default:
6178                                 summon_kin_type = 'p';
6179                                 break;
6180                 }
6181                 break;
6182         case MIMIC_DEMON:
6183                 if (one_in_(13)) summon_kin_type = 'U';
6184                 else summon_kin_type = 'u';
6185                 break;
6186         case MIMIC_DEMON_LORD:
6187                 summon_kin_type = 'U';
6188                 break;
6189         case MIMIC_VAMPIRE:
6190                 summon_kin_type = 'V';
6191                 break;
6192         }       
6193         return summon_specific((pet ? -1 : 0), y, x, level, SUMMON_KIN, mode);
6194 }