OSDN Git Service

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