OSDN Git Service

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