OSDN Git Service

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