OSDN Git Service

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