OSDN Git Service

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