OSDN Git Service

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