OSDN Git Service

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