OSDN Git Service

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