OSDN Git Service

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