OSDN Git Service

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