OSDN Git Service

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