OSDN Git Service

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