OSDN Git Service

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