OSDN Git Service

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