OSDN Git Service

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