OSDN Git Service

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