OSDN Git Service

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