OSDN Git Service

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