OSDN Git Service

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