OSDN Git Service

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