OSDN Git Service

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