OSDN Git Service

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