OSDN Git Service

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