OSDN Git Service

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