OSDN Git Service

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