OSDN Git Service

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