OSDN Git Service

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