OSDN Git Service

5885af82b0cd906cdbb4faa08ba4028135477b2e
[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-boost.h"
17 #include "object-hook.h"
18 #include "melee.h"
19 #include "player-status.h"
20 #include "projection.h"
21 #include "spells-summon.h"
22 #include "quest.h"
23 #include "artifact.h"
24 #include "avatar.h"
25 #include "spells-floor.h"
26 #include "monster-status.h"
27 #include "monster-spell.h"
28
29
30 /*! テレポート先探索の試行数 / Maximum number of tries for teleporting */
31 #define MAX_TRIES 100
32
33
34 /*!
35  * @brief モンスターのテレポートアウェイ処理 /
36  * Teleport a monster, normally up to "dis" grids away.
37  * @param m_idx モンスターID
38  * @param dis テレポート距離
39  * @param mode オプション
40  * @return テレポートが実際に行われたらtrue
41  * @details
42  * Attempt to move the monster at least "dis/2" grids away.
43  * But allow variation to prevent infinite loops.
44  */
45 bool teleport_away(MONSTER_IDX m_idx, POSITION dis, BIT_FLAGS mode)
46 {
47         POSITION oy, ox, d, i, min;
48         int tries = 0;
49         POSITION ny = 0, nx = 0;
50
51         bool look = TRUE;
52
53         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
54         if (!monster_is_valid(m_ptr)) return (FALSE);
55
56         oy = m_ptr->fy;
57         ox = m_ptr->fx;
58
59         /* Minimum distance */
60         min = dis / 2;
61
62         if ((mode & TELEPORT_DEC_VALOUR) &&
63             (((p_ptr->chp * 10) / p_ptr->mhp) > 5) &&
64                 (4+randint1(5) < ((p_ptr->chp * 10) / p_ptr->mhp)))
65         {
66                 chg_virtue(V_VALOUR, -1);
67         }
68
69         /* Look until done */
70         while (look)
71         {
72                 tries++;
73
74                 /* Verify max distance */
75                 if (dis > 200) dis = 200;
76
77                 /* Try several locations */
78                 for (i = 0; i < 500; i++)
79                 {
80                         /* Pick a (possibly illegal) location */
81                         while (1)
82                         {
83                                 ny = rand_spread(oy, dis);
84                                 nx = rand_spread(ox, dis);
85                                 d = distance(oy, ox, ny, nx);
86                                 if ((d >= min) && (d <= dis)) break;
87                         }
88
89                         /* Ignore illegal locations */
90                         if (!in_bounds(ny, nx)) continue;
91
92                         if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
93
94                         /* No teleporting into vaults and such */
95                         if (!(p_ptr->inside_quest || p_ptr->inside_arena))
96                                 if (current_floor_ptr->grid_array[ny][nx].info & CAVE_ICKY) continue;
97
98                         /* This grid looks good */
99                         look = FALSE;
100
101                         /* Stop looking */
102                         break;
103                 }
104
105                 /* Increase the maximum distance */
106                 dis = dis * 2;
107
108                 /* Decrease the minimum distance */
109                 min = min / 2;
110
111                 /* Stop after MAX_TRIES tries */
112                 if (tries > MAX_TRIES) return (FALSE);
113         }
114
115         sound(SOUND_TPOTHER);
116
117         /* Update the old location */
118         current_floor_ptr->grid_array[oy][ox].m_idx = 0;
119
120         /* Update the new location */
121         current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
122
123         /* Move the monster */
124         m_ptr->fy = ny;
125         m_ptr->fx = nx;
126
127         /* Forget the counter target */
128         reset_target(m_ptr);
129
130         update_monster(m_idx, TRUE);
131         lite_spot(oy, ox);
132         lite_spot(ny, nx);
133
134         if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
135                 p_ptr->update |= (PU_MON_LITE);
136
137         return (TRUE);
138 }
139
140
141 /*!
142  * @brief モンスターを指定された座標付近にテレポートする /
143  * Teleport monster next to a grid near the given location
144  * @param m_idx モンスターID
145  * @param ty 目安Y座標
146  * @param tx 目安X座標
147  * @param power テレポート成功確率
148  * @param mode オプション
149  * @return なし
150  */
151 void teleport_monster_to(MONSTER_IDX m_idx, POSITION ty, POSITION tx, int power, BIT_FLAGS mode)
152 {
153         POSITION ny, nx, oy, ox;
154         int d, i, min;
155         int attempts = 500;
156         POSITION dis = 2;
157         bool look = TRUE;
158         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
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 (current_floor_ptr->grid_array[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         current_floor_ptr->grid_array[oy][ox].m_idx = 0;
218
219         /* Update the new location */
220         current_floor_ptr->grid_array[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(current_floor_ptr->width - 2, p_ptr->x + dis);
266         int top = MAX(1, p_ptr->y - dis);
267         int bottom = MIN(current_floor_ptr->height - 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 = current_floor_ptr->grid_array[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 = &current_floor_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 = current_floor_ptr->grid_array[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 = &current_floor_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) && (!current_floor_ptr->grid_array[y][x].m_idx || (current_floor_ptr->grid_array[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 = &current_floor_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) && !current_world_ptr->timewalk_m_idx && !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 = current_floor_ptr->grid_array[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 = &current_floor_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 = &current_floor_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)) || (current_floor_ptr->dun_level <= d_info[p_ptr->dungeon_idx].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 (!current_floor_ptr->dun_level)
642                         {
643                                 p_ptr->dungeon_idx = 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 (!current_floor_ptr->dun_level)
653                         {
654                                 current_floor_ptr->dun_level = d_info[p_ptr->dungeon_idx].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                         p_ptr->leaving = TRUE;
662                 }
663         }
664
665         /* Up only */
666         else if (quest_number(current_floor_ptr->dun_level) || (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth))
667         {
668 #ifdef JP
669                 if (see_m) msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
670 #else
671                 if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
672 #endif
673
674
675                 if (m_idx <= 0) /* To player */
676                 {
677                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
678
679                         if (autosave_l) do_cmd_save_game(TRUE);
680
681                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
682
683                         leave_quest_check();
684                         p_ptr->inside_quest = 0;
685                         p_ptr->leaving = TRUE;
686                 }
687         }
688         else if (go_up)
689         {
690 #ifdef JP
691                 if (see_m) msg_format("%^sは天井を突き破って宙へ浮いていく。", m_name);
692 #else
693                 if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
694 #endif
695
696
697                 if (m_idx <= 0) /* To player */
698                 {
699                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
700
701                         if (autosave_l) do_cmd_save_game(TRUE);
702
703                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
704                         p_ptr->leaving = TRUE;
705                 }
706         }
707         else
708         {
709 #ifdef JP
710                 if (see_m) msg_format("%^sは床を突き破って沈んでいく。", m_name);
711 #else
712                 if (see_m) msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
713 #endif
714
715                 if (m_idx <= 0) /* To player */
716                 {
717                         /* Never reach this code on the surface */
718                         /* if (!current_floor_ptr->dun_level) p_ptr->dungeon_idx = p_ptr->recall_dungeon; */
719                         if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
720                         if (autosave_l) do_cmd_save_game(TRUE);
721
722                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
723                         p_ptr->leaving = TRUE;
724                 }
725         }
726
727         /* Monster level teleportation is simple deleting now */
728         if (m_idx > 0)
729         {
730                 monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
731
732                 /* Check for quest completion */
733                 check_quest_completion(m_ptr);
734
735                 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
736                 {
737                         char m2_name[MAX_NLEN];
738
739                         monster_desc(m2_name, m_ptr, MD_INDEF_VISIBLE);
740                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_TELE_LEVEL, m2_name);
741                 }
742
743                 delete_monster_idx(m_idx);
744         }
745
746         sound(SOUND_TPLEVEL);
747 }
748
749
750 /*!
751  * @brief これまでに入ったダンジョンの一覧を表示し、選択させる。
752  * @param note ダンジョンに施す処理記述
753  * @param y コンソールY座標
754  * @param x コンソールX座標
755  * @return 選択されたダンジョンID
756  */
757 DUNGEON_IDX choose_dungeon(concptr note, POSITION y, POSITION x)
758 {
759         DUNGEON_IDX select_dungeon;
760         DUNGEON_IDX i;
761         int num = 0;
762         DUNGEON_IDX *dun;
763
764         /* Hack -- No need to choose dungeon in some case */
765         if (lite_town || vanilla_town || ironman_downward)
766         {
767                 if (max_dlv[DUNGEON_ANGBAND]) return DUNGEON_ANGBAND;
768                 else
769                 {
770                         msg_format(_("まだ%sに入ったことはない。", "You haven't entered %s yet."), d_name + d_info[DUNGEON_ANGBAND].name);
771                         msg_print(NULL);
772                         return 0;
773                 }
774         }
775
776         /* Allocate the "dun" array */
777         C_MAKE(dun, max_d_idx, DUNGEON_IDX);
778
779         screen_save();
780         for(i = 1; i < max_d_idx; i++)
781         {
782                 char buf[80];
783                 bool seiha = FALSE;
784
785                 if (!d_info[i].maxdepth) continue;
786                 if (!max_dlv[i]) continue;
787                 if (d_info[i].final_guardian)
788                 {
789                         if (!r_info[d_info[i].final_guardian].max_num) seiha = TRUE;
790                 }
791                 else if (max_dlv[i] == d_info[i].maxdepth) seiha = TRUE;
792
793                 sprintf(buf,_("      %c) %c%-12s : 最大 %d 階", "      %c) %c%-16s : Max level %d"), 
794                                         'a'+num, seiha ? '!' : ' ', d_name + d_info[i].name, (int)max_dlv[i]);
795                 prt(buf, y + num, x);
796                 dun[num++] = i;
797         }
798
799         if (!num)
800         {
801                 prt(_("      選べるダンジョンがない。", "      No dungeon is available."), y, x);
802         }
803
804         prt(format(_("どのダンジョン%sしますか:", "Which dungeon do you %s?: "), note), 0, 0);
805         while(1)
806         {
807                 i = inkey();
808                 if ((i == ESCAPE) || !num)
809                 {
810                         /* Free the "dun" array */
811                         C_KILL(dun, max_d_idx, DUNGEON_IDX);
812
813                         screen_load();
814                         return 0;
815                 }
816                 if (i >= 'a' && i <('a'+num))
817                 {
818                         select_dungeon = dun[i-'a'];
819                         break;
820                 }
821                 else bell();
822         }
823         screen_load();
824
825         /* Free the "dun" array */
826         C_KILL(dun, max_d_idx, DUNGEON_IDX);
827
828         return select_dungeon;
829 }
830
831
832 /*!
833  * @brief プレイヤーの帰還発動及び中止処理 /
834  * Recall the player to town or dungeon
835  * @param turns 発動までのターン数
836  * @return 常にTRUEを返す
837  */
838 bool recall_player(player_type *creature_ptr, TIME_EFFECT turns)
839 {
840         /*
841          * TODO: Recall the player to the last
842          * visited town when in the wilderness
843          */
844
845         /* Ironman option */
846         if (creature_ptr->inside_arena || ironman_downward)
847         {
848                 msg_print(_("何も起こらなかった。", "Nothing happens."));
849                 return TRUE;
850         }
851
852         if (current_floor_ptr->dun_level && (max_dlv[p_ptr->dungeon_idx] > current_floor_ptr->dun_level) && !creature_ptr->inside_quest && !creature_ptr->word_recall)
853         {
854                 if (get_check(_("ここは最深到達階より浅い階です。この階に戻って来ますか? ", "Reset recall depth? ")))
855                 {
856                         max_dlv[p_ptr->dungeon_idx] = current_floor_ptr->dun_level;
857                         if (record_maxdepth)
858                                 do_cmd_write_nikki(NIKKI_TRUMP, p_ptr->dungeon_idx, _("帰還のときに", "when recall from dungeon"));
859                 }
860
861         }
862         if (!creature_ptr->word_recall)
863         {
864                 if (!current_floor_ptr->dun_level)
865                 {
866                         DUNGEON_IDX select_dungeon;
867                         select_dungeon = choose_dungeon(_("に帰還", "recall"), 2, 14);
868                         if (!select_dungeon) return FALSE;
869                         creature_ptr->recall_dungeon = select_dungeon;
870                 }
871                 creature_ptr->word_recall = turns;
872                 msg_print(_("回りの大気が張りつめてきた...", "The air about you becomes charged..."));
873                 creature_ptr->redraw |= (PR_STATUS);
874         }
875         else
876         {
877                 creature_ptr->word_recall = 0;
878                 msg_print(_("張りつめた大気が流れ去った...", "A tension leaves the air around you..."));
879                 creature_ptr->redraw |= (PR_STATUS);
880         }
881         return TRUE;
882 }
883
884 bool free_level_recall(player_type *creature_ptr)
885 {
886         DUNGEON_IDX select_dungeon;
887         DEPTH max_depth;
888         QUANTITY amt;
889
890         select_dungeon = choose_dungeon(_("にテレポート", "teleport"), 4, 0);
891
892         if (!select_dungeon) return FALSE;
893
894         max_depth = d_info[select_dungeon].maxdepth;
895
896         /* Limit depth in Angband */
897         if (select_dungeon == DUNGEON_ANGBAND)
898         {
899                 if (quest[QUEST_OBERON].status != QUEST_STATUS_FINISHED) max_depth = 98;
900                 else if (quest[QUEST_SERPENT].status != QUEST_STATUS_FINISHED) max_depth = 99;
901         }
902         amt = get_quantity(format(_("%sの何階にテレポートしますか?", "Teleport to which level of %s? "),
903                 d_name + d_info[select_dungeon].name), (QUANTITY)max_depth);
904
905         if (amt > 0)
906         {
907                 creature_ptr->word_recall = 1;
908                 creature_ptr->recall_dungeon = select_dungeon;
909                 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));
910                 if (record_maxdepth)
911                         do_cmd_write_nikki(NIKKI_TRUMP, select_dungeon, _("トランプタワーで", "at Trump Tower"));
912
913                 msg_print(_("回りの大気が張りつめてきた...", "The air about you becomes charged..."));
914
915                 creature_ptr->redraw |= (PR_STATUS);
916                 return TRUE;
917         }
918         return FALSE;
919 }
920
921
922 /*!
923  * @brief フロア・リセット処理
924  * @return リセット処理が実際に行われたらTRUEを返す
925  */
926 bool reset_recall(void)
927 {
928         int select_dungeon, dummy = 0;
929         char ppp[80];
930         char tmp_val[160];
931
932         select_dungeon = choose_dungeon(_("をセット", "reset"), 2, 14);
933
934         /* Ironman option */
935         if (ironman_downward)
936         {
937                 msg_print(_("何も起こらなかった。", "Nothing happens."));
938                 return TRUE;
939         }
940
941         if (!select_dungeon) return FALSE;
942         /* Prompt */
943         sprintf(ppp, _("何階にセットしますか (%d-%d):", "Reset to which level (%d-%d): "),
944                 (int)d_info[select_dungeon].mindepth, (int)max_dlv[select_dungeon]);
945
946         /* Default */
947         sprintf(tmp_val, "%d", (int)MAX(current_floor_ptr->dun_level, 1));
948
949         /* Ask for a level */
950         if (get_string(ppp, tmp_val, 10))
951         {
952                 /* Extract request */
953                 dummy = atoi(tmp_val);
954                 if (dummy < 1) dummy = 1;
955                 if (dummy > max_dlv[select_dungeon]) dummy = max_dlv[select_dungeon];
956                 if (dummy < d_info[select_dungeon].mindepth) dummy = d_info[select_dungeon].mindepth;
957
958                 max_dlv[select_dungeon] = dummy;
959
960                 if (record_maxdepth)
961                         do_cmd_write_nikki(NIKKI_TRUMP, select_dungeon, _("フロア・リセットで", "using a scroll of reset recall"));
962                                         /* Accept request */
963 #ifdef JP
964                 msg_format("%sの帰還レベルを %d 階にセット。", d_name+d_info[select_dungeon].name, dummy, dummy * 50);
965 #else
966                 msg_format("Recall depth set to level %d (%d').", dummy, dummy * 50);
967 #endif
968
969         }
970         else
971         {
972                 return FALSE;
973         }
974         return TRUE;
975 }
976
977
978 /*!
979  * @brief プレイヤーの装備劣化処理 /
980  * Apply disenchantment to the player's stuff
981  * @param mode 最下位ビットが1ならば劣化処理が若干低減される
982  * @return 劣化処理に関するメッセージが発せられた場合はTRUEを返す /
983  * Return "TRUE" if the player notices anything
984  */
985 bool apply_disenchant(BIT_FLAGS mode)
986 {
987         int             t = 0;
988         object_type *o_ptr;
989         GAME_TEXT o_name[MAX_NLEN];
990         int to_h, to_d, to_a, pval;
991
992         /* Pick a random slot */
993         switch (randint1(8))
994         {
995                 case 1: t = INVEN_RARM; break;
996                 case 2: t = INVEN_LARM; break;
997                 case 3: t = INVEN_BOW; break;
998                 case 4: t = INVEN_BODY; break;
999                 case 5: t = INVEN_OUTER; break;
1000                 case 6: t = INVEN_HEAD; break;
1001                 case 7: t = INVEN_HANDS; break;
1002                 case 8: t = INVEN_FEET; break;
1003         }
1004
1005         o_ptr = &inventory[t];
1006
1007         /* No item, nothing happens */
1008         if (!o_ptr->k_idx) return (FALSE);
1009
1010         /* Disenchant equipments only -- No disenchant on monster ball */
1011         if (!object_is_weapon_armour_ammo(o_ptr))
1012                 return FALSE;
1013
1014         /* Nothing to disenchant */
1015         if ((o_ptr->to_h <= 0) && (o_ptr->to_d <= 0) && (o_ptr->to_a <= 0) && (o_ptr->pval <= 1))
1016         {
1017                 /* Nothing to notice */
1018                 return (FALSE);
1019         }
1020
1021         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1022
1023         /* Artifacts have 71% chance to resist */
1024         if (object_is_artifact(o_ptr) && (randint0(100) < 71))
1025         {
1026 #ifdef JP
1027                 msg_format("%s(%c)は劣化を跳ね返した!",o_name, index_to_label(t) );
1028 #else
1029                 msg_format("Your %s (%c) resist%s disenchantment!", o_name, index_to_label(t),
1030                         ((o_ptr->number != 1) ? "" : "s"));
1031 #endif
1032                 return (TRUE);
1033         }
1034
1035
1036         /* Memorize old value */
1037         to_h = o_ptr->to_h;
1038         to_d = o_ptr->to_d;
1039         to_a = o_ptr->to_a;
1040         pval = o_ptr->pval;
1041
1042         /* Disenchant tohit */
1043         if (o_ptr->to_h > 0) o_ptr->to_h--;
1044         if ((o_ptr->to_h > 5) && (randint0(100) < 20)) o_ptr->to_h--;
1045
1046         /* Disenchant todam */
1047         if (o_ptr->to_d > 0) o_ptr->to_d--;
1048         if ((o_ptr->to_d > 5) && (randint0(100) < 20)) o_ptr->to_d--;
1049
1050         /* Disenchant toac */
1051         if (o_ptr->to_a > 0) o_ptr->to_a--;
1052         if ((o_ptr->to_a > 5) && (randint0(100) < 20)) o_ptr->to_a--;
1053
1054         /* Disenchant pval (occasionally) */
1055         /* Unless called from wild_magic() */
1056         if ((o_ptr->pval > 1) && one_in_(13) && !(mode & 0x01)) o_ptr->pval--;
1057
1058         if ((to_h != o_ptr->to_h) || (to_d != o_ptr->to_d) ||
1059             (to_a != o_ptr->to_a) || (pval != o_ptr->pval))
1060         {
1061 #ifdef JP
1062                 msg_format("%s(%c)は劣化してしまった!", o_name, index_to_label(t) );
1063 #else
1064                 msg_format("Your %s (%c) %s disenchanted!", o_name, index_to_label(t),
1065                         ((o_ptr->number != 1) ? "were" : "was"));
1066 #endif
1067
1068                 chg_virtue(V_HARMONY, 1);
1069                 chg_virtue(V_ENCHANT, -2);
1070                 p_ptr->update |= (PU_BONUS);
1071                 p_ptr->window |= (PW_EQUIP | PW_PLAYER);
1072
1073                 calc_android_exp();
1074         }
1075
1076         return (TRUE);
1077 }
1078
1079
1080 /*!
1081  * @brief 武器へのエゴ付加処理 /
1082  * Brand the current weapon
1083  * @param brand_type エゴ化ID(e_info.txtとは連動していない)
1084  * @return なし
1085  */
1086 void brand_weapon(int brand_type)
1087 {
1088         OBJECT_IDX item;
1089         object_type *o_ptr;
1090         concptr q, s;
1091
1092         /* Assume enchant weapon */
1093         item_tester_hook = object_allow_enchant_melee_weapon;
1094
1095         q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
1096         s = _("強化できる武器がない。", "You have nothing to enchant.");
1097
1098         o_ptr = choose_object(&item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT));
1099         if (!o_ptr) return;
1100
1101         /* you can never modify artifacts / ego-items */
1102         /* you can never modify cursed items */
1103         /* TY: You _can_ modify broken items (if you're silly enough) */
1104         if (o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) &&
1105             !object_is_cursed(o_ptr) &&
1106             !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) &&
1107             !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE)) &&
1108             !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE)))
1109         {
1110                 concptr act = NULL;
1111
1112                 /* Let's get the name before it is changed... */
1113                 GAME_TEXT o_name[MAX_NLEN];
1114                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1115
1116                 switch (brand_type)
1117                 {
1118                 case 17:
1119                         if (o_ptr->tval == TV_SWORD)
1120                         {
1121                                 act = _("は鋭さを増した!", "becomes very sharp!");
1122
1123                                 o_ptr->name2 = EGO_SHARPNESS;
1124                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, current_floor_ptr->dun_level) + 1;
1125
1126                                 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
1127                                         o_ptr->pval = 2;
1128                         }
1129                         else
1130                         {
1131                                 act = _("は破壊力を増した!", "seems very powerful.");
1132                                 o_ptr->name2 = EGO_EARTHQUAKES;
1133                                 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, current_floor_ptr->dun_level);
1134                         }
1135                         break;
1136                 case 16:
1137                         act = _("は人間の血を求めている!", "seems to be looking for humans!");
1138                         o_ptr->name2 = EGO_KILL_HUMAN;
1139                         break;
1140                 case 15:
1141                         act = _("は電撃に覆われた!", "covered with lightning!");
1142                         o_ptr->name2 = EGO_BRAND_ELEC;
1143                         break;
1144                 case 14:
1145                         act = _("は酸に覆われた!", "coated with acid!");
1146                         o_ptr->name2 = EGO_BRAND_ACID;
1147                         break;
1148                 case 13:
1149                         act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
1150                         o_ptr->name2 = EGO_KILL_EVIL;
1151                         break;
1152                 case 12:
1153                         act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
1154                         o_ptr->name2 = EGO_KILL_DEMON;
1155                         break;
1156                 case 11:
1157                         act = _("は屍を求めている!", "seems to be looking for undead!");
1158                         o_ptr->name2 = EGO_KILL_UNDEAD;
1159                         break;
1160                 case 10:
1161                         act = _("は動物の血を求めている!", "seems to be looking for animals!");
1162                         o_ptr->name2 = EGO_KILL_ANIMAL;
1163                         break;
1164                 case 9:
1165                         act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
1166                         o_ptr->name2 = EGO_KILL_DRAGON;
1167                         break;
1168                 case 8:
1169                         act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
1170                         o_ptr->name2 = EGO_KILL_TROLL;
1171                         break;
1172                 case 7:
1173                         act = _("はオークの血を求めている!", "seems to be looking for orcs!");
1174                         o_ptr->name2 = EGO_KILL_ORC;
1175                         break;
1176                 case 6:
1177                         act = _("は巨人の血を求めている!", "seems to be looking for giants!");
1178                         o_ptr->name2 = EGO_KILL_GIANT;
1179                         break;
1180                 case 5:
1181                         act = _("は非常に不安定になったようだ。", "seems very unstable now.");
1182                         o_ptr->name2 = EGO_TRUMP;
1183                         o_ptr->pval = randint1(2);
1184                         break;
1185                 case 4:
1186                         act = _("は血を求めている!", "thirsts for blood!");
1187                         o_ptr->name2 = EGO_VAMPIRIC;
1188                         break;
1189                 case 3:
1190                         act = _("は毒に覆われた。", "is coated with poison.");
1191                         o_ptr->name2 = EGO_BRAND_POIS;
1192                         break;
1193                 case 2:
1194                         act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
1195                         o_ptr->name2 = EGO_CHAOTIC;
1196                         break;
1197                 case 1:
1198                         act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
1199                         o_ptr->name2 = EGO_BRAND_FIRE;
1200                         break;
1201                 default:
1202                         act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
1203                         o_ptr->name2 = EGO_BRAND_COLD;
1204                         break;
1205                 }
1206
1207                 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
1208                 enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
1209
1210                 o_ptr->discount = 99;
1211                 chg_virtue(V_ENCHANT, 2);
1212         }
1213         else
1214         {
1215                 if (flush_failure) flush();
1216
1217                 msg_print(_("属性付加に失敗した。", "The Branding failed."));
1218                 chg_virtue(V_ENCHANT, -2);
1219         }
1220         calc_android_exp();
1221 }
1222
1223
1224 /*!
1225  * @brief 虚無招来によるフロア中の全壁除去処理 /
1226  * Vanish all walls in this floor
1227  * @return 実際に処理が反映された場合TRUE
1228  */
1229 static bool vanish_dungeon(void)
1230 {
1231         POSITION y, x;
1232         grid_type *g_ptr;
1233         feature_type *f_ptr;
1234         monster_type *m_ptr;
1235         GAME_TEXT m_name[MAX_NLEN];
1236
1237         /* Prevent vasishing of quest levels and town */
1238         if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !current_floor_ptr->dun_level)
1239         {
1240                 return FALSE;
1241         }
1242
1243         /* Scan all normal grids */
1244         for (y = 1; y < current_floor_ptr->height - 1; y++)
1245         {
1246                 for (x = 1; x < current_floor_ptr->width - 1; x++)
1247                 {
1248                         g_ptr = &current_floor_ptr->grid_array[y][x];
1249
1250                         /* Seeing true feature code (ignore mimic) */
1251                         f_ptr = &f_info[g_ptr->feat];
1252
1253                         /* Lose room and vault */
1254                         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1255
1256                         m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
1257
1258                         /* Awake monster */
1259                         if (g_ptr->m_idx && MON_CSLEEP(m_ptr))
1260                         {
1261                                 /* Reset sleep counter */
1262                                 (void)set_monster_csleep(g_ptr->m_idx, 0);
1263
1264                                 /* Notice the "waking up" */
1265                                 if (m_ptr->ml)
1266                                 {
1267                                         monster_desc(m_name, m_ptr, 0);
1268                                         msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1269                                 }
1270                         }
1271
1272                         /* Process all walls, doors and patterns */
1273                         if (have_flag(f_ptr->flags, FF_HURT_DISI)) cave_alter_feat(y, x, FF_HURT_DISI);
1274                 }
1275         }
1276
1277         /* Special boundary walls -- Top and bottom */
1278         for (x = 0; x < current_floor_ptr->width; x++)
1279         {
1280                 g_ptr = &current_floor_ptr->grid_array[0][x];
1281                 f_ptr = &f_info[g_ptr->mimic];
1282
1283                 /* Lose room and vault */
1284                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1285
1286                 /* Set boundary mimic if needed */
1287                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1288                 {
1289                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1290
1291                         /* Check for change to boring grid */
1292                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1293                 }
1294
1295                 g_ptr = &current_floor_ptr->grid_array[current_floor_ptr->height - 1][x];
1296                 f_ptr = &f_info[g_ptr->mimic];
1297
1298                 /* Lose room and vault */
1299                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1300
1301                 /* Set boundary mimic if needed */
1302                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1303                 {
1304                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1305
1306                         /* Check for change to boring grid */
1307                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1308                 }
1309         }
1310
1311         /* Special boundary walls -- Left and right */
1312         for (y = 1; y < (current_floor_ptr->height - 1); y++)
1313         {
1314                 g_ptr = &current_floor_ptr->grid_array[y][0];
1315                 f_ptr = &f_info[g_ptr->mimic];
1316
1317                 /* Lose room and vault */
1318                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1319
1320                 /* Set boundary mimic if needed */
1321                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1322                 {
1323                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1324
1325                         /* Check for change to boring grid */
1326                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1327                 }
1328
1329                 g_ptr = &current_floor_ptr->grid_array[y][current_floor_ptr->width - 1];
1330                 f_ptr = &f_info[g_ptr->mimic];
1331
1332                 /* Lose room and vault */
1333                 g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
1334
1335                 /* Set boundary mimic if needed */
1336                 if (g_ptr->mimic && have_flag(f_ptr->flags, FF_HURT_DISI))
1337                 {
1338                         g_ptr->mimic = feat_state(g_ptr->mimic, FF_HURT_DISI);
1339
1340                         /* Check for change to boring grid */
1341                         if (!have_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1342                 }
1343         }
1344
1345         /* Mega-Hack -- Forget the view and lite */
1346         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
1347         p_ptr->redraw |= (PR_MAP);
1348         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1349
1350         return TRUE;
1351 }
1352
1353 /*!
1354  * @brief 虚無招来処理 /
1355  * @return なし
1356  */
1357 void call_the_(void)
1358 {
1359         int i;
1360         grid_type *g_ptr;
1361         bool do_call = TRUE;
1362
1363         for (i = 0; i < 9; i++)
1364         {
1365                 g_ptr = &current_floor_ptr->grid_array[p_ptr->y + ddy_ddd[i]][p_ptr->x + ddx_ddd[i]];
1366
1367                 if (!cave_have_flag_grid(g_ptr, FF_PROJECT))
1368                 {
1369                         if (!g_ptr->mimic || !have_flag(f_info[g_ptr->mimic].flags, FF_PROJECT) ||
1370                             !permanent_wall(&f_info[g_ptr->feat]))
1371                         {
1372                                 do_call = FALSE;
1373                                 break;
1374                         }
1375                 }
1376         }
1377
1378         if (do_call)
1379         {
1380                 for (i = 1; i < 10; i++)
1381                 {
1382                         if (i - 5) fire_ball(GF_ROCKET, i, 175, 2);
1383                 }
1384
1385                 for (i = 1; i < 10; i++)
1386                 {
1387                         if (i - 5) fire_ball(GF_MANA, i, 175, 3);
1388                 }
1389
1390                 for (i = 1; i < 10; i++)
1391                 {
1392                         if (i - 5) fire_ball(GF_NUKE, i, 175, 4);
1393                 }
1394         }
1395
1396         /* Prevent destruction of quest levels and town */
1397         else if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !current_floor_ptr->dun_level)
1398         {
1399                 msg_print(_("地面が揺れた。", "The ground trembles."));
1400         }
1401
1402         else
1403         {
1404 #ifdef JP
1405                 msg_format("あなたは%sを壁に近すぎる場所で唱えてしまった!",
1406                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "祈り" : "呪文"));
1407 #else
1408                 msg_format("You %s the %s too close to a wall!",
1409                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1410                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "prayer" : "spell"));
1411 #endif
1412                 msg_print(_("大きな爆発音があった!", "There is a loud explosion!"));
1413
1414                 if (one_in_(666))
1415                 {
1416                         if (!vanish_dungeon()) msg_print(_("ダンジョンは一瞬静まり返った。", "The dungeon silences a moment."));
1417                 }
1418                 else
1419                 {
1420                         if (destroy_area(p_ptr->y, p_ptr->x, 15 + p_ptr->lev + randint0(11), FALSE))
1421                                 msg_print(_("ダンジョンが崩壊した...", "The dungeon collapses..."));
1422                         else
1423                                 msg_print(_("ダンジョンは大きく揺れた。", "The dungeon trembles."));
1424                 }
1425
1426                 take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), _("自殺的な虚無招来", "a suicidal Call the Void"), -1);
1427         }
1428 }
1429
1430
1431 /*!
1432  * @brief アイテム引き寄せ処理 /
1433  * Fetch an item (teleport it right underneath the caster)
1434  * @param dir 魔法の発動方向
1435  * @param wgt 許容重量
1436  * @param require_los 射線の通りを要求するならばTRUE
1437  * @return なし
1438  */
1439 void fetch(DIRECTION dir, WEIGHT wgt, bool require_los)
1440 {
1441         POSITION ty, tx;
1442         OBJECT_IDX i;
1443         grid_type *g_ptr;
1444         object_type *o_ptr;
1445         GAME_TEXT o_name[MAX_NLEN];
1446
1447         /* Check to see if an object is already there */
1448         if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx)
1449         {
1450                 msg_print(_("自分の足の下にある物は取れません。", "You can't fetch when you're already standing on something."));
1451                 return;
1452         }
1453
1454         /* Use a target */
1455         if (dir == 5 && target_okay())
1456         {
1457                 tx = target_col;
1458                 ty = target_row;
1459
1460                 if (distance(p_ptr->y, p_ptr->x, ty, tx) > MAX_RANGE)
1461                 {
1462                         msg_print(_("そんなに遠くにある物は取れません!", "You can't fetch something that far away!"));
1463                         return;
1464                 }
1465
1466                 g_ptr = &current_floor_ptr->grid_array[ty][tx];
1467
1468                 /* We need an item to fetch */
1469                 if (!g_ptr->o_idx)
1470                 {
1471                         msg_print(_("そこには何もありません。", "There is no object at this place."));
1472                         return;
1473                 }
1474
1475                 /* No fetching from vault */
1476                 if (g_ptr->info & CAVE_ICKY)
1477                 {
1478                         msg_print(_("アイテムがコントロールを外れて落ちた。", "The item slips from your control."));
1479                         return;
1480                 }
1481
1482                 /* We need to see the item */
1483                 if (require_los)
1484                 {
1485                         if (!player_has_los_bold(ty, tx))
1486                         {
1487                                 msg_print(_("そこはあなたの視界に入っていません。", "You have no direct line of sight to that location."));
1488                                 return;
1489                         }
1490                         else if (!projectable(p_ptr->y, p_ptr->x, ty, tx))
1491                         {
1492                                 msg_print(_("そこは壁の向こうです。", "You have no direct line of sight to that location."));
1493                                 return;
1494                         }
1495                 }
1496         }
1497         else
1498         {
1499                 ty = p_ptr->y; 
1500                 tx = p_ptr->x;
1501                 do
1502                 {
1503                         ty += ddy[dir];
1504                         tx += ddx[dir];
1505                         g_ptr = &current_floor_ptr->grid_array[ty][tx];
1506
1507                         if ((distance(p_ptr->y, p_ptr->x, ty, tx) > MAX_RANGE) ||
1508                                 !cave_have_flag_bold(ty, tx, FF_PROJECT)) return;
1509                 }
1510                 while (!g_ptr->o_idx);
1511         }
1512
1513         o_ptr = &current_floor_ptr->o_list[g_ptr->o_idx];
1514
1515         if (o_ptr->weight > wgt)
1516         {
1517                 /* Too heavy to 'fetch' */
1518                 msg_print(_("そのアイテムは重過ぎます。", "The object is too heavy."));
1519                 return;
1520         }
1521
1522         i = g_ptr->o_idx;
1523         g_ptr->o_idx = o_ptr->next_o_idx;
1524         current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx = i; /* 'move' it */
1525
1526         o_ptr->next_o_idx = 0;
1527         o_ptr->iy = p_ptr->y;
1528         o_ptr->ix = p_ptr->x;
1529
1530         object_desc(o_name, o_ptr, OD_NAME_ONLY);
1531         msg_format(_("%^sがあなたの足元に飛んできた。", "%^s flies through the air to your feet."), o_name);
1532
1533         note_spot(p_ptr->y, p_ptr->x);
1534         p_ptr->redraw |= PR_MAP;
1535 }
1536
1537 /*!
1538  * @brief 現実変容処理
1539  * @return なし
1540  */
1541 void alter_reality(void)
1542 {
1543         /* Ironman option */
1544         if (p_ptr->inside_arena || ironman_downward)
1545         {
1546                 msg_print(_("何も起こらなかった。", "Nothing happens."));
1547                 return;
1548         }
1549
1550         if (!p_ptr->alter_reality)
1551         {
1552                 TIME_EFFECT turns = randint0(21) + 15;
1553
1554                 p_ptr->alter_reality = turns;
1555                 msg_print(_("回りの景色が変わり始めた...", "The view around you begins to change..."));
1556
1557                 p_ptr->redraw |= (PR_STATUS);
1558         }
1559         else
1560         {
1561                 p_ptr->alter_reality = 0;
1562                 msg_print(_("景色が元に戻った...", "The view around you got back..."));
1563                 p_ptr->redraw |= (PR_STATUS);
1564         }
1565         return;
1566 }
1567
1568 /*!
1569  * @brief 全所持アイテム鑑定処理 /
1570  * Identify everything being carried.
1571  * Done by a potion of "self knowledge".
1572  * @return なし
1573  */
1574 void identify_pack(void)
1575 {
1576         INVENTORY_IDX i;
1577
1578         /* Simply identify and know every item */
1579         for (i = 0; i < INVEN_TOTAL; i++)
1580         {
1581                 object_type *o_ptr = &inventory[i];
1582
1583                 /* Skip non-objects */
1584                 if (!o_ptr->k_idx) continue;
1585
1586                 identify_item(o_ptr);
1587
1588                 /* Auto-inscription */
1589                 autopick_alter_item(i, FALSE);
1590         }
1591 }
1592
1593
1594 /*!
1595  * @brief 装備強化処理の失敗率定数(千分率) /
1596  * Used by the "enchant" function (chance of failure)
1597  * (modified for Zangband, we need better stuff there...) -- TY
1598  * @return なし
1599  */
1600 static int enchant_table[16] =
1601 {
1602         0, 10,  50, 100, 200,
1603         300, 400, 500, 650, 800,
1604         950, 987, 993, 995, 998,
1605         1000
1606 };
1607
1608
1609 /*!
1610  * @brief 装備の解呪処理 /
1611  * Removes curses from items in inventory
1612  * @param all 軽い呪いまでの解除ならば0
1613  * @return 解呪されたアイテムの数
1614  * @details
1615  * <pre>
1616  * Note that Items which are "Perma-Cursed" (The One Ring,
1617  * The Crown of Morgoth) can NEVER be uncursed.
1618  *
1619  * Note that if "all" is FALSE, then Items which are
1620  * "Heavy-Cursed" (Mormegil, Calris, and Weapons of Morgul)
1621  * will not be uncursed.
1622  * </pre>
1623  */
1624 static int remove_curse_aux(int all)
1625 {
1626         int i, cnt = 0;
1627
1628         /* Attempt to uncurse items being worn */
1629         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1630         {
1631                 object_type *o_ptr = &inventory[i];
1632
1633                 /* Skip non-objects */
1634                 if (!o_ptr->k_idx) continue;
1635
1636                 /* Uncursed already */
1637                 if (!object_is_cursed(o_ptr)) continue;
1638
1639                 /* Heavily Cursed Items need a special spell */
1640                 if (!all && (o_ptr->curse_flags & TRC_HEAVY_CURSE)) continue;
1641
1642                 /* Perma-Cursed Items can NEVER be uncursed */
1643                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
1644                 {
1645                         o_ptr->curse_flags &= (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE);
1646                         continue;
1647                 }
1648
1649                 o_ptr->curse_flags = 0L;
1650                 o_ptr->ident |= (IDENT_SENSE);
1651                 o_ptr->feeling = FEEL_NONE;
1652
1653                 p_ptr->update |= (PU_BONUS);
1654                 p_ptr->window |= (PW_EQUIP);
1655
1656                 /* Count the uncursings */
1657                 cnt++;
1658         }
1659
1660         if (cnt)
1661         {
1662                 msg_print(_("誰かに見守られているような気がする。", "You feel as if someone is watching over you."));
1663         }
1664         /* Return "something uncursed" */
1665         return (cnt);
1666 }
1667
1668
1669 /*!
1670  * @brief 装備の軽い呪い解呪処理 /
1671  * Remove most curses
1672  * @return 解呪に成功した装備数
1673  */
1674 int remove_curse(void)
1675 {
1676         return (remove_curse_aux(FALSE));
1677 }
1678
1679 /*!
1680  * @brief 装備の重い呪い解呪処理 /
1681  * Remove all curses
1682  * @return 解呪に成功した装備数
1683  */
1684 int remove_all_curse(void)
1685 {
1686         return (remove_curse_aux(TRUE));
1687 }
1688
1689
1690 /*!
1691  * @brief アイテムの価値に応じた錬金術処理 /
1692  * Turns an object into gold, gain some of its value in a shop
1693  * @return 処理が実際に行われたらTRUEを返す
1694  */
1695 bool alchemy(void)
1696 {
1697         OBJECT_IDX item;
1698         int amt = 1;
1699         ITEM_NUMBER old_number;
1700         PRICE price;
1701         bool force = FALSE;
1702         object_type *o_ptr;
1703         GAME_TEXT o_name[MAX_NLEN];
1704         char out_val[MAX_NLEN+40];
1705
1706         concptr q, s;
1707
1708         /* Hack -- force destruction */
1709         if (command_arg > 0) force = TRUE;
1710
1711         q = _("どのアイテムを金に変えますか?", "Turn which item to gold? ");
1712         s = _("金に変えられる物がありません。", "You have nothing to current_world_ptr->game_turn to gold.");
1713
1714         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
1715         if (!o_ptr) return (FALSE);
1716
1717         /* See how many items */
1718         if (o_ptr->number > 1)
1719         {
1720                 amt = get_quantity(NULL, o_ptr->number);
1721
1722                 /* Allow user abort */
1723                 if (amt <= 0) return FALSE;
1724         }
1725
1726         old_number = o_ptr->number;
1727         o_ptr->number = amt;
1728         object_desc(o_name, o_ptr, 0);
1729         o_ptr->number = old_number;
1730
1731         /* Verify unless quantity given */
1732         if (!force)
1733         {
1734                 if (confirm_destroy || (object_value(o_ptr) > 0))
1735                 {
1736                         /* Make a verification */
1737                         sprintf(out_val, _("本当に%sを金に変えますか?", "Really current_world_ptr->game_turn %s to gold? "), o_name);
1738                         if (!get_check(out_val)) return FALSE;
1739                 }
1740         }
1741
1742         /* Artifacts cannot be destroyed */
1743         if (!can_player_destroy_object(o_ptr))
1744         {
1745                 msg_format(_("%sを金に変えることに失敗した。", "You fail to current_world_ptr->game_turn %s to gold!"), o_name);
1746
1747                 return FALSE;
1748         }
1749
1750         price = object_value_real(o_ptr);
1751
1752         if (price <= 0)
1753         {
1754                 msg_format(_("%sをニセの金に変えた。", "You current_world_ptr->game_turn %s to fool's gold."), o_name);
1755         }
1756         else
1757         {
1758                 price /= 3;
1759
1760                 if (amt > 1) price *= amt;
1761
1762                 if (price > 30000) price = 30000;
1763                 msg_format(_("%sを$%d の金に変えた。", "You current_world_ptr->game_turn %s to %ld coins worth of gold."), o_name, price);
1764
1765                 p_ptr->au += price;
1766                 p_ptr->redraw |= (PR_GOLD);
1767                 p_ptr->window |= (PW_PLAYER);
1768         }
1769
1770         /* Eliminate the item (from the pack) */
1771         if (item >= 0)
1772         {
1773                 inven_item_increase(item, -amt);
1774                 inven_item_describe(item);
1775                 inven_item_optimize(item);
1776         }
1777
1778         /* Eliminate the item (from the floor) */
1779         else
1780         {
1781                 floor_item_increase(0 - item, -amt);
1782                 floor_item_describe(0 - item);
1783                 floor_item_optimize(0 - item);
1784         }
1785
1786         return TRUE;
1787 }
1788
1789
1790 /*!
1791  * @brief 呪いの打ち破り処理 /
1792  * Break the curse of an item
1793  * @param o_ptr 呪い装備情報の参照ポインタ
1794  * @return なし
1795  */
1796 static void break_curse(object_type *o_ptr)
1797 {
1798         if (object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
1799         {
1800                 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
1801
1802                 o_ptr->curse_flags = 0L;
1803                 o_ptr->ident |= (IDENT_SENSE);
1804                 o_ptr->feeling = FEEL_NONE;
1805         }
1806 }
1807
1808
1809 /*!
1810  * @brief 装備修正強化処理 /
1811  * Enchants a plus onto an item. -RAK-
1812  * @param o_ptr 強化するアイテムの参照ポインタ
1813  * @param n 強化基本量
1814  * @param eflag 強化オプション(命中/ダメージ/AC)
1815  * @return 強化に成功した場合TRUEを返す
1816  * @details
1817  * <pre>
1818  * Revamped!  Now takes item pointer, number of times to try enchanting,
1819  * and a flag of what to try enchanting.  Artifacts resist enchantment
1820  * some of the time, and successful enchantment to at least +0 might
1821  * break a curse on the item. -CFT-
1822  *
1823  * Note that an item can technically be enchanted all the way to +15 if
1824  * you wait a very, very, long time.  Going from +9 to +10 only works
1825  * about 5% of the time, and from +10 to +11 only about 1% of the time.
1826  *
1827  * Note that this function can now be used on "piles" of items, and
1828  * the larger the pile, the lower the chance of success.
1829  * </pre>
1830  */
1831 bool enchant(object_type *o_ptr, int n, int eflag)
1832 {
1833         int     i, chance, prob;
1834         bool    res = FALSE;
1835         bool    a = object_is_artifact(o_ptr);
1836         bool    force = (eflag & ENCH_FORCE);
1837
1838         /* Large piles resist enchantment */
1839         prob = o_ptr->number * 100;
1840
1841         /* Missiles are easy to enchant */
1842         if ((o_ptr->tval == TV_BOLT) ||
1843             (o_ptr->tval == TV_ARROW) ||
1844             (o_ptr->tval == TV_SHOT))
1845         {
1846                 prob = prob / 20;
1847         }
1848
1849         /* Try "n" times */
1850         for (i = 0; i < n; i++)
1851         {
1852                 /* Hack -- Roll for pile resistance */
1853                 if (!force && randint0(prob) >= 100) continue;
1854
1855                 /* Enchant to hit */
1856                 if (eflag & ENCH_TOHIT)
1857                 {
1858                         if (o_ptr->to_h < 0) chance = 0;
1859                         else if (o_ptr->to_h > 15) chance = 1000;
1860                         else chance = enchant_table[o_ptr->to_h];
1861
1862                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1863                         {
1864                                 o_ptr->to_h++;
1865                                 res = TRUE;
1866
1867                                 /* only when you get it above -1 -CFT */
1868                                 if (o_ptr->to_h >= 0)
1869                                         break_curse(o_ptr);
1870                         }
1871                 }
1872
1873                 /* Enchant to damage */
1874                 if (eflag & ENCH_TODAM)
1875                 {
1876                         if (o_ptr->to_d < 0) chance = 0;
1877                         else if (o_ptr->to_d > 15) chance = 1000;
1878                         else chance = enchant_table[o_ptr->to_d];
1879
1880                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1881                         {
1882                                 o_ptr->to_d++;
1883                                 res = TRUE;
1884
1885                                 /* only when you get it above -1 -CFT */
1886                                 if (o_ptr->to_d >= 0)
1887                                         break_curse(o_ptr);
1888                         }
1889                 }
1890
1891                 /* Enchant to armor class */
1892                 if (eflag & ENCH_TOAC)
1893                 {
1894                         if (o_ptr->to_a < 0) chance = 0;
1895                         else if (o_ptr->to_a > 15) chance = 1000;
1896                         else chance = enchant_table[o_ptr->to_a];
1897
1898                         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1899                         {
1900                                 o_ptr->to_a++;
1901                                 res = TRUE;
1902
1903                                 /* only when you get it above -1 -CFT */
1904                                 if (o_ptr->to_a >= 0)
1905                                         break_curse(o_ptr);
1906                         }
1907                 }
1908         }
1909
1910         /* Failure */
1911         if (!res) return (FALSE);
1912         p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
1913         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1914
1915         calc_android_exp();
1916
1917         /* Success */
1918         return (TRUE);
1919 }
1920
1921
1922 /*!
1923  * @brief 装備修正強化処理のメインルーチン /
1924  * Enchant an item (in the inventory or on the floor)
1925  * @param num_hit 命中修正量
1926  * @param num_dam ダメージ修正量
1927  * @param num_ac AC修正量
1928  * @return 強化に成功した場合TRUEを返す
1929  * @details
1930  * Note that "num_ac" requires armour, else weapon
1931  * Returns TRUE if attempted, FALSE if cancelled
1932  */
1933 bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
1934 {
1935         OBJECT_IDX item;
1936         bool        okay = FALSE;
1937         object_type *o_ptr;
1938         GAME_TEXT o_name[MAX_NLEN];
1939         concptr        q, s;
1940
1941         /* Assume enchant weapon */
1942         item_tester_hook = object_allow_enchant_weapon;
1943
1944         /* Enchant armor if requested */
1945         if (num_ac) item_tester_hook = object_is_armour;
1946
1947         q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
1948         s = _("強化できるアイテムがない。", "You have nothing to enchant.");
1949
1950         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
1951         if (!o_ptr) return (FALSE);
1952
1953         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1954 #ifdef JP
1955         msg_format("%s は明るく輝いた!", o_name);
1956 #else
1957         msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
1958 #endif
1959
1960         /* Enchant */
1961         if (enchant(o_ptr, num_hit, ENCH_TOHIT)) okay = TRUE;
1962         if (enchant(o_ptr, num_dam, ENCH_TODAM)) okay = TRUE;
1963         if (enchant(o_ptr, num_ac, ENCH_TOAC)) okay = TRUE;
1964
1965         /* Failure */
1966         if (!okay)
1967         {
1968                 if (flush_failure) flush();
1969                 msg_print(_("強化に失敗した。", "The enchantment failed."));
1970                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
1971         }
1972         else
1973                 chg_virtue(V_ENCHANT, 1);
1974
1975         calc_android_exp();
1976
1977         /* Something happened */
1978         return (TRUE);
1979 }
1980
1981
1982 /*!
1983  * @brief アーティファクト生成の巻物処理 /
1984  * @return 生成が実際に試みられたらTRUEを返す
1985  */
1986 bool artifact_scroll(void)
1987 {
1988         OBJECT_IDX item;
1989         bool okay = FALSE;
1990         object_type *o_ptr;
1991         GAME_TEXT o_name[MAX_NLEN];
1992         concptr q, s;
1993
1994         /* Enchant weapon/armour */
1995         item_tester_hook = item_tester_hook_nameless_weapon_armour;
1996
1997         q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
1998         s = _("強化できるアイテムがない。", "You have nothing to enchant.");
1999
2000         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
2001         if (!o_ptr) return (FALSE);
2002
2003         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2004 #ifdef JP
2005         msg_format("%s は眩い光を発した!",o_name);
2006 #else
2007         msg_format("%s %s radiate%s a blinding light!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
2008 #endif
2009
2010         if (object_is_artifact(o_ptr))
2011         {
2012 #ifdef JP
2013                 msg_format("%sは既に伝説のアイテムです!", o_name  );
2014 #else
2015                 msg_format("The %s %s already %s!", o_name, ((o_ptr->number > 1) ? "are" : "is"), ((o_ptr->number > 1) ? "artifacts" : "an artifact"));
2016 #endif
2017
2018                 okay = FALSE;
2019         }
2020
2021         else if (object_is_ego(o_ptr))
2022         {
2023 #ifdef JP
2024                 msg_format("%sは既に名のあるアイテムです!", o_name );
2025 #else
2026                 msg_format("The %s %s already %s!",
2027                     o_name, ((o_ptr->number > 1) ? "are" : "is"),
2028                     ((o_ptr->number > 1) ? "ego items" : "an ego item"));
2029 #endif
2030
2031                 okay = FALSE;
2032         }
2033
2034         else if (o_ptr->xtra3)
2035         {
2036 #ifdef JP
2037                 msg_format("%sは既に強化されています!", o_name );
2038 #else
2039                 msg_format("The %s %s already %s!", o_name, ((o_ptr->number > 1) ? "are" : "is"),
2040                     ((o_ptr->number > 1) ? "customized items" : "a customized item"));
2041 #endif
2042         }
2043
2044         else
2045         {
2046                 if (o_ptr->number > 1)
2047                 {
2048                         msg_print(_("複数のアイテムに魔法をかけるだけのエネルギーはありません!", "Not enough energy to enchant more than one object!"));
2049 #ifdef JP
2050                         msg_format("%d 個の%sが壊れた!",(o_ptr->number)-1, o_name);
2051 #else
2052                         msg_format("%d of your %s %s destroyed!",(o_ptr->number)-1, o_name, (o_ptr->number>2?"were":"was"));
2053 #endif
2054
2055                         if (item >= 0)
2056                         {
2057                                 inven_item_increase(item, 1 - (o_ptr->number));
2058                         }
2059                         else
2060                         {
2061                                 floor_item_increase(0 - item, 1 - (o_ptr->number));
2062                         }
2063                 }
2064                 okay = create_artifact(o_ptr, TRUE);
2065         }
2066
2067         /* Failure */
2068         if (!okay)
2069         {
2070                 if (flush_failure) flush();
2071                 msg_print(_("強化に失敗した。", "The enchantment failed."));
2072                 if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
2073         }
2074         else
2075         {
2076                 if (record_rand_art)
2077                 {
2078                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2079                         do_cmd_write_nikki(NIKKI_ART_SCROLL, 0, o_name);
2080                 }
2081                 chg_virtue(V_ENCHANT, 1);
2082         }
2083
2084         calc_android_exp();
2085
2086         /* Something happened */
2087         return (TRUE);
2088 }
2089
2090
2091 /*!
2092  * @brief アイテム鑑定処理 /
2093  * Identify an object
2094  * @param o_ptr 鑑定されるアイテムの情報参照ポインタ
2095  * @return 実際に鑑定できたらTRUEを返す
2096  */
2097 bool identify_item(object_type *o_ptr)
2098 {
2099         bool old_known = FALSE;
2100         GAME_TEXT o_name[MAX_NLEN];
2101
2102         object_desc(o_name, o_ptr, 0);
2103
2104         if (o_ptr->ident & IDENT_KNOWN)
2105                 old_known = TRUE;
2106
2107         if (!(o_ptr->ident & (IDENT_MENTAL)))
2108         {
2109                 if (object_is_artifact(o_ptr) || one_in_(5))
2110                         chg_virtue(V_KNOWLEDGE, 1);
2111         }
2112
2113         object_aware(o_ptr);
2114         object_known(o_ptr);
2115         o_ptr->marked |= OM_TOUCHED;
2116
2117         p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
2118         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
2119
2120         strcpy(record_o_name, o_name);
2121         record_turn = current_world_ptr->game_turn;
2122
2123         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2124
2125         if(record_fix_art && !old_known && object_is_fixed_artifact(o_ptr))
2126                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2127         if(record_rand_art && !old_known && o_ptr->art_name)
2128                 do_cmd_write_nikki(NIKKI_ART, 0, o_name);
2129
2130         return old_known;
2131 }
2132
2133 /*!
2134  * @brief アイテム鑑定のメインルーチン処理 /
2135  * Identify an object in the inventory (or on the floor)
2136  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2137  * @return 実際に鑑定を行ったならばTRUEを返す
2138  * @details
2139  * This routine does *not* automatically combine objects.
2140  * Returns TRUE if something was identified, else FALSE.
2141  */
2142 bool ident_spell(bool only_equip)
2143 {
2144         OBJECT_IDX item;
2145         object_type *o_ptr;
2146         GAME_TEXT o_name[MAX_NLEN];
2147         concptr            q, s;
2148         bool old_known;
2149
2150         if (only_equip)
2151                 item_tester_hook = item_tester_hook_identify_weapon_armour;
2152         else
2153                 item_tester_hook = item_tester_hook_identify;
2154
2155         if (can_get_item())
2156         {
2157                 q = _("どのアイテムを鑑定しますか? ", "Identify which item? ");
2158         }
2159         else
2160         {
2161                 if (only_equip)
2162                         item_tester_hook = object_is_weapon_armour_ammo;
2163                 else
2164                         item_tester_hook = NULL;
2165
2166                 q = _("すべて鑑定済みです。 ", "All items are identified. ");
2167         }
2168
2169         s = _("鑑定するべきアイテムがない。", "You have nothing to identify.");
2170
2171         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
2172         if (!o_ptr) return (FALSE);
2173
2174         old_known = identify_item(o_ptr);
2175
2176         object_desc(o_name, o_ptr, 0);
2177         if (item >= INVEN_RARM)
2178         {
2179                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
2180         }
2181         else if (item >= 0)
2182         {
2183                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
2184         }
2185         else
2186         {
2187                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
2188         }
2189
2190         /* Auto-inscription/destroy */
2191         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2192
2193         /* Something happened */
2194         return (TRUE);
2195 }
2196
2197
2198 /*!
2199  * @brief アイテム凡庸化のメインルーチン処理 /
2200  * Identify an object in the inventory (or on the floor)
2201  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2202  * @return 実際に凡庸化をを行ったならばTRUEを返す
2203  * @details
2204  * <pre>
2205  * Mundanify an object in the inventory (or on the floor)
2206  * This routine does *not* automatically combine objects.
2207  * Returns TRUE if something was mundanified, else FALSE.
2208  * </pre>
2209  */
2210 bool mundane_spell(bool only_equip)
2211 {
2212         OBJECT_IDX item;
2213         object_type *o_ptr;
2214         concptr q, s;
2215
2216         if (only_equip) item_tester_hook = object_is_weapon_armour_ammo;
2217
2218         q = _("どれを使いますか?", "Use which item? ");
2219         s = _("使えるものがありません。", "You have nothing you can use.");
2220
2221         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
2222         if (!o_ptr) return (FALSE);
2223
2224         msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
2225         {
2226                 POSITION iy = o_ptr->iy;                 /* Y-position on map, or zero */
2227                 POSITION ix = o_ptr->ix;                 /* X-position on map, or zero */
2228                 OBJECT_IDX next_o_idx = o_ptr->next_o_idx; /* Next object in stack (if any) */
2229                 byte marked = o_ptr->marked;         /* Object is marked */
2230                 WEIGHT weight = o_ptr->number * o_ptr->weight;
2231                 u16b inscription = o_ptr->inscription;
2232
2233                 /* Wipe it clean */
2234                 object_prep(o_ptr, o_ptr->k_idx);
2235
2236                 o_ptr->iy = iy;
2237                 o_ptr->ix = ix;
2238                 o_ptr->next_o_idx = next_o_idx;
2239                 o_ptr->marked = marked;
2240                 o_ptr->inscription = inscription;
2241                 if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
2242         }
2243         calc_android_exp();
2244
2245         /* Something happened */
2246         return TRUE;
2247 }
2248
2249 /*!
2250  * @brief アイテム*鑑定*のメインルーチン処理 /
2251  * Identify an object in the inventory (or on the floor)
2252  * @param only_equip 装備品のみを対象とするならばTRUEを返す
2253  * @return 実際に鑑定を行ったならばTRUEを返す
2254  * @details
2255  * Fully "identify" an object in the inventory  -BEN-
2256  * This routine returns TRUE if an item was identified.
2257  */
2258 bool identify_fully(bool only_equip)
2259 {
2260         OBJECT_IDX item;
2261         object_type *o_ptr;
2262         GAME_TEXT o_name[MAX_NLEN];
2263         concptr q, s;
2264         bool old_known;
2265
2266         if (only_equip)
2267                 item_tester_hook = item_tester_hook_identify_fully_weapon_armour;
2268         else
2269                 item_tester_hook = item_tester_hook_identify_fully;
2270
2271         if (can_get_item())
2272         {
2273                 q = _("どのアイテムを*鑑定*しますか? ", "*Identify* which item? ");
2274         }
2275         else
2276         {
2277                 if (only_equip)
2278                         item_tester_hook = object_is_weapon_armour_ammo;
2279                 else
2280                         item_tester_hook = NULL;
2281
2282                 q = _("すべて*鑑定*済みです。 ", "All items are *identified*. ");
2283         }
2284
2285         s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*.");
2286
2287         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
2288         if (!o_ptr) return (FALSE);
2289
2290         old_known = identify_item(o_ptr);
2291
2292         /* Mark the item as fully known */
2293         o_ptr->ident |= (IDENT_MENTAL);
2294         handle_stuff();
2295
2296         object_desc(o_name, o_ptr, 0);
2297         if (item >= INVEN_RARM)
2298         {
2299                 msg_format(_("%^s: %s(%c)。", "%^s: %s (%c)."), describe_use(item), o_name, index_to_label(item));
2300         }
2301         else if (item >= 0)
2302         {
2303                 msg_format(_("ザック中: %s(%c)。", "In your pack: %s (%c)."), o_name, index_to_label(item));
2304         }
2305         else
2306         {
2307                 msg_format(_("床上: %s。", "On the ground: %s."), o_name);
2308         }
2309
2310         /* Describe it fully */
2311         (void)screen_object(o_ptr, 0L);
2312
2313         /* Auto-inscription/destroy */
2314         autopick_alter_item(item, (bool)(destroy_identify && !old_known));
2315
2316         /* Success */
2317         return (TRUE);
2318 }
2319
2320
2321
2322 /*!
2323  * @brief 魔力充填処理 /
2324  * Recharge a wand/staff/rod from the pack or on the floor.
2325  * This function has been rewritten in Oangband and ZAngband.
2326  * @param power 充填パワー
2327  * @return ターン消費を要する処理まで進んだらTRUEを返す
2328  *
2329  * Sorcery/Arcane -- Recharge  --> recharge(plev * 4)
2330  * Chaos -- Arcane Binding     --> recharge(90)
2331  *
2332  * Scroll of recharging        --> recharge(130)
2333  * Artifact activation/Thingol --> recharge(130)
2334  *
2335  * It is harder to recharge high level, and highly charged wands,
2336  * staffs, and rods.  The more wands in a stack, the more easily and
2337  * strongly they recharge.  Staffs, however, each get fewer charges if
2338  * stacked.
2339  *
2340  * Beware of "sliding index errors".
2341  */
2342 bool recharge(int power)
2343 {
2344         OBJECT_IDX item;
2345         DEPTH lev;
2346         int recharge_strength;
2347         TIME_EFFECT recharge_amount;
2348
2349         object_type *o_ptr;
2350         object_kind *k_ptr;
2351
2352         bool fail = FALSE;
2353         byte fail_type = 1;
2354
2355         concptr q, s;
2356         GAME_TEXT o_name[MAX_NLEN];
2357
2358         /* Only accept legal items */
2359         item_tester_hook = item_tester_hook_recharge;
2360
2361         q = _("どのアイテムに魔力を充填しますか? ", "Recharge which item? ");
2362         s = _("魔力を充填すべきアイテムがない。", "You have nothing to recharge.");
2363
2364         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
2365         if (!o_ptr) return (FALSE);
2366
2367         /* Get the object kind. */
2368         k_ptr = &k_info[o_ptr->k_idx];
2369
2370         /* Extract the object "level" */
2371         lev = k_info[o_ptr->k_idx].level;
2372
2373
2374         /* Recharge a rod */
2375         if (o_ptr->tval == TV_ROD)
2376         {
2377                 /* Extract a recharge strength by comparing object level to power. */
2378                 recharge_strength = ((power > lev / 2) ? (power - lev / 2) : 0) / 5;
2379
2380
2381                 /* Back-fire */
2382                 if (one_in_(recharge_strength))
2383                 {
2384                         /* Activate the failure code. */
2385                         fail = TRUE;
2386                 }
2387
2388                 /* Recharge */
2389                 else
2390                 {
2391                         /* Recharge amount */
2392                         recharge_amount = (power * damroll(3, 2));
2393
2394                         /* Recharge by that amount */
2395                         if (o_ptr->timeout > recharge_amount)
2396                                 o_ptr->timeout -= recharge_amount;
2397                         else
2398                                 o_ptr->timeout = 0;
2399                 }
2400         }
2401
2402
2403         /* Recharge wand/staff */
2404         else
2405         {
2406                 /* Extract a recharge strength by comparing object level to power.
2407                  * Divide up a stack of wands' charges to calculate charge penalty.
2408                  */
2409                 if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
2410                         recharge_strength = (100 + power - lev - (8 * o_ptr->pval / o_ptr->number)) / 15;
2411
2412                 /* All staffs, unstacked wands. */
2413                 else recharge_strength = (100 + power - lev - (8 * o_ptr->pval)) / 15;
2414                 if (recharge_strength < 0) recharge_strength = 0;
2415
2416                 /* Back-fire */
2417                 if (one_in_(recharge_strength))
2418                 {
2419                         /* Activate the failure code. */
2420                         fail = TRUE;
2421                 }
2422
2423                 /* If the spell didn't backfire, recharge the wand or staff. */
2424                 else
2425                 {
2426                         /* Recharge based on the standard number of charges. */
2427                         recharge_amount = randint1(1 + k_ptr->pval / 2);
2428
2429                         /* Multiple wands in a stack increase recharging somewhat. */
2430                         if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
2431                         {
2432                                 recharge_amount +=
2433                                         (randint1(recharge_amount * (o_ptr->number - 1))) / 2;
2434                                 if (recharge_amount < 1) recharge_amount = 1;
2435                                 if (recharge_amount > 12) recharge_amount = 12;
2436                         }
2437
2438                         /* But each staff in a stack gets fewer additional charges,
2439                          * although always at least one.
2440                          */
2441                         if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1))
2442                         {
2443                                 recharge_amount /= (TIME_EFFECT)o_ptr->number;
2444                                 if (recharge_amount < 1) recharge_amount = 1;
2445                         }
2446
2447                         /* Recharge the wand or staff. */
2448                         o_ptr->pval += recharge_amount;
2449
2450
2451                         /* Hack -- we no longer "know" the item */
2452                         o_ptr->ident &= ~(IDENT_KNOWN);
2453
2454                         /* Hack -- we no longer think the item is empty */
2455                         o_ptr->ident &= ~(IDENT_EMPTY);
2456                 }
2457         }
2458
2459
2460         /* Inflict the penalties for failing a recharge. */
2461         if (fail)
2462         {
2463                 /* Artifacts are never destroyed. */
2464                 if (object_is_fixed_artifact(o_ptr))
2465                 {
2466                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
2467                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
2468
2469                         /* Artifact rods. */
2470                         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout < 10000))
2471                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
2472
2473                         /* Artifact wands and staffs. */
2474                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
2475                                 o_ptr->pval = 0;
2476                 }
2477                 else
2478                 {
2479                         /* Get the object description */
2480                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2481
2482                         /*** Determine Seriousness of Failure ***/
2483
2484                         /* Mages recharge objects more safely. */
2485                         if (IS_WIZARD_CLASS() || p_ptr->pclass == CLASS_MAGIC_EATER || p_ptr->pclass == CLASS_BLUE_MAGE)
2486                         {
2487                                 /* 10% chance to blow up one rod, otherwise draining. */
2488                                 if (o_ptr->tval == TV_ROD)
2489                                 {
2490                                         if (one_in_(10)) fail_type = 2;
2491                                         else fail_type = 1;
2492                                 }
2493                                 /* 75% chance to blow up one wand, otherwise draining. */
2494                                 else if (o_ptr->tval == TV_WAND)
2495                                 {
2496                                         if (!one_in_(3)) fail_type = 2;
2497                                         else fail_type = 1;
2498                                 }
2499                                 /* 50% chance to blow up one staff, otherwise no effect. */
2500                                 else if (o_ptr->tval == TV_STAFF)
2501                                 {
2502                                         if (one_in_(2)) fail_type = 2;
2503                                         else fail_type = 0;
2504                                 }
2505                         }
2506
2507                         /* All other classes get no special favors. */
2508                         else
2509                         {
2510                                 /* 33% chance to blow up one rod, otherwise draining. */
2511                                 if (o_ptr->tval == TV_ROD)
2512                                 {
2513                                         if (one_in_(3)) fail_type = 2;
2514                                         else fail_type = 1;
2515                                 }
2516                                 /* 20% chance of the entire stack, else destroy one wand. */
2517                                 else if (o_ptr->tval == TV_WAND)
2518                                 {
2519                                         if (one_in_(5)) fail_type = 3;
2520                                         else fail_type = 2;
2521                                 }
2522                                 /* Blow up one staff. */
2523                                 else if (o_ptr->tval == TV_STAFF)
2524                                 {
2525                                         fail_type = 2;
2526                                 }
2527                         }
2528
2529                         /*** Apply draining and destruction. ***/
2530
2531                         /* Drain object or stack of objects. */
2532                         if (fail_type == 1)
2533                         {
2534                                 if (o_ptr->tval == TV_ROD)
2535                                 {
2536                                         msg_print(_("魔力が逆噴射して、ロッドからさらに魔力を吸い取ってしまった!", "The recharge backfires, draining the rod further!"));
2537
2538                                         if (o_ptr->timeout < 10000)
2539                                                 o_ptr->timeout = (o_ptr->timeout + 100) * 2;
2540                                 }
2541                                 else if (o_ptr->tval == TV_WAND)
2542                                 {
2543                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
2544                                         o_ptr->pval = 0;
2545                                 }
2546                                 /* Staffs aren't drained. */
2547                         }
2548
2549                         /* Destroy an object or one in a stack of objects. */
2550                         if (fail_type == 2)
2551                         {
2552                                 if (o_ptr->number > 1)
2553                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
2554                                 else
2555                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
2556
2557                                 /* Reduce rod stack maximum timeout, drain wands. */
2558                                 if (o_ptr->tval == TV_ROD) o_ptr->timeout = (o_ptr->number - 1) * k_ptr->pval;
2559                                 if (o_ptr->tval == TV_WAND) o_ptr->pval = 0;
2560
2561                                 /* Reduce and describe inventory */
2562                                 if (item >= 0)
2563                                 {
2564                                         inven_item_increase(item, -1);
2565                                         inven_item_describe(item);
2566                                         inven_item_optimize(item);
2567                                 }
2568
2569                                 /* Reduce and describe floor item */
2570                                 else
2571                                 {
2572                                         floor_item_increase(0 - item, -1);
2573                                         floor_item_describe(0 - item);
2574                                         floor_item_optimize(0 - item);
2575                                 }
2576                         }
2577
2578                         /* Destroy all members of a stack of objects. */
2579                         if (fail_type == 3)
2580                         {
2581                                 if (o_ptr->number > 1)
2582                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
2583                                 else
2584                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
2585
2586                                 /* Reduce and describe inventory */
2587                                 if (item >= 0)
2588                                 {
2589                                         inven_item_increase(item, -999);
2590                                         inven_item_describe(item);
2591                                         inven_item_optimize(item);
2592                                 }
2593
2594                                 /* Reduce and describe floor item */
2595                                 else
2596                                 {
2597                                         floor_item_increase(0 - item, -999);
2598                                         floor_item_describe(0 - item);
2599                                         floor_item_optimize(0 - item);
2600                                 }
2601                         }
2602                 }
2603         }
2604         p_ptr->update |= (PU_COMBINE | PU_REORDER);
2605         p_ptr->window |= (PW_INVEN);
2606
2607         /* Something was done */
2608         return (TRUE);
2609 }
2610
2611
2612 /*!
2613  * @brief プレイヤーの全既知呪文を表示する /
2614  * Hack -- Display all known spells in a window
2615  * return なし
2616  * @details
2617  * Need to analyze size of the window.
2618  * Need more color coding.
2619  */
2620 void display_spell_list(void)
2621 {
2622         int i, j;
2623         TERM_LEN y, x;
2624         int m[9];
2625         const magic_type *s_ptr;
2626         GAME_TEXT name[MAX_NLEN];
2627         char out_val[160];
2628
2629         clear_from(0);
2630
2631         /* They have too many spells to list */
2632         if (p_ptr->pclass == CLASS_SORCERER) return;
2633         if (p_ptr->pclass == CLASS_RED_MAGE) return;
2634
2635         if (p_ptr->pclass == CLASS_SNIPER)
2636         {
2637                 display_snipe_list();
2638                 return;
2639         }
2640
2641         /* mind.c type classes */
2642         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
2643             (p_ptr->pclass == CLASS_BERSERKER) ||
2644             (p_ptr->pclass == CLASS_NINJA) ||
2645             (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
2646             (p_ptr->pclass == CLASS_FORCETRAINER))
2647         {
2648                 PERCENTAGE minfail = 0;
2649                 PLAYER_LEVEL plev = p_ptr->lev;
2650                 PERCENTAGE chance = 0;
2651                 mind_type       spell;
2652                 char            comment[80];
2653                 char            psi_desc[80];
2654                 int             use_mind;
2655                 bool use_hp = FALSE;
2656
2657                 y = 1;
2658                 x = 1;
2659
2660                 /* Display a list of spells */
2661                 prt("", y, x);
2662                 put_str(_("名前", "Name"), y, x + 5);
2663                 put_str(_("Lv   MP 失率 効果", "Lv Mana Fail Info"), y, x + 35);
2664
2665                 switch(p_ptr->pclass)
2666                 {
2667                 case CLASS_MINDCRAFTER: use_mind = MIND_MINDCRAFTER;break;
2668                 case CLASS_FORCETRAINER:          use_mind = MIND_KI;break;
2669                 case CLASS_BERSERKER: use_mind = MIND_BERSERKER; use_hp = TRUE; break;
2670                 case CLASS_MIRROR_MASTER: use_mind = MIND_MIRROR_MASTER; break;
2671                 case CLASS_NINJA: use_mind = MIND_NINJUTSU; use_hp = TRUE; break;
2672                 default:                use_mind = 0;break;
2673                 }
2674
2675                 /* Dump the spells */
2676                 for (i = 0; i < MAX_MIND_POWERS; i++)
2677                 {
2678                         byte a = TERM_WHITE;
2679
2680                         /* Access the available spell */
2681                         spell = mind_powers[use_mind].info[i];
2682                         if (spell.min_lev > plev) break;
2683
2684                         /* Get the failure rate */
2685                         chance = spell.fail;
2686
2687                         /* Reduce failure rate by "effective" level adjustment */
2688                         chance -= 3 * (p_ptr->lev - spell.min_lev);
2689
2690                         /* Reduce failure rate by INT/WIS adjustment */
2691                         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
2692
2693                         if (!use_hp)
2694                         {
2695                                 /* Not enough mana to cast */
2696                                 if (spell.mana_cost > p_ptr->csp)
2697                                 {
2698                                         chance += 5 * (spell.mana_cost - p_ptr->csp);
2699                                         a = TERM_ORANGE;
2700                                 }
2701                         }
2702                         else
2703                         {
2704                                 /* Not enough hp to cast */
2705                                 if (spell.mana_cost > p_ptr->chp)
2706                                 {
2707                                         chance += 100;
2708                                         a = TERM_RED;
2709                                 }
2710                         }
2711
2712                         /* Extract the minimum failure rate */
2713                         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
2714
2715                         /* Minimum failure rate */
2716                         if (chance < minfail) chance = minfail;
2717
2718                         /* Stunning makes spells harder */
2719                         if (p_ptr->stun > 50) chance += 25;
2720                         else if (p_ptr->stun) chance += 15;
2721
2722                         /* Always a 5 percent chance of working */
2723                         if (chance > 95) chance = 95;
2724
2725                         /* Get info */
2726                         mindcraft_info(comment, use_mind, i);
2727
2728                         /* Dump the spell */
2729                         sprintf(psi_desc, "  %c) %-30s%2d %4d %3d%%%s",
2730                             I2A(i), spell.name,
2731                             spell.min_lev, spell.mana_cost, chance, comment);
2732
2733                         Term_putstr(x, y + i + 1, -1, a, psi_desc);
2734                 }
2735                 return;
2736         }
2737
2738         /* Cannot read spellbooks */
2739         if (REALM_NONE == p_ptr->realm1) return;
2740
2741         /* Normal spellcaster with books */
2742
2743         /* Scan books */
2744         for (j = 0; j < ((p_ptr->realm2 > REALM_NONE) ? 2 : 1); j++)
2745         {
2746                 int n = 0;
2747
2748                 /* Reset vertical */
2749                 m[j] = 0;
2750
2751                 /* Vertical location */
2752                 y = (j < 3) ? 0 : (m[j - 3] + 2);
2753
2754                 /* Horizontal location */
2755                 x = 27 * (j % 3);
2756
2757                 /* Scan spells */
2758                 for (i = 0; i < 32; i++)
2759                 {
2760                         byte a = TERM_WHITE;
2761
2762                         /* Access the spell */
2763                         if (!is_magic((j < 1) ? p_ptr->realm1 : p_ptr->realm2))
2764                         {
2765                                 s_ptr = &technic_info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - MIN_TECHNIC][i % 32];
2766                         }
2767                         else
2768                         {
2769                                 s_ptr = &mp_ptr->info[((j < 1) ? p_ptr->realm1 : p_ptr->realm2) - 1][i % 32];
2770                         }
2771
2772                         strcpy(name, do_spell((j < 1) ? p_ptr->realm1 : p_ptr->realm2, i % 32, SPELL_NAME));
2773
2774                         /* Illegible */
2775                         if (s_ptr->slevel >= 99)
2776                         {
2777                                 /* Illegible */
2778                                 strcpy(name, _("(判読不能)", "(illegible)"));
2779
2780                                 /* Unusable */
2781                                 a = TERM_L_DARK;
2782                         }
2783
2784                         /* Forgotten */
2785                         else if ((j < 1) ?
2786                                 ((p_ptr->spell_forgotten1 & (1L << i))) :
2787                                 ((p_ptr->spell_forgotten2 & (1L << (i % 32)))))
2788                         {
2789                                 /* Forgotten */
2790                                 a = TERM_ORANGE;
2791                         }
2792
2793                         /* Unknown */
2794                         else if (!((j < 1) ?
2795                                 (p_ptr->spell_learned1 & (1L << i)) :
2796                                 (p_ptr->spell_learned2 & (1L << (i % 32)))))
2797                         {
2798                                 /* Unknown */
2799                                 a = TERM_RED;
2800                         }
2801
2802                         /* Untried */
2803                         else if (!((j < 1) ?
2804                                 (p_ptr->spell_worked1 & (1L << i)) :
2805                                 (p_ptr->spell_worked2 & (1L << (i % 32)))))
2806                         {
2807                                 /* Untried */
2808                                 a = TERM_YELLOW;
2809                         }
2810
2811                         /* Dump the spell --(-- */
2812                         sprintf(out_val, "%c/%c) %-20.20s",
2813                                 I2A(n / 8), I2A(n % 8), name);
2814
2815                         /* Track maximum */
2816                         m[j] = y + n;
2817
2818                         /* Dump onto the window */
2819                         Term_putstr(x, m[j], -1, a, out_val);
2820
2821                         /* Next */
2822                         n++;
2823                 }
2824         }
2825 }
2826
2827
2828 /*!
2829  * @brief 呪文の経験値を返す /
2830  * Returns experience of a spell
2831  * @param spell 呪文ID
2832  * @param use_realm 魔法領域
2833  * @return 経験値
2834  */
2835 EXP experience_of_spell(SPELL_IDX spell, REALM_IDX use_realm)
2836 {
2837         if (p_ptr->pclass == CLASS_SORCERER) return SPELL_EXP_MASTER;
2838         else if (p_ptr->pclass == CLASS_RED_MAGE) return SPELL_EXP_SKILLED;
2839         else if (use_realm == p_ptr->realm1) return p_ptr->spell_exp[spell];
2840         else if (use_realm == p_ptr->realm2) return p_ptr->spell_exp[spell + 32];
2841         else return 0;
2842 }
2843
2844
2845 /*!
2846  * @brief 呪文の消費MPを返す /
2847  * Modify mana consumption rate using spell exp and p_ptr->dec_mana
2848  * @param need_mana 基本消費MP
2849  * @param spell 呪文ID
2850  * @param realm 魔法領域
2851  * @return 消費MP
2852  */
2853 MANA_POINT mod_need_mana(MANA_POINT need_mana, SPELL_IDX spell, REALM_IDX realm)
2854 {
2855 #define MANA_CONST   2400
2856 #define MANA_DIV        4
2857 #define DEC_MANA_DIV    3
2858
2859         /* Realm magic */
2860         if ((realm > REALM_NONE) && (realm <= MAX_REALM))
2861         {
2862                 /*
2863                  * need_mana defaults if spell exp equals SPELL_EXP_EXPERT and !p_ptr->dec_mana.
2864                  * MANA_CONST is used to calculate need_mana effected from spell proficiency.
2865                  */
2866                 need_mana = need_mana * (MANA_CONST + SPELL_EXP_EXPERT - experience_of_spell(spell, realm)) + (MANA_CONST - 1);
2867                 need_mana *= p_ptr->dec_mana ? DEC_MANA_DIV : MANA_DIV;
2868                 need_mana /= MANA_CONST * MANA_DIV;
2869                 if (need_mana < 1) need_mana = 1;
2870         }
2871
2872         /* Non-realm magic */
2873         else
2874         {
2875                 if (p_ptr->dec_mana) need_mana = (need_mana + 1) * DEC_MANA_DIV / MANA_DIV;
2876         }
2877
2878 #undef DEC_MANA_DIV
2879 #undef MANA_DIV
2880 #undef MANA_CONST
2881
2882         return need_mana;
2883 }
2884
2885
2886 /*!
2887  * @brief 呪文の失敗率修正処理1(呪い、消費魔力減少、呪文簡易化) /
2888  * Modify spell fail rate
2889  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
2890  * @param chance 修正前失敗率
2891  * @return 失敗率(%)
2892  * @todo 統合を検討
2893  */
2894 PERCENTAGE mod_spell_chance_1(PERCENTAGE chance)
2895 {
2896         chance += p_ptr->to_m_chance;
2897
2898         if (p_ptr->heavy_spell) chance += 20;
2899
2900         if (p_ptr->dec_mana && p_ptr->easy_spell) chance -= 4;
2901         else if (p_ptr->easy_spell) chance -= 3;
2902         else if (p_ptr->dec_mana) chance -= 2;
2903
2904         return chance;
2905 }
2906
2907
2908 /*!
2909  * @brief 呪文の失敗率修正処理2(消費魔力減少、呪い、負値修正) /
2910  * Modify spell fail rate
2911  * Using p_ptr->to_m_chance, p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
2912  * @param chance 修正前失敗率
2913  * @return 失敗率(%)
2914  * Modify spell fail rate (as "suffix" process)
2915  * Using p_ptr->dec_mana, p_ptr->easy_spell and p_ptr->heavy_spell
2916  * Note: variable "chance" cannot be negative.
2917  * @todo 統合を検討
2918  */
2919 PERCENTAGE mod_spell_chance_2(PERCENTAGE chance)
2920 {
2921         if (p_ptr->dec_mana) chance--;
2922
2923         if (p_ptr->heavy_spell) chance += 5;
2924
2925         return MAX(chance, 0);
2926 }
2927
2928
2929 /*!
2930  * @brief 呪文の失敗率計算メインルーチン /
2931  * Returns spell chance of failure for spell -RAK-
2932  * @param spell 呪文ID
2933  * @param use_realm 魔法領域ID
2934  * @return 失敗率(%)
2935  */
2936 PERCENTAGE spell_chance(SPELL_IDX spell, REALM_IDX use_realm)
2937 {
2938         PERCENTAGE chance, minfail;
2939         const magic_type *s_ptr;
2940         MANA_POINT need_mana;
2941         PERCENTAGE penalty = (mp_ptr->spell_stat == A_WIS) ? 10 : 4;
2942
2943
2944         /* Paranoia -- must be literate */
2945         if (!mp_ptr->spell_book) return (100);
2946
2947         if (use_realm == REALM_HISSATSU) return 0;
2948
2949         /* Access the spell */
2950         if (!is_magic(use_realm))
2951         {
2952                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
2953         }
2954         else
2955         {
2956                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
2957         }
2958
2959         /* Extract the base spell failure rate */
2960         chance = s_ptr->sfail;
2961
2962         /* Reduce failure rate by "effective" level adjustment */
2963         chance -= 3 * (p_ptr->lev - s_ptr->slevel);
2964
2965         /* Reduce failure rate by INT/WIS adjustment */
2966         chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
2967
2968         if (p_ptr->riding)
2969                 chance += (MAX(r_info[current_floor_ptr->m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 100 - 10, 0));
2970
2971         /* Extract mana consumption rate */
2972         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
2973
2974         /* Not enough mana to cast */
2975         if (need_mana > p_ptr->csp)
2976         {
2977                 chance += 5 * (need_mana - p_ptr->csp);
2978         }
2979
2980         if ((use_realm != p_ptr->realm1) && ((p_ptr->pclass == CLASS_MAGE) || (p_ptr->pclass == CLASS_PRIEST))) chance += 5;
2981
2982         /* Extract the minimum failure rate */
2983         minfail = adj_mag_fail[p_ptr->stat_ind[mp_ptr->spell_stat]];
2984
2985         /*
2986          * Non mage/priest characters never get too good
2987          * (added high mage, mindcrafter)
2988          */
2989         if (mp_ptr->spell_xtra & MAGIC_FAIL_5PERCENT)
2990         {
2991                 if (minfail < 5) minfail = 5;
2992         }
2993
2994         /* Hack -- Priest prayer penalty for "edged" weapons  -DGK */
2995         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[0]) chance += 25;
2996         if (((p_ptr->pclass == CLASS_PRIEST) || (p_ptr->pclass == CLASS_SORCERER)) && p_ptr->icky_wield[1]) chance += 25;
2997
2998         chance = mod_spell_chance_1(chance);
2999
3000         /* Goodness or evilness gives a penalty to failure rate */
3001         switch (use_realm)
3002         {
3003         case REALM_NATURE:
3004                 if ((p_ptr->align > 50) || (p_ptr->align < -50)) chance += penalty;
3005                 break;
3006         case REALM_LIFE: case REALM_CRUSADE:
3007                 if (p_ptr->align < -20) chance += penalty;
3008                 break;
3009         case REALM_DEATH: case REALM_DAEMON: case REALM_HEX:
3010                 if (p_ptr->align > 20) chance += penalty;
3011                 break;
3012         }
3013
3014         /* Minimum failure rate */
3015         if (chance < minfail) chance = minfail;
3016
3017         /* Stunning makes spells harder */
3018         if (p_ptr->stun > 50) chance += 25;
3019         else if (p_ptr->stun) chance += 15;
3020
3021         /* Always a 5 percent chance of working */
3022         if (chance > 95) chance = 95;
3023
3024         if ((use_realm == p_ptr->realm1) || (use_realm == p_ptr->realm2)
3025             || (p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
3026         {
3027                 EXP exp = experience_of_spell(spell, use_realm);
3028                 if (exp >= SPELL_EXP_EXPERT) chance--;
3029                 if (exp >= SPELL_EXP_MASTER) chance--;
3030         }
3031
3032         /* Return the chance */
3033         return mod_spell_chance_2(chance);
3034 }
3035
3036
3037
3038 /*!
3039  * @brief 呪文情報の表示処理 /
3040  * Print a list of spells (for browsing or casting or viewing)
3041  * @param target_spell 呪文ID             
3042  * @param spells 表示するスペルID配列の参照ポインタ
3043  * @param num 表示するスペルの数(spellsの要素数)
3044  * @param y 表示メッセージ左上Y座標
3045  * @param x 表示メッセージ左上X座標
3046  * @param use_realm 魔法領域ID
3047  * @return なし
3048  */
3049 void print_spells(SPELL_IDX target_spell, SPELL_IDX *spells, int num, TERM_LEN y, TERM_LEN x, REALM_IDX use_realm)
3050 {
3051         int i;
3052         SPELL_IDX spell;
3053         int  exp_level, increment = 64;
3054         const magic_type *s_ptr;
3055         concptr comment;
3056         char info[80];
3057         char out_val[160];
3058         byte line_attr;
3059         MANA_POINT need_mana;
3060         char ryakuji[5];
3061         char buf[256];
3062         bool max = FALSE;
3063
3064         if (((use_realm <= REALM_NONE) || (use_realm > MAX_REALM)) && p_ptr->wizard)
3065         msg_print(_("警告! print_spell が領域なしに呼ばれた", "Warning! print_spells called with null realm"));
3066
3067         /* Title the list */
3068         prt("", y, x);
3069         if (use_realm == REALM_HISSATSU)
3070                 strcpy(buf,_("  Lv   MP", "  Lv   SP"));
3071         else
3072                 strcpy(buf,_("熟練度 Lv   MP 失率 効果", "Profic Lv   SP Fail Effect"));
3073
3074         put_str(_("名前", "Name"), y, x + 5);
3075         put_str(buf, y, x + 29);
3076
3077         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) increment = 0;
3078         else if (use_realm == p_ptr->realm1) increment = 0;
3079         else if (use_realm == p_ptr->realm2) increment = 32;
3080
3081         /* Dump the spells */
3082         for (i = 0; i < num; i++)
3083         {
3084                 spell = spells[i];
3085
3086                 if (!is_magic(use_realm))
3087                 {
3088                         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
3089                 }
3090                 else
3091                 {
3092                         s_ptr = &mp_ptr->info[use_realm - 1][spell];
3093                 }
3094
3095                 if (use_realm == REALM_HISSATSU)
3096                         need_mana = s_ptr->smana;
3097                 else
3098                 {
3099                         EXP exp = experience_of_spell(spell, use_realm);
3100
3101                         /* Extract mana consumption rate */
3102                         need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
3103
3104                         if ((increment == 64) || (s_ptr->slevel >= 99)) exp_level = EXP_LEVEL_UNSKILLED;
3105                         else exp_level = spell_exp_level(exp);
3106
3107                         max = FALSE;
3108                         if (!increment && (exp_level == EXP_LEVEL_MASTER)) max = TRUE;
3109                         else if ((increment == 32) && (exp_level >= EXP_LEVEL_EXPERT)) max = TRUE;
3110                         else if (s_ptr->slevel >= 99) max = TRUE;
3111                         else if ((p_ptr->pclass == CLASS_RED_MAGE) && (exp_level >= EXP_LEVEL_SKILLED)) max = TRUE;
3112
3113                         strncpy(ryakuji, exp_level_str[exp_level], 4);
3114                         ryakuji[3] = ']';
3115                         ryakuji[4] = '\0';
3116                 }
3117
3118                 if (use_menu && target_spell)
3119                 {
3120                         if (i == (target_spell-1))
3121                                 strcpy(out_val, _("  》 ", "  >  "));
3122                         else
3123                                 strcpy(out_val, "     ");
3124                 }
3125                 else sprintf(out_val, "  %c) ", I2A(i));
3126                 /* Skip illegible spells */
3127                 if (s_ptr->slevel >= 99)
3128                 {
3129                         strcat(out_val, format("%-30s", _("(判読不能)", "(illegible)")));
3130                         c_prt(TERM_L_DARK, out_val, y + i + 1, x);
3131                         continue;
3132                 }
3133
3134                 /* XXX XXX Could label spells above the players level */
3135
3136                 /* Get extra info */
3137                 strcpy(info, do_spell(use_realm, spell, SPELL_INFO));
3138
3139                 /* Use that info */
3140                 comment = info;
3141
3142                 /* Assume spell is known and tried */
3143                 line_attr = TERM_WHITE;
3144
3145                 /* Analyze the spell */
3146                 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
3147                 {
3148                         if (s_ptr->slevel > p_ptr->max_plv)
3149                         {
3150                                 comment = _("未知", "unknown");
3151                                 line_attr = TERM_L_BLUE;
3152                         }
3153                         else if (s_ptr->slevel > p_ptr->lev)
3154                         {
3155                                 comment = _("忘却", "forgotten");
3156                                 line_attr = TERM_YELLOW;
3157                         }
3158                 }
3159                 else if ((use_realm != p_ptr->realm1) && (use_realm != p_ptr->realm2))
3160                 {
3161                         comment = _("未知", "unknown");
3162                         line_attr = TERM_L_BLUE;
3163                 }
3164                 else if ((use_realm == p_ptr->realm1) ?
3165                     ((p_ptr->spell_forgotten1 & (1L << spell))) :
3166                     ((p_ptr->spell_forgotten2 & (1L << spell))))
3167                 {
3168                         comment = _("忘却", "forgotten");
3169                         line_attr = TERM_YELLOW;
3170                 }
3171                 else if (!((use_realm == p_ptr->realm1) ?
3172                     (p_ptr->spell_learned1 & (1L << spell)) :
3173                     (p_ptr->spell_learned2 & (1L << spell))))
3174                 {
3175                         comment = _("未知", "unknown");
3176                         line_attr = TERM_L_BLUE;
3177                 }
3178                 else if (!((use_realm == p_ptr->realm1) ?
3179                     (p_ptr->spell_worked1 & (1L << spell)) :
3180                     (p_ptr->spell_worked2 & (1L << spell))))
3181                 {
3182                         comment = _("未経験", "untried");
3183                         line_attr = TERM_L_GREEN;
3184                 }
3185
3186                 /* Dump the spell --(-- */
3187                 if (use_realm == REALM_HISSATSU)
3188                 {
3189                         strcat(out_val, format("%-25s %2d %4d",
3190                             do_spell(use_realm, spell, SPELL_NAME), /* realm, spell */
3191                             s_ptr->slevel, need_mana));
3192                 }
3193                 else
3194                 {
3195                         strcat(out_val, format("%-25s%c%-4s %2d %4d %3d%% %s",
3196                             do_spell(use_realm, spell, SPELL_NAME), /* realm, spell */
3197                             (max ? '!' : ' '), ryakuji,
3198                             s_ptr->slevel, need_mana, spell_chance(spell, use_realm), comment));
3199                 }
3200                 c_prt(line_attr, out_val, y + i + 1, x);
3201         }
3202
3203         /* Clear the bottom line */
3204         prt("", y + i + 1, x);
3205 }
3206
3207 /*!
3208  * @brief 変身処理向けにモンスターの近隣レベル帯モンスターを返す /
3209  * Helper function -- return a "nearby" race for polymorphing
3210  * @param r_idx 基準となるモンスター種族ID
3211  * @return 変更先のモンスター種族ID
3212  * @details
3213  * Note that this function is one of the more "dangerous" ones...
3214  */
3215 static MONRACE_IDX poly_r_idx(MONRACE_IDX r_idx)
3216 {
3217         monster_race *r_ptr = &r_info[r_idx];
3218
3219         int i;
3220         MONRACE_IDX r;
3221         DEPTH lev1, lev2;
3222
3223         /* Hack -- Uniques/Questors never polymorph */
3224         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags1 & RF1_QUESTOR))
3225                 return (r_idx);
3226
3227         /* Allowable range of "levels" for resulting monster */
3228         lev1 = r_ptr->level - ((randint1(20) / randint1(9)) + 1);
3229         lev2 = r_ptr->level + ((randint1(20) / randint1(9)) + 1);
3230
3231         /* Pick a (possibly new) non-unique race */
3232         for (i = 0; i < 1000; i++)
3233         {
3234                 /* Pick a new race, using a level calculation */
3235                 r = get_mon_num((current_floor_ptr->dun_level + r_ptr->level) / 2 + 5);
3236
3237                 /* Handle failure */
3238                 if (!r) break;
3239
3240                 /* Obtain race */
3241                 r_ptr = &r_info[r];
3242
3243                 /* Ignore unique monsters */
3244                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3245
3246                 /* Ignore monsters with incompatible levels */
3247                 if ((r_ptr->level < lev1) || (r_ptr->level > lev2)) continue;
3248
3249                 /* Use that index */
3250                 r_idx = r;
3251
3252                 break;
3253         }
3254         return (r_idx);
3255 }
3256
3257 /*!
3258  * @brief 指定座標にいるモンスターを変身させる /
3259  * Helper function -- return a "nearby" race for polymorphing
3260  * @param y 指定のY座標
3261  * @param x 指定のX座標
3262  * @return 実際に変身したらTRUEを返す
3263  */
3264 bool polymorph_monster(POSITION y, POSITION x)
3265 {
3266         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
3267         monster_type *m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
3268         bool polymorphed = FALSE;
3269         MONRACE_IDX new_r_idx;
3270         MONRACE_IDX old_r_idx = m_ptr->r_idx;
3271         bool targeted = (target_who == g_ptr->m_idx) ? TRUE : FALSE;
3272         bool health_tracked = (p_ptr->health_who == g_ptr->m_idx) ? TRUE : FALSE;
3273         monster_type back_m;
3274
3275         if (p_ptr->inside_arena || p_ptr->inside_battle) return (FALSE);
3276
3277         if ((p_ptr->riding == g_ptr->m_idx) || (m_ptr->mflag2 & MFLAG2_KAGE)) return (FALSE);
3278
3279         /* Memorize the monster before polymorphing */
3280         back_m = *m_ptr;
3281
3282         /* Pick a "new" monster race */
3283         new_r_idx = poly_r_idx(old_r_idx);
3284
3285         /* Handle polymorph */
3286         if (new_r_idx != old_r_idx)
3287         {
3288                 BIT_FLAGS mode = 0L;
3289                 bool preserve_hold_objects = back_m.hold_o_idx ? TRUE : FALSE;
3290                 OBJECT_IDX this_o_idx, next_o_idx = 0;
3291
3292                 /* Get the monsters attitude */
3293                 if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
3294                 if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
3295                 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
3296
3297                 /* Mega-hack -- ignore held objects */
3298                 m_ptr->hold_o_idx = 0;
3299
3300                 /* "Kill" the "old" monster */
3301                 delete_monster_idx(g_ptr->m_idx);
3302
3303                 /* Create a new monster (no groups) */
3304                 if (place_monster_aux(0, y, x, new_r_idx, mode))
3305                 {
3306                         current_floor_ptr->m_list[hack_m_idx_ii].nickname = back_m.nickname;
3307                         current_floor_ptr->m_list[hack_m_idx_ii].parent_m_idx = back_m.parent_m_idx;
3308                         current_floor_ptr->m_list[hack_m_idx_ii].hold_o_idx = back_m.hold_o_idx;
3309
3310                         /* Success */
3311                         polymorphed = TRUE;
3312                 }
3313                 else
3314                 {
3315                         /* Placing the new monster failed */
3316                         if (place_monster_aux(0, y, x, old_r_idx, (mode | PM_NO_KAGE | PM_IGNORE_TERRAIN)))
3317                         {
3318                                 current_floor_ptr->m_list[hack_m_idx_ii] = back_m;
3319
3320                                 /* Re-initialize monster process */
3321                                 mproc_init();
3322                         }
3323                         else preserve_hold_objects = FALSE;
3324                 }
3325
3326                 /* Mega-hack -- preserve held objects */
3327                 if (preserve_hold_objects)
3328                 {
3329                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3330                         {
3331                                 object_type *o_ptr = &current_floor_ptr->o_list[this_o_idx];
3332                                 next_o_idx = o_ptr->next_o_idx;
3333
3334                                 /* Held by new monster */
3335                                 o_ptr->held_m_idx = hack_m_idx_ii;
3336                         }
3337                 }
3338                 else if (back_m.hold_o_idx) /* Failed (paranoia) */
3339                 {
3340                         for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3341                         {
3342                                 next_o_idx = current_floor_ptr->o_list[this_o_idx].next_o_idx;
3343                                 delete_object_idx(this_o_idx);
3344                         }
3345                 }
3346
3347                 if (targeted) target_who = hack_m_idx_ii;
3348                 if (health_tracked) health_track(hack_m_idx_ii);
3349         }
3350
3351         return polymorphed;
3352 }
3353
3354 /*!
3355  * @brief 次元の扉処理 /
3356  * Dimension Door
3357  * @param x テレポート先のX座標
3358  * @param y テレポート先のY座標
3359  * @return 目標に指定通りテレポートできたならばTRUEを返す
3360  */
3361 static bool dimension_door_aux(DEPTH x, DEPTH y)
3362 {
3363         PLAYER_LEVEL plev = p_ptr->lev;
3364
3365         p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
3366
3367         if (!cave_player_teleportable_bold(y, x, 0L) ||
3368             (distance(y, x, p_ptr->y, p_ptr->x) > plev / 2 + 10) ||
3369             (!randint0(plev / 10 + 10)))
3370         {
3371                 p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
3372                 teleport_player((plev + 2) * 2, TELEPORT_PASSIVE);
3373
3374                 /* Failed */
3375                 return FALSE;
3376         }
3377         else
3378         {
3379                 teleport_player_to(y, x, 0L);
3380
3381                 /* Success */
3382                 return TRUE;
3383         }
3384 }
3385
3386
3387 /*!
3388  * @brief 次元の扉処理のメインルーチン /
3389  * Dimension Door
3390  * @return ターンを消費した場合TRUEを返す
3391  */
3392 bool dimension_door(void)
3393 {
3394         DEPTH x = 0, y = 0;
3395
3396         /* Rerutn FALSE if cancelled */
3397         if (!tgt_pt(&x, &y)) return FALSE;
3398
3399         if (dimension_door_aux(x, y)) return TRUE;
3400
3401         msg_print(_("精霊界から物質界に戻る時うまくいかなかった!", "You fail to exit the astral plane correctly!"));
3402
3403         return TRUE;
3404 }
3405
3406
3407 /*!
3408  * @brief 鏡抜け処理のメインルーチン /
3409  * Mirror Master's Dimension Door
3410  * @return ターンを消費した場合TRUEを返す
3411  */
3412 bool mirror_tunnel(void)
3413 {
3414         POSITION x = 0, y = 0;
3415
3416         /* Rerutn FALSE if cancelled */
3417         if (!tgt_pt(&x, &y)) return FALSE;
3418
3419         if (dimension_door_aux(x, y)) return TRUE;
3420
3421         msg_print(_("鏡の世界をうまく通れなかった!", "You fail to pass the mirror plane correctly!"));
3422
3423         return TRUE;
3424 }
3425
3426 /*!
3427  * @brief 魔力食い処理
3428  * @param power 基本効力
3429  * @return ターンを消費した場合TRUEを返す
3430  */
3431 bool eat_magic(int power)
3432 {
3433         object_type *o_ptr;
3434         object_kind *k_ptr;
3435         DEPTH lev;
3436         OBJECT_IDX item;
3437         int recharge_strength = 0;
3438
3439         bool fail = FALSE;
3440         byte fail_type = 1;
3441
3442         concptr q, s;
3443         GAME_TEXT o_name[MAX_NLEN];
3444
3445         item_tester_hook = item_tester_hook_recharge;
3446
3447         q = _("どのアイテムから魔力を吸収しますか?", "Drain which item? ");
3448         s = _("魔力を吸収できるアイテムがありません。", "You have nothing to drain.");
3449
3450         o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
3451         if (!o_ptr) return FALSE;
3452
3453         k_ptr = &k_info[o_ptr->k_idx];
3454         lev = k_info[o_ptr->k_idx].level;
3455
3456         if (o_ptr->tval == TV_ROD)
3457         {
3458                 recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
3459
3460                 /* Back-fire */
3461                 if (one_in_(recharge_strength))
3462                 {
3463                         /* Activate the failure code. */
3464                         fail = TRUE;
3465                 }
3466                 else
3467                 {
3468                         if (o_ptr->timeout > (o_ptr->number - 1) * k_ptr->pval)
3469                         {
3470                                 msg_print(_("充填中のロッドから魔力を吸収することはできません。", "You can't absorb energy from a discharged rod."));
3471                         }
3472                         else
3473                         {
3474                                 p_ptr->csp += lev;
3475                                 o_ptr->timeout += k_ptr->pval;
3476                         }
3477                 }
3478         }
3479         else
3480         {
3481                 /* All staffs, wands. */
3482                 recharge_strength = (100 + power - lev) / 15;
3483                 if (recharge_strength < 0) recharge_strength = 0;
3484
3485                 /* Back-fire */
3486                 if (one_in_(recharge_strength))
3487                 {
3488                         /* Activate the failure code. */
3489                         fail = TRUE;
3490                 }
3491                 else
3492                 {
3493                         if (o_ptr->pval > 0)
3494                         {
3495                                 p_ptr->csp += lev / 2;
3496                                 o_ptr->pval --;
3497
3498                                 /* XXX Hack -- unstack if necessary */
3499                                 if ((o_ptr->tval == TV_STAFF) && (item >= 0) && (o_ptr->number > 1))
3500                                 {
3501                                         object_type forge;
3502                                         object_type *q_ptr;
3503                                         q_ptr = &forge;
3504
3505                                         /* Obtain a local object */
3506                                         object_copy(q_ptr, o_ptr);
3507
3508                                         /* Modify quantity */
3509                                         q_ptr->number = 1;
3510
3511                                         /* Restore the charges */
3512                                         o_ptr->pval++;
3513
3514                                         /* Unstack the used item */
3515                                         o_ptr->number--;
3516                                         p_ptr->total_weight -= q_ptr->weight;
3517                                         item = inven_carry(q_ptr);
3518
3519                                         msg_print(_("杖をまとめなおした。", "You unstack your staff."));
3520                                 }
3521                         }
3522                         else
3523                         {
3524                                 msg_print(_("吸収できる魔力がありません!", "There's no energy there to absorb!"));
3525                         }
3526                         if (!o_ptr->pval) o_ptr->ident |= IDENT_EMPTY;
3527                 }
3528         }
3529
3530         /* Inflict the penalties for failing a recharge. */
3531         if (fail)
3532         {
3533                 /* Artifacts are never destroyed. */
3534                 if (object_is_fixed_artifact(o_ptr))
3535                 {
3536                         object_desc(o_name, o_ptr, OD_NAME_ONLY);
3537                         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
3538
3539                         /* Artifact rods. */
3540                         if (o_ptr->tval == TV_ROD)
3541                                 o_ptr->timeout = k_ptr->pval * o_ptr->number;
3542
3543                         /* Artifact wands and staffs. */
3544                         else if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))
3545                                 o_ptr->pval = 0;
3546                 }
3547                 else
3548                 {
3549                         /* Get the object description */
3550                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3551
3552                         /*** Determine Seriousness of Failure ***/
3553
3554                         /* Mages recharge objects more safely. */
3555                         if (IS_WIZARD_CLASS())
3556                         {
3557                                 /* 10% chance to blow up one rod, otherwise draining. */
3558                                 if (o_ptr->tval == TV_ROD)
3559                                 {
3560                                         if (one_in_(10)) fail_type = 2;
3561                                         else fail_type = 1;
3562                                 }
3563                                 /* 75% chance to blow up one wand, otherwise draining. */
3564                                 else if (o_ptr->tval == TV_WAND)
3565                                 {
3566                                         if (!one_in_(3)) fail_type = 2;
3567                                         else fail_type = 1;
3568                                 }
3569                                 /* 50% chance to blow up one staff, otherwise no effect. */
3570                                 else if (o_ptr->tval == TV_STAFF)
3571                                 {
3572                                         if (one_in_(2)) fail_type = 2;
3573                                         else fail_type = 0;
3574                                 }
3575                         }
3576
3577                         /* All other classes get no special favors. */
3578                         else
3579                         {
3580                                 /* 33% chance to blow up one rod, otherwise draining. */
3581                                 if (o_ptr->tval == TV_ROD)
3582                                 {
3583                                         if (one_in_(3)) fail_type = 2;
3584                                         else fail_type = 1;
3585                                 }
3586                                 /* 20% chance of the entire stack, else destroy one wand. */
3587                                 else if (o_ptr->tval == TV_WAND)
3588                                 {
3589                                         if (one_in_(5)) fail_type = 3;
3590                                         else fail_type = 2;
3591                                 }
3592                                 /* Blow up one staff. */
3593                                 else if (o_ptr->tval == TV_STAFF)
3594                                 {
3595                                         fail_type = 2;
3596                                 }
3597                         }
3598
3599                         /*** Apply draining and destruction. ***/
3600
3601                         /* Drain object or stack of objects. */
3602                         if (fail_type == 1)
3603                         {
3604                                 if (o_ptr->tval == TV_ROD)
3605                                 {
3606                                         msg_format(_("ロッドは破損を免れたが、魔力は全て失なわれた。",
3607                                                                  "You save your rod from destruction, but all charges are lost."), o_name);
3608                                         o_ptr->timeout = k_ptr->pval * o_ptr->number;
3609                                 }
3610                                 else if (o_ptr->tval == TV_WAND)
3611                                 {
3612                                         msg_format(_("%sは破損を免れたが、魔力が全て失われた。", "You save your %s from destruction, but all charges are lost."), o_name);
3613                                         o_ptr->pval = 0;
3614                                 }
3615                                 /* Staffs aren't drained. */
3616                         }
3617
3618                         /* Destroy an object or one in a stack of objects. */
3619                         if (fail_type == 2)
3620                         {
3621                                 if (o_ptr->number > 1)
3622                                 {
3623                                         msg_format(_("乱暴な魔法のために%sが一本壊れた!", "Wild magic consumes one of your %s!"), o_name);
3624                                         /* Reduce rod stack maximum timeout, drain wands. */
3625                                         if (o_ptr->tval == TV_ROD) o_ptr->timeout = MIN(o_ptr->timeout, k_ptr->pval * (o_ptr->number - 1));
3626                                         else if (o_ptr->tval == TV_WAND) o_ptr->pval = o_ptr->pval * (o_ptr->number - 1) / o_ptr->number;
3627                                 }
3628                                 else
3629                                 {
3630                                         msg_format(_("乱暴な魔法のために%sが何本か壊れた!", "Wild magic consumes your %s!"), o_name);
3631                                 }
3632                                 
3633                                 /* Reduce and describe inventory */
3634                                 if (item >= 0)
3635                                 {
3636                                         inven_item_increase(item, -1);
3637                                         inven_item_describe(item);
3638                                         inven_item_optimize(item);
3639                                 }
3640
3641                                 /* Reduce and describe floor item */
3642                                 else
3643                                 {
3644                                         floor_item_increase(0 - item, -1);
3645                                         floor_item_describe(0 - item);
3646                                         floor_item_optimize(0 - item);
3647                                 }
3648                         }
3649
3650                         /* Destroy all members of a stack of objects. */
3651                         if (fail_type == 3)
3652                         {
3653                                 if (o_ptr->number > 1)
3654                                         msg_format(_("乱暴な魔法のために%sが全て壊れた!", "Wild magic consumes all your %s!"), o_name);
3655                                 else
3656                                         msg_format(_("乱暴な魔法のために%sが壊れた!", "Wild magic consumes your %s!"), o_name);
3657
3658                                 /* Reduce and describe inventory */
3659                                 if (item >= 0)
3660                                 {
3661                                         inven_item_increase(item, -999);
3662                                         inven_item_describe(item);
3663                                         inven_item_optimize(item);
3664                                 }
3665
3666                                 /* Reduce and describe floor item */
3667                                 else
3668                                 {
3669                                         floor_item_increase(0 - item, -999);
3670                                         floor_item_describe(0 - item);
3671                                         floor_item_optimize(0 - item);
3672                                 }
3673                         }
3674                 }
3675         }
3676
3677         if (p_ptr->csp > p_ptr->msp)
3678         {
3679                 p_ptr->csp = p_ptr->msp;
3680         }
3681
3682         p_ptr->redraw |= (PR_MANA);
3683         p_ptr->update |= (PU_COMBINE | PU_REORDER);
3684         p_ptr->window |= (PW_INVEN);
3685
3686         return TRUE;
3687 }
3688
3689
3690 /*!
3691  * @brief 皆殺し(全方向攻撃)処理
3692  * @param py プレイヤーY座標
3693  * @param px プレイヤーX座標
3694  * @return なし
3695  */
3696 void massacre(void)
3697 {
3698         POSITION x, y;
3699         grid_type *g_ptr;
3700         monster_type *m_ptr;
3701         DIRECTION dir;
3702
3703         for (dir = 0; dir < 8; dir++)
3704         {
3705                 y = p_ptr->y + ddy_ddd[dir];
3706                 x = p_ptr->x + ddx_ddd[dir];
3707                 g_ptr = &current_floor_ptr->grid_array[y][x];
3708                 m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
3709
3710                 /* Hack -- attack monsters */
3711                 if (g_ptr->m_idx && (m_ptr->ml || cave_have_flag_bold(y, x, FF_PROJECT)))
3712                         py_attack(y, x, 0);
3713         }
3714 }
3715
3716 bool eat_lock(void)
3717 {
3718         POSITION x, y;
3719         grid_type *g_ptr;
3720         feature_type *f_ptr, *mimic_f_ptr;
3721         DIRECTION dir;
3722
3723         if (!get_direction(&dir, FALSE, FALSE)) return FALSE;
3724         y = p_ptr->y + ddy[dir];
3725         x = p_ptr->x + ddx[dir];
3726         g_ptr = &current_floor_ptr->grid_array[y][x];
3727         f_ptr = &f_info[g_ptr->feat];
3728         mimic_f_ptr = &f_info[get_feat_mimic(g_ptr)];
3729
3730         stop_mouth();
3731
3732         if (!have_flag(mimic_f_ptr->flags, FF_HURT_ROCK))
3733         {
3734                 msg_print(_("この地形は食べられない。", "You cannot eat this feature."));
3735         }
3736         else if (have_flag(f_ptr->flags, FF_PERMANENT))
3737         {
3738                 msg_format(_("いてっ!この%sはあなたの歯より硬い!", "Ouch!  This %s is harder than your teeth!"), f_name + mimic_f_ptr->name);
3739         }
3740         else if (g_ptr->m_idx)
3741         {
3742                 monster_type *m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
3743                 msg_print(_("何かが邪魔しています!", "There's something in the way!"));
3744
3745                 if (!m_ptr->ml || !is_pet(m_ptr)) py_attack(y, x, 0);
3746         }
3747         else if (have_flag(f_ptr->flags, FF_TREE))
3748         {
3749                 msg_print(_("木の味は好きじゃない!", "You don't like the woody taste!"));
3750         }
3751         else if (have_flag(f_ptr->flags, FF_GLASS))
3752         {
3753                 msg_print(_("ガラスの味は好きじゃない!", "You don't like the glassy taste!"));
3754         }
3755         else if (have_flag(f_ptr->flags, FF_DOOR) || have_flag(f_ptr->flags, FF_CAN_DIG))
3756         {
3757                 (void)set_food(p_ptr->food + 3000);
3758         }
3759         else if (have_flag(f_ptr->flags, FF_MAY_HAVE_GOLD) || have_flag(f_ptr->flags, FF_HAS_GOLD))
3760         {
3761                 (void)set_food(p_ptr->food + 5000);
3762         }
3763         else
3764         {
3765                 msg_format(_("この%sはとてもおいしい!", "This %s is very filling!"), f_name + mimic_f_ptr->name);
3766                 (void)set_food(p_ptr->food + 10000);
3767         }
3768
3769         /* Destroy the wall */
3770         cave_alter_feat(y, x, FF_HURT_ROCK);
3771
3772         (void)move_player_effect(y, x, MPE_DONT_PICKUP);
3773         return TRUE;
3774 }
3775
3776
3777 bool shock_power(void)
3778 {
3779         DIRECTION dir;
3780         POSITION y, x;
3781         HIT_POINT dam;
3782         PLAYER_LEVEL plev = p_ptr->lev;
3783         int boost = P_PTR_KI;
3784         if (heavy_armor()) boost /= 2;
3785
3786         project_length = 1;
3787         if (!get_aim_dir(&dir)) return FALSE;
3788
3789         y = p_ptr->y + ddy[dir];
3790         x = p_ptr->x + ddx[dir];
3791         dam = damroll(8 + ((plev - 5) / 4) + boost / 12, 8);
3792         fire_beam(GF_MISSILE, dir, dam);
3793         if (current_floor_ptr->grid_array[y][x].m_idx)
3794         {
3795                 int i;
3796                 POSITION ty = y, tx = x;
3797                 POSITION oy = y, ox = x;
3798                 MONSTER_IDX m_idx = current_floor_ptr->grid_array[y][x].m_idx;
3799                 monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
3800                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3801                 GAME_TEXT m_name[MAX_NLEN];
3802
3803                 monster_desc(m_name, m_ptr, 0);
3804
3805                 if (randint1(r_ptr->level * 3 / 2) > randint0(dam / 2) + dam / 2)
3806                 {
3807                         msg_format(_("%sは飛ばされなかった。", "%^s was not blown away."), m_name);
3808                 }
3809                 else
3810                 {
3811                         for (i = 0; i < 5; i++)
3812                         {
3813                                 y += ddy[dir];
3814                                 x += ddx[dir];
3815                                 if (cave_empty_bold(y, x))
3816                                 {
3817                                         ty = y;
3818                                         tx = x;
3819                                 }
3820                                 else break;
3821                         }
3822                         if ((ty != oy) || (tx != ox))
3823                         {
3824                                 msg_format(_("%sを吹き飛ばした!", "You blow %s away!"), m_name);
3825                                 current_floor_ptr->grid_array[oy][ox].m_idx = 0;
3826                                 current_floor_ptr->grid_array[ty][tx].m_idx = m_idx;
3827                                 m_ptr->fy = ty;
3828                                 m_ptr->fx = tx;
3829
3830                                 update_monster(m_idx, TRUE);
3831                                 lite_spot(oy, ox);
3832                                 lite_spot(ty, tx);
3833
3834                                 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
3835                                         p_ptr->update |= (PU_MON_LITE);
3836                         }
3837                 }
3838         }
3839         return TRUE;
3840 }
3841
3842 bool booze(player_type *creature_ptr)
3843 {
3844         bool ident = FALSE;
3845         if (creature_ptr->pclass != CLASS_MONK) chg_virtue(V_HARMONY, -1);
3846         else if (!creature_ptr->resist_conf) creature_ptr->special_attack |= ATTACK_SUIKEN;
3847         if (!creature_ptr->resist_conf)
3848         {
3849                 if (set_confused(randint0(20) + 15))
3850                 {
3851                         ident = TRUE;
3852                 }
3853         }
3854
3855         if (!creature_ptr->resist_chaos)
3856         {
3857                 if (one_in_(2))
3858                 {
3859                         if (set_image(creature_ptr->image + randint0(150) + 150))
3860                         {
3861                                 ident = TRUE;
3862                         }
3863                 }
3864                 if (one_in_(13) && (creature_ptr->pclass != CLASS_MONK))
3865                 {
3866                         ident = TRUE;
3867                         if (one_in_(3)) lose_all_info();
3868                         else wiz_dark();
3869                         (void)teleport_player_aux(100, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
3870                         wiz_dark();
3871                         msg_print(_("知らない場所で目が醒めた。頭痛がする。", "You wake up somewhere with a sore head..."));
3872                         msg_print(_("何も思い出せない。どうやってここへ来たのかも分からない!", "You can't remember a thing, or how you got here!"));
3873                 }
3874         }
3875         return ident;
3876 }
3877
3878 bool detonation(player_type *creature_ptr)
3879 {
3880         msg_print(_("体の中で激しい爆発が起きた!", "Massive explosions rupture your body!"));
3881         take_hit(DAMAGE_NOESCAPE, damroll(50, 20), _("爆発の薬", "a potion of Detonation"), -1);
3882         (void)set_stun(creature_ptr->stun + 75);
3883         (void)set_cut(creature_ptr->cut + 5000);
3884         return TRUE;
3885 }
3886
3887 void blood_curse_to_enemy(MONSTER_IDX m_idx)
3888 {
3889         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
3890         grid_type *g_ptr = &current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
3891         BIT_FLAGS curse_flg = (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP);
3892         int count = 0;
3893         do
3894         {
3895                 switch (randint1(28))
3896                 {
3897                 case 1: case 2:
3898                         if (!count)
3899                         {
3900                                 msg_print(_("地面が揺れた...", "The ground trembles..."));
3901                                 earthquake(m_ptr->fy, m_ptr->fx, 4 + randint0(4));
3902                                 if (!one_in_(6)) break;
3903                         }
3904                 case 3: case 4: case 5: case 6:
3905                         if (!count)
3906                         {
3907                                 int extra_dam = damroll(10, 10);
3908                                 msg_print(_("純粋な魔力の次元への扉が開いた!", "A portal opens to a plane of raw mana!"));
3909
3910                                 project(0, 8, m_ptr->fy, m_ptr->fx, extra_dam, GF_MANA, curse_flg, -1);
3911                                 if (!one_in_(6)) break;
3912                         }
3913                 case 7: case 8:
3914                         if (!count)
3915                         {
3916                                 msg_print(_("空間が歪んだ!", "Space warps about you!"));
3917
3918                                 if (m_ptr->r_idx) teleport_away(g_ptr->m_idx, damroll(10, 10), TELEPORT_PASSIVE);
3919                                 if (one_in_(13)) count += activate_hi_summon(m_ptr->fy, m_ptr->fx, TRUE);
3920                                 if (!one_in_(6)) break;
3921                         }
3922                 case 9: case 10: case 11:
3923                         msg_print(_("エネルギーのうねりを感じた!", "You feel a surge of energy!"));
3924                         project(0, 7, m_ptr->fy, m_ptr->fx, 50, GF_DISINTEGRATE, curse_flg, -1);
3925                         if (!one_in_(6)) break;
3926                 case 12: case 13: case 14: case 15: case 16:
3927                         aggravate_monsters(0);
3928                         if (!one_in_(6)) break;
3929                 case 17: case 18:
3930                         count += activate_hi_summon(m_ptr->fy, m_ptr->fx, TRUE);
3931                         if (!one_in_(6)) break;
3932                 case 19: case 20: case 21: case 22:
3933                 {
3934                         bool pet = !one_in_(3);
3935                         BIT_FLAGS mode = PM_ALLOW_GROUP;
3936
3937                         if (pet) mode |= PM_FORCE_PET;
3938                         else mode |= (PM_NO_PET | PM_FORCE_FRIENDLY);
3939
3940                         count += summon_specific((pet ? -1 : 0), p_ptr->y, p_ptr->x, (pet ? p_ptr->lev * 2 / 3 + randint1(p_ptr->lev / 2) : current_floor_ptr->dun_level), 0, mode, '\0');
3941                         if (!one_in_(6)) break;
3942                 }
3943                 case 23: case 24: case 25:
3944                         if (p_ptr->hold_exp && (randint0(100) < 75)) break;
3945                         msg_print(_("経験値が体から吸い取られた気がする!", "You feel your experience draining away..."));
3946
3947                         if (p_ptr->hold_exp) lose_exp(p_ptr->exp / 160);
3948                         else lose_exp(p_ptr->exp / 16);
3949                         if (!one_in_(6)) break;
3950                 case 26: case 27: case 28:
3951                 {
3952                         int i = 0;
3953                         if (one_in_(13))
3954                         {
3955                                 while (i < A_MAX)
3956                                 {
3957                                         do
3958                                         {
3959                                                 (void)do_dec_stat(i);
3960                                         } while (one_in_(2));
3961
3962                                         i++;
3963                                 }
3964                         }
3965                         else
3966                         {
3967                                 (void)do_dec_stat(randint0(6));
3968                         }
3969                         break;
3970                 }
3971                 }
3972         } while (one_in_(5));
3973 }
3974
3975
3976 bool fire_crimson(void)
3977 {
3978         int num = 1;
3979         int i;
3980         BIT_FLAGS flg = PROJECT_STOP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
3981         POSITION tx, ty;
3982         DIRECTION dir;
3983
3984         if (!get_aim_dir(&dir)) return FALSE;
3985
3986         /* Use the given direction */
3987         tx = p_ptr->x + 99 * ddx[dir];
3988         ty = p_ptr->y + 99 * ddy[dir];
3989
3990         /* Hack -- Use an actual "target" */
3991         if ((dir == 5) && target_okay())
3992         {
3993                 tx = target_col;
3994                 ty = target_row;
3995         }
3996
3997         if (p_ptr->pclass == CLASS_ARCHER)
3998         {
3999                 /* Extra shot at level 10 */
4000                 if (p_ptr->lev >= 10) num++;
4001
4002                 /* Extra shot at level 30 */
4003                 if (p_ptr->lev >= 30) num++;
4004
4005                 /* Extra shot at level 45 */
4006                 if (p_ptr->lev >= 45) num++;
4007         }
4008
4009         for (i = 0; i < num; i++)
4010                 project(0, p_ptr->lev / 20 + 1, ty, tx, p_ptr->lev*p_ptr->lev * 6 / 50, GF_ROCKET, flg, -1);
4011
4012         return TRUE;
4013 }
4014