OSDN Git Service

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