OSDN Git Service

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