OSDN Git Service

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