OSDN Git Service

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