OSDN Git Service

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