OSDN Git Service

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