OSDN Git Service

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