OSDN Git Service

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