OSDN Git Service

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