OSDN Git Service

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