OSDN Git Service

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