OSDN Git Service

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