OSDN Git Service

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