OSDN Git Service

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