OSDN Git Service

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