OSDN Git Service

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