OSDN Git Service

#37287 #37353 (2.2.0.89) 型の置換を継続中。 / Ongoing type replacement.
[hengband/hengband.git] / src / cmd2.c
1 /*!
2  *  @file cmd2.c
3  *  @brief プレイヤーのコマンド処理2 / Movement commands (part 2)
4  *  @date 2014/01/02
5  *  @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  */
12
13 #include "angband.h"
14
15
16 /*!
17  * @brief フロア脱出時に出戻りが不可能だった場合に警告を加える処理
18  * @param down_stair TRUEならば階段を降りる処理、FALSEなら階段を昇る処理による内容
19  * @return フロア移動を実際に行うならTRUE、キャンセルする場合はFALSE
20  */
21 bool confirm_leave_level(bool down_stair)
22 {
23         quest_type *q_ptr = &quest[p_ptr->inside_quest];
24
25         /* Confirm leaving from once only quest */
26         if (confirm_quest && p_ptr->inside_quest &&
27             (q_ptr->type == QUEST_TYPE_RANDOM ||
28              (q_ptr->flags & QUEST_FLAG_ONCE &&
29                                                 q_ptr->status != QUEST_STATUS_COMPLETED) ||
30                  (q_ptr->flags & QUEST_FLAG_TOWER &&
31                                                 ((q_ptr->status != QUEST_STATUS_STAGE_COMPLETED) ||
32                                                  (down_stair && (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))))))
33         {
34 #ifdef JP
35                 msg_print("この階を一度去ると二度と戻って来られません。");
36                 if (get_check("本当にこの階を去りますか?")) return TRUE;
37 #else
38                 msg_print("You can't come back here once you leave this floor.");
39                 if (get_check("Really leave this floor? ")) return TRUE;
40 #endif
41         }
42         else
43         {
44                 return TRUE;
45         }
46         return FALSE;
47 }
48
49 /*!
50  * @brief 階段を使って階層を昇る処理 / Go up one level
51  * @return なし
52  */
53 void do_cmd_go_up(void)
54 {
55         bool go_up = FALSE;
56
57         /* Player grid */
58         cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
59         feature_type *f_ptr = &f_info[c_ptr->feat];
60
61         int up_num = 0;
62
63         if (p_ptr->special_defense & KATA_MUSOU)
64         {
65                 set_action(ACTION_NONE);
66         }
67
68         /* Verify stairs */
69         if (!have_flag(f_ptr->flags, FF_LESS))
70         {
71                 msg_print(_("ここには上り階段が見当たらない。", "I see no up staircase here."));
72                 return;
73         }
74
75         /* Quest up stairs */
76         if (have_flag(f_ptr->flags, FF_QUEST))
77         {
78                 /* Cancel the command */
79                 if (!confirm_leave_level(FALSE)) return;
80         
81                 
82                 /* Success */
83 #ifdef JP
84                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
85                         msg_print("なんだこの階段は!");
86                 else
87                         msg_print("上の階に登った。");
88 #else
89                 msg_print("You enter the up staircase.");
90 #endif
91
92                 leave_quest_check();
93
94                 p_ptr->inside_quest = c_ptr->special;
95
96                 /* Activate the quest */
97                 if (!quest[p_ptr->inside_quest].status)
98                 {
99                         if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
100                         {
101                                 init_flags = INIT_ASSIGN;
102                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
103                         }
104                         quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
105                 }
106
107                 /* Leaving a quest */
108                 if (!p_ptr->inside_quest)
109                 {
110                         dun_level = 0;
111                 }
112
113                 /* Leaving */
114                 p_ptr->leaving = TRUE;
115
116                 p_ptr->oldpx = 0;
117                 p_ptr->oldpy = 0;
118                 
119                 /* Hack -- take a turn */
120                 p_ptr->energy_use = 100;
121
122                 /* End the command */
123                 return;
124         }
125
126         if (!dun_level)
127         {
128                 go_up = TRUE;
129         }
130         else
131         {
132                 go_up = confirm_leave_level(FALSE);
133         }
134
135         /* Cancel the command */
136         if (!go_up) return;
137
138         /* Hack -- take a turn */
139         p_ptr->energy_use = 100;
140
141         if (autosave_l) do_cmd_save_game(TRUE);
142
143         /* For a random quest */
144         if (p_ptr->inside_quest &&
145             quest[p_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
146         {
147                 leave_quest_check();
148
149                 p_ptr->inside_quest = 0;
150         }
151
152         /* For a fixed quest */
153         if (p_ptr->inside_quest &&
154             quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
155         {
156                 leave_quest_check();
157
158                 p_ptr->inside_quest = c_ptr->special;
159                 dun_level = 0;
160                 up_num = 0;
161         }
162
163         /* For normal dungeon and random quest */
164         else
165         {
166                 /* New depth */
167                 if (have_flag(f_ptr->flags, FF_SHAFT))
168                 {
169                         /* Create a way back */
170                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_SHAFT);
171
172                         up_num = 2;
173                 }
174                 else
175                 {
176                         /* Create a way back */
177                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP);
178
179                         up_num = 1;
180                 }
181
182                 /* Get out from current dungeon */
183                 if (dun_level - up_num < d_info[dungeon_type].mindepth)
184                         up_num = dun_level;
185         }
186         if (record_stair) do_cmd_write_nikki(NIKKI_STAIR, 0-up_num, _("階段を上った", "climbed up the stairs to"));
187
188         /* Success */
189         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
190                 msg_print(_("なんだこの階段は!", ""));
191         else if (up_num == dun_level)
192                 msg_print(_("地上に戻った。", "You go back to the surface."));
193         else
194                 msg_print(_("階段を上って新たなる迷宮へと足を踏み入れた。", "You enter a maze of up staircases."));
195
196         /* Leaving */
197         p_ptr->leaving = TRUE;
198 }
199
200
201 /*!
202  * @brief 階段を使って階層を降りる処理 / Go down one level
203  * @return なし
204  */
205 void do_cmd_go_down(void)
206 {
207         /* Player grid */
208         cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
209         feature_type *f_ptr = &f_info[c_ptr->feat];
210
211         bool fall_trap = FALSE;
212         int down_num = 0;
213
214         if (p_ptr->special_defense & KATA_MUSOU)
215         {
216                 set_action(ACTION_NONE);
217         }
218
219         /* Verify stairs */
220         if (!have_flag(f_ptr->flags, FF_MORE))
221         {
222                 msg_print(_("ここには下り階段が見当たらない。", "I see no down staircase here."));
223                 return;
224         }
225
226         if (have_flag(f_ptr->flags, FF_TRAP)) fall_trap = TRUE;
227
228         /* Quest entrance */
229         if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
230         {
231                 do_cmd_quest();
232         }
233
234         /* Quest down stairs */
235         else if (have_flag(f_ptr->flags, FF_QUEST))
236         {
237                 /* Confirm Leaving */
238                 if(!confirm_leave_level(TRUE)) return;
239                 
240 #ifdef JP
241                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
242                         msg_print("なんだこの階段は!");
243                 else
244                         msg_print("下の階に降りた。");
245 #else
246                         msg_print("You enter the down staircase.");
247 #endif
248
249                 leave_quest_check();
250                 leave_tower_check();
251
252                 p_ptr->inside_quest = c_ptr->special;
253
254                 /* Activate the quest */
255                 if (!quest[p_ptr->inside_quest].status)
256                 {
257                         if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
258                         {
259                                 init_flags = INIT_ASSIGN;
260                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
261                         }
262                         quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
263                 }
264
265                 /* Leaving a quest */
266                 if (!p_ptr->inside_quest)
267                 {
268                         dun_level = 0;
269                 }
270
271                 /* Leaving */
272                 p_ptr->leaving = TRUE;
273
274                 p_ptr->oldpx = 0;
275                 p_ptr->oldpy = 0;
276                 
277                 
278         /* Hack -- take a turn */
279         p_ptr->energy_use = 100;
280         }
281
282         else
283         {
284                 int target_dungeon = 0;
285
286                 if (!dun_level)
287                 {
288                         target_dungeon = have_flag(f_ptr->flags, FF_ENTRANCE) ? c_ptr->special : DUNGEON_ANGBAND;
289
290                         if (ironman_downward && (target_dungeon != DUNGEON_ANGBAND))
291                         {
292                                 msg_print(_("ダンジョンの入口は塞がれている!", "The entrance of this dungeon is closed!"));
293                                 return;
294                         }
295                         if (!max_dlv[target_dungeon])
296                         {
297                                 msg_format(_("ここには%sの入り口(%d階相当)があります", "There is the entrance of %s (Danger level: %d)"),
298                                                         d_name+d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
299                                 if (!get_check(_("本当にこのダンジョンに入りますか?", "Do you really get in this dungeon? "))) return;
300                         }
301
302                         /* Save old player position */
303                         p_ptr->oldpx = p_ptr->x;
304                         p_ptr->oldpy = p_ptr->y;
305                         dungeon_type = (byte)target_dungeon;
306
307                         /*
308                          * Clear all saved floors
309                          * and create a first saved floor
310                          */
311                         prepare_change_floor_mode(CFM_FIRST_FLOOR);
312                 }
313
314                 /* Hack -- take a turn */
315                 p_ptr->energy_use = 100;
316
317                 if (autosave_l) do_cmd_save_game(TRUE);
318
319                 /* Go down */
320                 if (have_flag(f_ptr->flags, FF_SHAFT)) down_num += 2;
321                 else down_num += 1;
322
323                 if (!dun_level)
324                 {
325                         /* Enter the dungeon just now */
326                         p_ptr->enter_dungeon = TRUE;
327                         down_num = d_info[dungeon_type].mindepth;
328                 }
329
330                 if (record_stair)
331                 {
332                         if (fall_trap) do_cmd_write_nikki(NIKKI_STAIR, down_num, _("落とし戸に落ちた", "fell through a trap door"));
333                         else do_cmd_write_nikki(NIKKI_STAIR, down_num, _("階段を下りた", "climbed down the stairs to"));
334                 }
335
336                 if (fall_trap)
337                 {
338                         msg_print(_("わざと落とし戸に落ちた。", "You deliberately jump through the trap door."));
339                 }
340                 else
341                 {
342                         /* Success */
343                         if (target_dungeon)
344                         {
345                                 msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[dungeon_type].text);
346                         }
347                         else
348                         {
349                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
350                                         msg_print(_("なんだこの階段は!", ""));
351                                 else
352                                         msg_print(_("階段を下りて新たなる迷宮へと足を踏み入れた。", "You enter a maze of down staircases."));
353                         }
354                 }
355
356
357                 /* Leaving */
358                 p_ptr->leaving = TRUE;
359
360                 if (fall_trap)
361                 {
362                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
363                 }
364                 else
365                 {
366                         if (have_flag(f_ptr->flags, FF_SHAFT))
367                         {
368                                 /* Create a way back */
369                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_SHAFT);
370                         }
371                         else
372                         {
373                                 /* Create a way back */
374                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN);
375                         }
376                 }
377         }
378 }
379
380
381 /*!
382  * @brief 探索コマンドのメインルーチン / Simple command to "search" for one turn
383  * @return なし
384  */
385 void do_cmd_search(void)
386 {
387         /* Allow repeated command */
388         if (command_arg)
389         {
390                 /* Set repeat count */
391                 command_rep = command_arg - 1;
392
393                 /* Redraw the state */
394                 p_ptr->redraw |= (PR_STATE);
395
396                 /* Cancel the arg */
397                 command_arg = 0;
398         }
399
400         /* Take a turn */
401         p_ptr->energy_use = 100;
402
403         /* Search */
404         search();
405 }
406
407
408 /*!
409  * @brief 該当のマスに存在している箱のオブジェクトIDを返す。
410  * @param y 走査対象にしたいマスのY座標
411  * @param x 走査対象にしたいマスのX座標
412  * @param trapped TRUEならばトラップが存在する箱のみ、FALSEならば空でない箱全てを対象にする
413  * @return 箱が存在する場合そのオブジェクトID、存在しない場合0を返す。
414  */
415 static s16b chest_check(int y, int x, bool trapped)
416 {
417         cave_type *c_ptr = &cave[y][x];
418
419         s16b this_o_idx, next_o_idx = 0;
420
421
422         /* Scan all objects in the grid */
423         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
424         {
425                 object_type *o_ptr;
426
427                 /* Acquire object */
428                 o_ptr = &o_list[this_o_idx];
429
430                 /* Acquire next object */
431                 next_o_idx = o_ptr->next_o_idx;
432
433                 /* Skip unknown chests XXX XXX */
434                 /* if (!(o_ptr->marked & OM_FOUND)) continue; */
435
436                 /* Check for non empty chest */
437                 if ((o_ptr->tval == TV_CHEST) &&
438                         (((!trapped) && (o_ptr->pval)) || /* non empty */
439                         ((trapped) && (o_ptr->pval > 0)))) /* trapped only */
440                 {
441                         return (this_o_idx);
442                 }
443         }
444
445         /* No chest */
446         return (0);
447 }
448
449
450 /*!
451  * @brief 箱からアイテムを引き出す /
452  * Allocates objects upon opening a chest    -BEN-
453  * @param scatter TRUEならばトラップによるアイテムの拡散処理
454  * @param y 箱の存在するマスのY座標
455  * @param x 箱の存在するマスのX座標
456  * @param o_idx 箱のオブジェクトID
457  * @return なし
458  * @details
459  * <pre>
460  * Disperse treasures from the given chest, centered at (x,y).
461  *
462  * Small chests often contain "gold", while Large chests always contain
463  * items.  Wooden chests contain 2 items, Iron chests contain 4 items,
464  * and Steel chests contain 6 items.  The "value" of the items in a
465  * chest is based on the "power" of the chest, which is in turn based
466  * on the level on which the chest is generated.
467  * </pre>
468  */
469 static void chest_death(bool scatter, int y, int x, s16b o_idx)
470 {
471         int number;
472
473         bool small;
474         u32b mode = AM_GOOD;
475
476         object_type forge;
477         object_type *q_ptr;
478
479         object_type *o_ptr = &o_list[o_idx];
480
481
482         /* Small chests often hold "gold" */
483         small = (o_ptr->sval < SV_CHEST_MIN_LARGE);
484
485         /* Determine how much to drop (see above) */
486         number = (o_ptr->sval % SV_CHEST_MIN_LARGE) * 2;
487
488         if (o_ptr->sval == SV_CHEST_KANDUME)
489         {
490                 number = 5;
491                 small = FALSE;
492                 mode |= AM_GREAT;
493                 object_level = o_ptr->xtra3;
494         }
495         else
496         {
497                 /* Determine the "value" of the items */
498                 object_level = ABS(o_ptr->pval) + 10;
499         }
500
501         /* Zero pval means empty chest */
502         if (!o_ptr->pval) number = 0;
503
504         /* Opening a chest */
505         opening_chest = TRUE;
506
507         /* Drop some objects (non-chests) */
508         for (; number > 0; --number)
509         {
510                 /* Get local object */
511                 q_ptr = &forge;
512
513                 /* Wipe the object */
514                 object_wipe(q_ptr);
515
516                 /* Small chests often drop gold */
517                 if (small && (randint0(100) < 25))
518                 {
519                         /* Make some gold */
520                         if (!make_gold(q_ptr)) continue;
521                 }
522
523                 /* Otherwise drop an item */
524                 else
525                 {
526                         /* Make a good object */
527                         if (!make_object(q_ptr, mode)) continue;
528                 }
529
530                 /* If chest scatters its contents, pick any floor square. */
531                 if (scatter)
532                 {
533                         int i;
534                         for (i = 0; i < 200; i++)
535                         {
536                                 /* Pick a totally random spot. */
537                                 y = randint0(MAX_HGT);
538                                 x = randint0(MAX_WID);
539
540                                 /* Must be an empty floor. */
541                                 if (!cave_empty_bold(y, x)) continue;
542
543                                 /* Place the object there. */
544                                 drop_near(q_ptr, -1, y, x);
545
546                                 /* Done. */
547                                 break;
548                         }
549                 }
550                 /* Normally, drop object near the chest. */
551                 else drop_near(q_ptr, -1, y, x);
552         }
553
554         /* Reset the object level */
555         object_level = base_level;
556
557         /* No longer opening a chest */
558         opening_chest = FALSE;
559
560         /* Empty */
561         o_ptr->pval = 0;
562
563         /* Known */
564         object_known(o_ptr);
565 }
566
567
568 /*!
569  * @brief 箱のトラップ処理 /
570  * Chests have traps too.
571  * @param y 箱の存在するマスのY座標
572  * @param x 箱の存在するマスのX座標
573  * @param o_idx 箱のオブジェクトID
574  * @return なし
575  * @details
576  * <pre>
577  * Exploding chest destroys contents (and traps).
578  * Note that the chest itself is never destroyed.
579  * </pre>
580  */
581 static void chest_trap(int y, int x, s16b o_idx)
582 {
583         int  i, trap;
584
585         object_type *o_ptr = &o_list[o_idx];
586
587         int mon_level = o_ptr->xtra3;
588
589         /* Ignore disarmed chests */
590         if (o_ptr->pval <= 0) return;
591
592         /* Obtain the traps */
593         trap = chest_traps[o_ptr->pval];
594
595         /* Lose strength */
596         if (trap & (CHEST_LOSE_STR))
597         {
598 #ifdef JP
599                 msg_print("仕掛けられていた小さな針に刺されてしまった!");
600                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "毒針", -1);
601 #else
602                 msg_print("A small needle has pricked you!");
603                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "a poison needle", -1);
604 #endif
605
606                 (void)do_dec_stat(A_STR);
607         }
608
609         /* Lose constitution */
610         if (trap & (CHEST_LOSE_CON))
611         {
612 #ifdef JP
613                 msg_print("仕掛けられていた小さな針に刺されてしまった!");
614                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "毒針", -1);
615 #else
616                 msg_print("A small needle has pricked you!");
617                 take_hit(DAMAGE_NOESCAPE, damroll(1, 4), "a poison needle", -1);
618 #endif
619
620                 (void)do_dec_stat(A_CON);
621         }
622
623         /* Poison */
624         if (trap & (CHEST_POISON))
625         {
626                 msg_print(_("突如吹き出した緑色のガスに包み込まれた!", "A puff of green gas surrounds you!"));
627                 if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))
628                 {
629                         (void)set_poisoned(p_ptr->poisoned + 10 + randint1(20));
630                 }
631         }
632
633         /* Paralyze */
634         if (trap & (CHEST_PARALYZE))
635         {
636                 msg_print(_("突如吹き出した黄色いガスに包み込まれた!", "A puff of yellow gas surrounds you!"));
637                 if (!p_ptr->free_act)
638                 {
639                         (void)set_paralyzed(p_ptr->paralyzed + 10 + randint1(20));
640                 }
641         }
642
643         /* Summon monsters */
644         if (trap & (CHEST_SUMMON))
645         {
646                 int num = 2 + randint1(3);
647                 msg_print(_("突如吹き出した煙に包み込まれた!", "You are enveloped in a cloud of smoke!"));
648                 for (i = 0; i < num; i++)
649                 {
650                         if (randint1(100)<dun_level)
651                                 activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
652                         else
653                                 (void)summon_specific(0, y, x, mon_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
654                 }
655         }
656
657         /* Elemental summon. */
658         if (trap & (CHEST_E_SUMMON))
659         {
660                 msg_print(_("宝を守るためにエレメンタルが現れた!", "Elemental beings appear to protect their treasures!"));
661                 for (i = 0; i < randint1(3) + 5; i++)
662                 {
663                         (void)summon_specific(0, y, x, mon_level, SUMMON_ELEMENTAL, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
664                 }
665         }
666
667         /* Force clouds, then summon birds. */
668         if (trap & (CHEST_BIRD_STORM))
669         {
670                 msg_print(_("鳥の群れがあなたを取り巻いた!", "A storm of birds swirls around you!"));
671
672                 for (i = 0; i < randint1(3) + 3; i++)
673                         (void)fire_meteor(-1, GF_FORCE, y, x, o_ptr->pval / 5, 7);
674
675                 for (i = 0; i < randint1(5) + o_ptr->pval / 5; i++)
676                 {
677                         (void)summon_specific(0, y, x, mon_level, SUMMON_BIRD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
678                 }
679         }
680
681         /* Various colorful summonings. */
682         if (trap & (CHEST_H_SUMMON))
683         {
684                 /* Summon demons. */
685                 if (one_in_(4))
686                 {
687                         msg_print(_("炎と硫黄の雲の中に悪魔が姿を現した!", "Demons materialize in clouds of fire and brimstone!"));
688                         for (i = 0; i < randint1(3) + 2; i++)
689                         {
690                                 (void)fire_meteor(-1, GF_FIRE, y, x, 10, 5);
691                                 (void)summon_specific(0, y, x, mon_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
692                         }
693                 }
694
695                 /* Summon dragons. */
696                 else if (one_in_(3))
697                 {
698                         msg_print(_("暗闇にドラゴンの影がぼんやりと現れた!", "Draconic forms loom out of the darkness!"));
699                         for (i = 0; i < randint1(3) + 2; i++)
700                         {
701                                 (void)summon_specific(0, y, x, mon_level, SUMMON_DRAGON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
702                         }
703                 }
704
705                 /* Summon hybrids. */
706                 else if (one_in_(2))
707                 {
708                         msg_print(_("奇妙な姿の怪物が襲って来た!", "Creatures strange and twisted assault you!"));
709                         for (i = 0; i < randint1(5) + 3; i++)
710                         {
711                                 (void)summon_specific(0, y, x, mon_level, SUMMON_HYBRID, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
712                         }
713                 }
714
715                 /* Summon vortices (scattered) */
716                 else
717                 {
718                         msg_print(_("渦巻が合体し、破裂した!", "Vortices coalesce and wreak destruction!"));
719                         for (i = 0; i < randint1(3) + 2; i++)
720                         {
721                                 (void)summon_specific(0, y, x, mon_level, SUMMON_VORTEX, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
722                         }
723                 }
724         }
725
726         /* Dispel player. */
727         if ((trap & (CHEST_RUNES_OF_EVIL)) && o_ptr->k_idx)
728         {
729                 /* Determine how many nasty tricks can be played. */
730                 int nasty_tricks_count = 4 + randint0(3);
731
732                 /* Message. */
733                 msg_print(_("恐ろしい声が響いた:  「暗闇が汝をつつまん!」", "Hideous voices bid:  'Let the darkness have thee!'"));
734                 /* This is gonna hurt... */
735                 for (; nasty_tricks_count > 0; nasty_tricks_count--)
736                 {
737                         /* ...but a high saving throw does help a little. */
738                         if (randint1(100+o_ptr->pval*2) > p_ptr->skill_sav)
739                         {
740                                 if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), _("破滅のトラップの宝箱", "a chest dispel-player trap"), -1);
741                                 else if (one_in_(5)) (void)set_cut(p_ptr->cut + 200);
742                                 else if (one_in_(4))
743                                 {
744                                         if (!p_ptr->free_act) 
745                                                 (void)set_paralyzed(p_ptr->paralyzed + 2 + 
746                                                 randint0(6));
747                                         else 
748                                                 (void)set_stun(p_ptr->stun + 10 + 
749                                                 randint0(100));
750                                 }
751                                 else if (one_in_(3)) apply_disenchant(0);
752                                 else if (one_in_(2))
753                                 {
754                                         (void)do_dec_stat(A_STR);
755                                         (void)do_dec_stat(A_DEX);
756                                         (void)do_dec_stat(A_CON);
757                                         (void)do_dec_stat(A_INT);
758                                         (void)do_dec_stat(A_WIS);
759                                         (void)do_dec_stat(A_CHR);
760                                 }
761                                 else (void)fire_meteor(-1, GF_NETHER, y, x, 150, 1);
762                         }
763                 }
764         }
765
766         /* Aggravate monsters. */
767         if (trap & (CHEST_ALARM))
768         {
769                 msg_print(_("けたたましい音が鳴り響いた!", "An alarm sounds!"));
770                 aggravate_monsters(0);
771         }
772
773         /* Explode */
774         if ((trap & (CHEST_EXPLODE)) && o_ptr->k_idx)
775         {
776                 msg_print(_("突然、箱が爆発した!", "There is a sudden explosion!"));
777                 msg_print(_("箱の中の物はすべて粉々に砕け散った!", "Everything inside the chest is destroyed!"));
778                 o_ptr->pval = 0;
779                 sound(SOUND_EXPLODE);
780                 take_hit(DAMAGE_ATTACK, damroll(5, 8), _("爆発する箱", "an exploding chest"), -1);
781         }
782         /* Scatter contents. */
783         if ((trap & (CHEST_SCATTER)) && o_ptr->k_idx)
784         {
785                 msg_print(_("宝箱の中身はダンジョンじゅうに散乱した!", "The contents of the chest scatter all over the dungeon!"));
786                 chest_death(TRUE, y, x, o_idx);
787                 o_ptr->pval = 0;
788         }
789 }
790
791
792 /*!
793  * @brief 箱を開けるコマンドのメインルーチン /
794  * Attempt to open the given chest at the given location
795  * @param y 箱の存在するマスのY座標
796  * @param x 箱の存在するマスのX座標
797  * @param o_idx 箱のオブジェクトID
798  * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
799  * @details
800  * Assume there is no monster blocking the destination
801  */
802 static bool do_cmd_open_chest(int y, int x, s16b o_idx)
803 {
804         int i, j;
805
806         bool flag = TRUE;
807
808         bool more = FALSE;
809
810         object_type *o_ptr = &o_list[o_idx];
811
812
813         /* Take a turn */
814         p_ptr->energy_use = 100;
815
816         /* Attempt to unlock it */
817         if (o_ptr->pval > 0)
818         {
819                 /* Assume locked, and thus not open */
820                 flag = FALSE;
821
822                 /* Get the "disarm" factor */
823                 i = p_ptr->skill_dis;
824
825                 /* Penalize some conditions */
826                 if (p_ptr->blind || no_lite()) i = i / 10;
827                 if (p_ptr->confused || p_ptr->image) i = i / 10;
828
829                 /* Extract the difficulty */
830                 j = i - o_ptr->pval;
831
832                 /* Always have a small chance of success */
833                 if (j < 2) j = 2;
834
835                 /* Success -- May still have traps */
836                 if (randint0(100) < j)
837                 {
838                         msg_print(_("鍵をはずした。", "You have picked the lock."));
839                         gain_exp(1);
840                         flag = TRUE;
841                 }
842
843                 /* Failure -- Keep trying */
844                 else
845                 {
846                         /* We may continue repeating */
847                         more = TRUE;
848                         if (flush_failure) flush();
849                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
850
851                 }
852         }
853
854         /* Allowed to open */
855         if (flag)
856         {
857                 /* Apply chest traps, if any */
858                 chest_trap(y, x, o_idx);
859
860                 /* Let the Chest drop items */
861                 chest_death(FALSE, y, x, o_idx);
862         }
863
864         /* Result */
865         return (more);
866 }
867
868
869 #if defined(ALLOW_EASY_OPEN) || defined(ALLOW_EASY_DISARM) /* TNB */
870
871 /*!
872  * @brief 地形は開くものであって、かつ開かれているかを返す /
873  * Attempt to open the given chest at the given location
874  * @param feat 地形ID
875  * @return 開いた地形である場合TRUEを返す /  Return TRUE if the given feature is an open door
876  */
877 static bool is_open(IDX feat)
878 {
879         return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
880 }
881
882
883 /*!
884  * @brief プレイヤーの周辺9マスに該当する地形がいくつあるかを返す /
885  * Attempt to open the given chest at the given location
886  * @param y 該当する地形の中から1つのY座標を返す参照ポインタ
887  * @param x 該当する地形の中から1つのX座標を返す参照ポインタ
888  * @param test 地形条件を判定するための関数ポインタ
889  * @param under TRUEならばプレイヤーの直下の座標も走査対象にする
890  * @return 該当する地形の数
891  * @details Return the number of features around (or under) the character.
892  * Usually look for doors and floor traps.
893  */
894 static int count_dt(POSITION *y, POSITION *x, bool (*test)(IDX feat), bool under)
895 {
896         int d, count, xx, yy;
897
898         /* Count how many matches */
899         count = 0;
900
901         /* Check around (and under) the character */
902         for (d = 0; d < 9; d++)
903         {
904                 cave_type *c_ptr;
905                 s16b feat;
906
907                 /* if not searching under player continue */
908                 if ((d == 8) && !under) continue;
909
910                 /* Extract adjacent (legal) location */
911                 yy = p_ptr->y + ddy_ddd[d];
912                 xx = p_ptr->x + ddx_ddd[d];
913
914                 /* Get the cave */
915                 c_ptr = &cave[yy][xx];
916
917                 /* Must have knowledge */
918                 if (!(c_ptr->info & (CAVE_MARK))) continue;
919
920                 /* Feature code (applying "mimic" field) */
921                 feat = get_feat_mimic(c_ptr);
922
923                 /* Not looking for this feature */
924                 if (!((*test)(feat))) continue;
925
926                 /* OK */
927                 ++count;
928
929                 /* Remember the location. Only useful if only one match */
930                 *y = yy;
931                 *x = xx;
932         }
933
934         /* All done */
935         return count;
936 }
937
938
939 /*!
940  * @brief プレイヤーの周辺9マスに箱のあるマスがいくつあるかを返す /
941  * Return the number of chests around (or under) the character.
942  * @param y 該当するマスの中から1つのY座標を返す参照ポインタ
943  * @param x 該当するマスの中から1つのX座標を返す参照ポインタ
944  * @param trapped TRUEならばトラップの存在が判明している箱のみ対象にする
945  * @return 該当する地形の数
946  * @details
947  * If requested, count only trapped chests.
948  */
949 static int count_chests(POSITION *y, POSITION *x, bool trapped)
950 {
951         int d, count;
952         IDX o_idx;
953
954         object_type *o_ptr;
955
956         /* Count how many matches */
957         count = 0;
958
959         /* Check around (and under) the character */
960         for (d = 0; d < 9; d++)
961         {
962                 /* Extract adjacent (legal) location */
963                 int yy = p_ptr->y + ddy_ddd[d];
964                 int xx = p_ptr->x + ddx_ddd[d];
965
966                 /* No (visible) chest is there */
967                 if ((o_idx = chest_check(yy, xx, FALSE)) == 0) continue;
968
969                 /* Grab the object */
970                 o_ptr = &o_list[o_idx];
971
972                 /* Already open */
973                 if (o_ptr->pval == 0) continue;
974
975                 /* No (known) traps here */
976                 if (trapped && (!object_is_known(o_ptr) ||
977                         !chest_traps[o_ptr->pval])) continue;
978
979                 /* OK */
980                 ++count;
981
982                 /* Remember the location. Only useful if only one match */
983                 *y = yy;
984                 *x = xx;
985         }
986
987         /* All done */
988         return count;
989 }
990
991
992 /*!
993  * @brief プレイヤーから指定の座標がどの方角にあるかを返す /
994  * Convert an adjacent location to a direction.
995  * @param y 方角を確認したY座標
996  * @param x 方角を確認したX座標
997  * @return 方向ID
998  */
999 static DIRECTION coords_to_dir(POSITION y, POSITION x)
1000 {
1001         int d[3][3] = { {7, 4, 1}, {8, 5, 2}, {9, 6, 3} };
1002         int dy, dx;
1003
1004         dy = y - p_ptr->y;
1005         dx = x - p_ptr->x;
1006
1007         /* Paranoia */
1008         if (ABS(dx) > 1 || ABS(dy) > 1) return (0);
1009
1010         return d[dx + 1][dy + 1];
1011 }
1012
1013 #endif /* defined(ALLOW_EASY_OPEN) || defined(ALLOW_EASY_DISARM) -- TNB */
1014
1015
1016 /*!
1017  * @brief 「開ける」動作コマンドのサブルーチン /
1018  * Perform the basic "open" command on doors
1019  * @param y 対象を行うマスのY座標
1020  * @param x 対象を行うマスのX座標
1021  * @return 実際に処理が行われた場合TRUEを返す。
1022  * @details
1023  * Assume destination is a closed/locked/jammed door
1024  * Assume there is no monster blocking the destination
1025  * Returns TRUE if repeated commands may continue
1026  */
1027 static bool do_cmd_open_aux(int y, int x)
1028 {
1029         int i, j;
1030
1031         /* Get requested grid */
1032         cave_type *c_ptr = &cave[y][x];
1033
1034         feature_type *f_ptr = &f_info[c_ptr->feat];
1035
1036         bool more = FALSE;
1037
1038
1039         /* Take a turn */
1040         p_ptr->energy_use = 100;
1041
1042         /* Seeing true feature code (ignore mimic) */
1043
1044         /* Jammed door */
1045         if (!have_flag(f_ptr->flags, FF_OPEN))
1046         {
1047                 /* Stuck */
1048                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(c_ptr)].name);
1049         }
1050
1051         /* Locked door */
1052         else if (f_ptr->power)
1053         {
1054                 /* Disarm factor */
1055                 i = p_ptr->skill_dis;
1056
1057                 /* Penalize some conditions */
1058                 if (p_ptr->blind || no_lite()) i = i / 10;
1059                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1060
1061                 /* Extract the lock power */
1062                 j = f_ptr->power;
1063
1064                 /* Extract the difficulty XXX XXX XXX */
1065                 j = i - (j * 4);
1066
1067                 /* Always have a small chance of success */
1068                 if (j < 2) j = 2;
1069
1070                 /* Success */
1071                 if (randint0(100) < j)
1072                 {
1073                         /* Message */
1074                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1075
1076                         /* Open the door */
1077                         cave_alter_feat(y, x, FF_OPEN);
1078
1079                         /* Sound */
1080                         sound(SOUND_OPENDOOR);
1081
1082                         /* Experience */
1083                         gain_exp(1);
1084                 }
1085
1086                 /* Failure */
1087                 else
1088                 {
1089                         /* Failure */
1090                         if (flush_failure) flush();
1091
1092                         /* Message */
1093                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1094
1095                         /* We may keep trying */
1096                         more = TRUE;
1097                 }
1098         }
1099
1100         /* Closed door */
1101         else
1102         {
1103                 /* Open the door */
1104                 cave_alter_feat(y, x, FF_OPEN);
1105
1106                 /* Sound */
1107                 sound(SOUND_OPENDOOR);
1108         }
1109
1110         /* Result */
1111         return (more);
1112 }
1113
1114 /*!
1115  * @brief 「開ける」コマンドのメインルーチン /
1116  * Open a closed/locked/jammed door or a closed/locked chest.
1117  * @return なし
1118  * @details
1119  * Unlocking a locked door/chest is worth one experience point.
1120  */
1121 void do_cmd_open(void)
1122 {
1123         POSITION y, x;
1124         DIRECTION dir;
1125         IDX o_idx;
1126
1127         bool more = FALSE;
1128
1129         if (p_ptr->special_defense & KATA_MUSOU)
1130         {
1131                 set_action(ACTION_NONE);
1132         }
1133
1134 #ifdef ALLOW_EASY_OPEN /* TNB */
1135
1136         /* Option: Pick a direction */
1137         if (easy_open)
1138         {
1139                 int num_doors, num_chests;
1140
1141                 /* Count closed doors (locked or jammed) */
1142                 num_doors = count_dt(&y, &x, is_closed_door, FALSE);
1143
1144                 /* Count chests (locked) */
1145                 num_chests = count_chests(&y, &x, FALSE);
1146
1147                 /* See if only one target */
1148                 if (num_doors || num_chests)
1149                 {
1150                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
1151                             (num_chests > 1);
1152                         if (!too_many) command_dir = coords_to_dir(y, x);
1153                 }
1154         }
1155
1156 #endif /* ALLOW_EASY_OPEN -- TNB */
1157
1158         /* Allow repeated command */
1159         if (command_arg)
1160         {
1161                 /* Set repeat count */
1162                 command_rep = command_arg - 1;
1163
1164                 /* Redraw the state */
1165                 p_ptr->redraw |= (PR_STATE);
1166
1167                 /* Cancel the arg */
1168                 command_arg = 0;
1169         }
1170
1171         /* Get a "repeated" direction */
1172         if (get_rep_dir(&dir, TRUE))
1173         {
1174                 s16b feat;
1175                 cave_type *c_ptr;
1176
1177                 /* Get requested location */
1178                 y = p_ptr->y + ddy[dir];
1179                 x = p_ptr->x + ddx[dir];
1180
1181                 /* Get requested grid */
1182                 c_ptr = &cave[y][x];
1183
1184                 /* Feature code (applying "mimic" field) */
1185                 feat = get_feat_mimic(c_ptr);
1186
1187                 /* Check for chest */
1188                 o_idx = chest_check(y, x, FALSE);
1189
1190                 /* Nothing useful */
1191                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
1192                 {
1193                         /* Message */
1194                         msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
1195                 }
1196
1197                 /* Monster in the way */
1198                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
1199                 {
1200                         /* Take a turn */
1201                         p_ptr->energy_use = 100;
1202
1203                         /* Message */
1204                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1205                         
1206                         /* Attack */
1207                         py_attack(y, x, 0);
1208                 }
1209
1210                 /* Handle chests */
1211                 else if (o_idx)
1212                 {
1213                         /* Open the chest */
1214                         more = do_cmd_open_chest(y, x, o_idx);
1215                 }
1216
1217                 /* Handle doors */
1218                 else
1219                 {
1220                         /* Open the door */
1221                         more = do_cmd_open_aux(y, x);
1222                 }
1223         }
1224
1225         /* Cancel repeat unless we may continue */
1226         if (!more) disturb(0, 0);
1227 }
1228
1229
1230
1231 /*!
1232  * @brief 「閉じる」動作コマンドのサブルーチン /
1233  * Perform the basic "close" command
1234  * @param y 対象を行うマスのY座標
1235  * @param x 対象を行うマスのX座標
1236  * @return 実際に処理が行われた場合TRUEを返す。
1237  * @details
1238  * Assume destination is an open/broken door
1239  * Assume there is no monster blocking the destination
1240  * Returns TRUE if repeated commands may continue
1241  */
1242 static bool do_cmd_close_aux(int y, int x)
1243 {
1244         /* Get grid and contents */
1245         cave_type *c_ptr = &cave[y][x];
1246         s16b      old_feat = c_ptr->feat;
1247         bool      more = FALSE;
1248
1249         /* Take a turn */
1250         p_ptr->energy_use = 100;
1251
1252         /* Seeing true feature code (ignore mimic) */
1253
1254         /* Open door */
1255         if (have_flag(f_info[old_feat].flags, FF_CLOSE))
1256         {
1257                 s16b closed_feat = feat_state(old_feat, FF_CLOSE);
1258
1259                 /* Hack -- object in the way */
1260                 if ((c_ptr->o_idx || (c_ptr->info & CAVE_OBJECT)) &&
1261                     (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
1262                 {
1263                         /* Message */
1264                         msg_print(_("何かがつっかえて閉まらない。", "There seems stuck."));
1265                 }
1266                 else
1267                 {
1268                         /* Close the door */
1269                         cave_alter_feat(y, x, FF_CLOSE);
1270
1271                         /* Broken door */
1272                         if (old_feat == c_ptr->feat)
1273                         {
1274                                 /* Message */
1275                                 msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
1276                         }
1277                         else
1278                         {
1279                                 /* Sound */
1280                                 sound(SOUND_SHUTDOOR);
1281                         }
1282                 }
1283         }
1284
1285         /* Result */
1286         return (more);
1287 }
1288
1289
1290 /*!
1291  * @brief 「閉じる」コマンドのメインルーチン /
1292  * Close an open door.
1293  * @return なし
1294  * @details
1295  * Unlocking a locked door/chest is worth one experience point.
1296  */
1297 void do_cmd_close(void)
1298 {
1299         POSITION y, x;
1300         DIRECTION dir;
1301
1302         bool more = FALSE;
1303
1304         if (p_ptr->special_defense & KATA_MUSOU)
1305         {
1306                 set_action(ACTION_NONE);
1307         }
1308
1309 #ifdef ALLOW_EASY_OPEN /* TNB */
1310
1311         /* Option: Pick a direction */
1312         if (easy_open)
1313         {
1314                 /* Count open doors */
1315                 if (count_dt(&y, &x, is_open, FALSE) == 1)
1316                 {
1317                         command_dir = coords_to_dir(y, x);
1318                 }
1319         }
1320
1321 #endif /* ALLOW_EASY_OPEN -- TNB */
1322
1323         /* Allow repeated command */
1324         if (command_arg)
1325         {
1326                 /* Set repeat count */
1327                 command_rep = command_arg - 1;
1328
1329                 /* Redraw the state */
1330                 p_ptr->redraw |= (PR_STATE);
1331
1332                 /* Cancel the arg */
1333                 command_arg = 0;
1334         }
1335
1336         /* Get a "repeated" direction */
1337         if (get_rep_dir(&dir,FALSE))
1338         {
1339                 cave_type *c_ptr;
1340                 s16b feat;
1341
1342                 /* Get requested location */
1343                 y = p_ptr->y + ddy[dir];
1344                 x = p_ptr->x + ddx[dir];
1345
1346                 /* Get grid and contents */
1347                 c_ptr = &cave[y][x];
1348
1349                 /* Feature code (applying "mimic" field) */
1350                 feat = get_feat_mimic(c_ptr);
1351
1352                 /* Require open/broken door */
1353                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
1354                 {
1355                         /* Message */
1356                         msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
1357                 }
1358
1359                 /* Monster in the way */
1360                 else if (c_ptr->m_idx)
1361                 {
1362                         /* Take a turn */
1363                         p_ptr->energy_use = 100;
1364
1365                         /* Message */
1366                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1367
1368                         /* Attack */
1369                         py_attack(y, x, 0);
1370                 }
1371
1372                 /* Close the door */
1373                 else
1374                 {
1375                         /* Close the door */
1376                         more = do_cmd_close_aux(y, x);
1377                 }
1378         }
1379
1380         /* Cancel repeat unless we may continue */
1381         if (!more) disturb(0, 0);
1382 }
1383
1384
1385 /*!
1386  * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
1387  * Determine if a given grid may be "tunneled"
1388  * @param y 対象を行うマスのY座標
1389  * @param x 対象を行うマスのX座標
1390  * @return 
1391  */
1392 static bool do_cmd_tunnel_test(int y, int x)
1393 {
1394         cave_type *c_ptr = &cave[y][x];
1395
1396         /* Must have knowledge */
1397         if (!(c_ptr->info & CAVE_MARK))
1398         {
1399                 /* Message */
1400                 msg_print(_("そこには何も見当たらない。", "You see nothing there."));
1401
1402                 /* Nope */
1403                 return (FALSE);
1404         }
1405
1406         /* Must be a wall/door/etc */
1407         if (!cave_have_flag_grid(c_ptr, FF_TUNNEL))
1408         {
1409                 /* Message */
1410                 msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
1411
1412                 /* Nope */
1413                 return (FALSE);
1414         }
1415
1416         /* Okay */
1417         return (TRUE);
1418 }
1419
1420
1421 /*!
1422  * @brief 「掘る」動作コマンドのサブルーチン /
1423  * Perform the basic "tunnel" command
1424  * @param y 対象を行うマスのY座標
1425  * @param x 対象を行うマスのX座標
1426  * @return 実際に処理が行われた場合TRUEを返す。
1427  * @details
1428  * Assumes that no monster is blocking the destination
1429  * Do not use twall anymore
1430  * Returns TRUE if repeated commands may continue
1431  */
1432 static bool do_cmd_tunnel_aux(int y, int x)
1433 {
1434         cave_type *c_ptr;
1435         feature_type *f_ptr, *mimic_f_ptr;
1436         int power;
1437         cptr name;
1438         bool more = FALSE;
1439
1440         /* Verify legality */
1441         if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1442
1443         /* Take a turn */
1444         p_ptr->energy_use = 100;
1445
1446         /* Get grid */
1447         c_ptr = &cave[y][x];
1448         f_ptr = &f_info[c_ptr->feat];
1449         power = f_ptr->power;
1450
1451         /* Feature code (applying "mimic" field) */
1452         mimic_f_ptr = &f_info[get_feat_mimic(c_ptr)];
1453
1454         name = f_name + mimic_f_ptr->name;
1455
1456         /* Sound */
1457         sound(SOUND_DIG);
1458
1459         if (have_flag(f_ptr->flags, FF_PERMANENT))
1460         {
1461                 /* Titanium */
1462                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1463                 {
1464                         msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
1465                 }
1466
1467                 /* Map border (mimiccing Permanent wall) */
1468                 else
1469                 {
1470                         msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
1471                 }
1472         }
1473
1474         /* Dig or tunnel */
1475         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1476         {
1477                 /* Dig */
1478                 if (p_ptr->skill_dig > randint0(20 * power))
1479                 {
1480                         /* Message */
1481                         msg_format(_("%sをくずした。", "You have removed the %s."), name);
1482
1483                         /* Remove the feature */
1484                         cave_alter_feat(y, x, FF_TUNNEL);
1485
1486                         /* Update some things */
1487                         p_ptr->update |= (PU_FLOW);
1488                 }
1489                 else
1490                 {
1491                         /* Message, keep digging */
1492                         msg_format(_("%sをくずしている。", "You dig into the %s."), name);
1493                         
1494                         more = TRUE;
1495                 }
1496         }
1497
1498         else
1499         {
1500                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1501
1502                 /* Tunnel */
1503                 if (p_ptr->skill_dig > power + randint0(40 * power))
1504                 {
1505                         if (tree) msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
1506                         else
1507                         {
1508                                 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
1509                                 p_ptr->update |= (PU_FLOW);
1510                         }
1511                         
1512                         /* Sound */
1513                         if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1514
1515                         /* Remove the feature */
1516                         cave_alter_feat(y, x, FF_TUNNEL);
1517
1518                         chg_virtue(V_DILIGENCE, 1);
1519                         chg_virtue(V_NATURE, -1);
1520                 }
1521
1522                 /* Keep trying */
1523                 else
1524                 {
1525                         if (tree)
1526                         {
1527                                 /* We may continue chopping */
1528                                 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
1529                                 /* Occasional Search XXX XXX */
1530                                 if (randint0(100) < 25) search();
1531                         }
1532                         else
1533                         {
1534                                 /* We may continue tunelling */
1535                                 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
1536                         }
1537
1538                         more = TRUE;
1539                 }
1540         }
1541
1542         if (is_hidden_door(c_ptr))
1543         {
1544                 /* Occasional Search XXX XXX */
1545                 if (randint0(100) < 25) search();
1546         }
1547
1548         /* Result */
1549         return more;
1550 }
1551
1552
1553 /*!
1554  * @brief 「掘る」動作コマンドのメインルーチン /
1555  * Tunnels through "walls" (including rubble and closed doors)
1556  * @return なし
1557  * @details
1558  * <pre>
1559  * Note that you must tunnel in order to hit invisible monsters
1560  * in walls, though moving into walls still takes a turn anyway.
1561  *
1562  * Digging is very difficult without a "digger" weapon, but can be
1563  * accomplished by strong players using heavy weapons.
1564  * </pre>
1565  */
1566 void do_cmd_tunnel(void)
1567 {
1568         int                     y, x, dir;
1569
1570         cave_type       *c_ptr;
1571         s16b feat;
1572
1573         bool            more = FALSE;
1574
1575
1576         if (p_ptr->special_defense & KATA_MUSOU)
1577         {
1578                 set_action(ACTION_NONE);
1579         }
1580
1581         /* Allow repeated command */
1582         if (command_arg)
1583         {
1584                 /* Set repeat count */
1585                 command_rep = command_arg - 1;
1586
1587                 /* Redraw the state */
1588                 p_ptr->redraw |= (PR_STATE);
1589
1590                 /* Cancel the arg */
1591                 command_arg = 0;
1592         }
1593
1594         /* Get a direction to tunnel, or Abort */
1595         if (get_rep_dir(&dir,FALSE))
1596         {
1597                 /* Get location */
1598                 y = p_ptr->y + ddy[dir];
1599                 x = p_ptr->x + ddx[dir];
1600
1601                 /* Get grid */
1602                 c_ptr = &cave[y][x];
1603
1604                 /* Feature code (applying "mimic" field) */
1605                 feat = get_feat_mimic(c_ptr);
1606
1607                 /* No tunnelling through doors */
1608                 if (have_flag(f_info[feat].flags, FF_DOOR))
1609                 {
1610                         /* Message */
1611                         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
1612                 }
1613
1614                 /* No tunnelling through most features */
1615                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1616                 {
1617                         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
1618                 }
1619
1620                 /* A monster is in the way */
1621                 else if (c_ptr->m_idx)
1622                 {
1623                         /* Take a turn */
1624                         p_ptr->energy_use = 100;
1625
1626                         /* Message */
1627                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1628
1629                         /* Attack */
1630                         py_attack(y, x, 0);
1631                 }
1632
1633                 /* Try digging */
1634                 else
1635                 {
1636                         /* Tunnel through walls */
1637                         more = do_cmd_tunnel_aux(y, x);
1638                 }
1639         }
1640
1641         /* Cancel repetition unless we can continue */
1642         if (!more) disturb(0, 0);
1643 }
1644
1645
1646 #ifdef ALLOW_EASY_OPEN /* TNB */
1647
1648 /*!
1649  * @brief 移動処理による簡易な「開く」処理 /
1650  * easy_open_door --
1651  * @return 開く処理が実際に試みられた場合TRUEを返す
1652  * @details
1653  * <pre>
1654  *      If there is a jammed/closed/locked door at the given location,
1655  *      then attempt to unlock/open it. Return TRUE if an attempt was
1656  *      made (successful or not), otherwise return FALSE.
1657  *
1658  *      The code here should be nearly identical to that in
1659  *      do_cmd_open_test() and do_cmd_open_aux().
1660  * </pre>
1661  */
1662 bool easy_open_door(int y, int x)
1663 {
1664         int i, j;
1665
1666         cave_type *c_ptr = &cave[y][x];
1667         feature_type *f_ptr = &f_info[c_ptr->feat];
1668
1669         /* Must be a closed door */
1670         if (!is_closed_door(c_ptr->feat))
1671         {
1672                 /* Nope */
1673                 return (FALSE);
1674         }
1675
1676         /* Jammed door */
1677         if (!have_flag(f_ptr->flags, FF_OPEN))
1678         {
1679                 /* Stuck */
1680                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(c_ptr)].name);
1681
1682         }
1683
1684         /* Locked door */
1685         else if (f_ptr->power)
1686         {
1687                 /* Disarm factor */
1688                 i = p_ptr->skill_dis;
1689
1690                 /* Penalize some conditions */
1691                 if (p_ptr->blind || no_lite()) i = i / 10;
1692                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1693
1694                 /* Extract the lock power */
1695                 j = f_ptr->power;
1696
1697                 /* Extract the difficulty XXX XXX XXX */
1698                 j = i - (j * 4);
1699
1700                 /* Always have a small chance of success */
1701                 if (j < 2) j = 2;
1702
1703                 /* Success */
1704                 if (randint0(100) < j)
1705                 {
1706                         /* Message */
1707                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1708
1709                         /* Open the door */
1710                         cave_alter_feat(y, x, FF_OPEN);
1711
1712                         /* Sound */
1713                         sound(SOUND_OPENDOOR);
1714
1715                         /* Experience */
1716                         gain_exp(1);
1717                 }
1718
1719                 /* Failure */
1720                 else
1721                 {
1722                         /* Failure */
1723                         if (flush_failure) flush();
1724
1725                         /* Message */
1726                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1727
1728                 }
1729         }
1730
1731         /* Closed door */
1732         else
1733         {
1734                 /* Open the door */
1735                 cave_alter_feat(y, x, FF_OPEN);
1736
1737                 /* Sound */
1738                 sound(SOUND_OPENDOOR);
1739         }
1740
1741         /* Result */
1742         return (TRUE);
1743 }
1744
1745 #endif /* ALLOW_EASY_OPEN -- TNB */
1746
1747
1748 /*!
1749  * @brief 箱のトラップを解除するコマンドのメインルーチン /
1750  * Perform the basic "disarm" command
1751  * @param y 解除を行うマスのY座標
1752  * @param x 解除を行うマスのX座標
1753  * @param o_idx 箱のオブジェクトID
1754  * @return ターンを消費する処理が行われた場合TRUEを返す
1755  * @details
1756  * <pre>
1757  * Assume destination is a visible trap
1758  * Assume there is no monster blocking the destination
1759  * Returns TRUE if repeated commands may continue
1760  * </pre>
1761  */
1762 static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
1763 {
1764         int i, j;
1765
1766         bool more = FALSE;
1767
1768         object_type *o_ptr = &o_list[o_idx];
1769
1770
1771         /* Take a turn */
1772         p_ptr->energy_use = 100;
1773
1774         /* Get the "disarm" factor */
1775         i = p_ptr->skill_dis;
1776
1777         /* Penalize some conditions */
1778         if (p_ptr->blind || no_lite()) i = i / 10;
1779         if (p_ptr->confused || p_ptr->image) i = i / 10;
1780
1781         /* Extract the difficulty */
1782         j = i - o_ptr->pval;
1783
1784         /* Always have a small chance of success */
1785         if (j < 2) j = 2;
1786
1787         /* Must find the trap first. */
1788         if (!object_is_known(o_ptr))
1789         {
1790                 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
1791
1792         }
1793
1794         /* Already disarmed/unlocked */
1795         else if (o_ptr->pval <= 0)
1796         {
1797                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1798         }
1799
1800         /* No traps to find. */
1801         else if (!chest_traps[o_ptr->pval])
1802         {
1803                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1804         }
1805
1806         /* Success (get a lot of experience) */
1807         else if (randint0(100) < j)
1808         {
1809                 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
1810                 gain_exp(o_ptr->pval);
1811                 o_ptr->pval = (0 - o_ptr->pval);
1812         }
1813
1814         /* Failure -- Keep trying */
1815         else if ((i > 5) && (randint1(i) > 5))
1816         {
1817                 /* We may keep trying */
1818                 more = TRUE;
1819                 if (flush_failure) flush();
1820                 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
1821         }
1822
1823         /* Failure -- Set off the trap */
1824         else
1825         {
1826                 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
1827                 sound(SOUND_FAIL);
1828                 chest_trap(y, x, o_idx);
1829         }
1830
1831         /* Result */
1832         return (more);
1833 }
1834
1835
1836 /*!
1837  * @brief 箱のトラップを解除するコマンドのサブルーチン /
1838  * Perform the basic "disarm" command
1839  * @param y 解除を行うマスのY座標
1840  * @param x 解除を行うマスのX座標
1841  * @param dir プレイヤーからみた方向ID
1842  * @return ターンを消費する処理が行われた場合TRUEを返す
1843  * @details
1844  * <pre>
1845  * Assume destination is a visible trap
1846  * Assume there is no monster blocking the destination
1847  * Returns TRUE if repeated commands may continue
1848  * </pre>
1849  */
1850 #ifdef ALLOW_EASY_DISARM /* TNB */
1851
1852 bool do_cmd_disarm_aux(int y, int x, int dir)
1853
1854 #else /* ALLOW_EASY_DISARM -- TNB */
1855
1856 static bool do_cmd_disarm_aux(int y, int x, int dir)
1857
1858 #endif /* ALLOW_EASY_DISARM -- TNB */
1859 {
1860         /* Get grid and contents */
1861         cave_type *c_ptr = &cave[y][x];
1862
1863         /* Get feature */
1864         feature_type *f_ptr = &f_info[c_ptr->feat];
1865
1866         /* Access trap name */
1867         cptr name = (f_name + f_ptr->name);
1868
1869         /* Extract trap "power" */
1870         int power = f_ptr->power;
1871
1872         bool more = FALSE;
1873
1874         /* Get the "disarm" factor */
1875         int i = p_ptr->skill_dis;
1876
1877         int j;
1878
1879         /* Take a turn */
1880         p_ptr->energy_use = 100;
1881
1882         /* Penalize some conditions */
1883         if (p_ptr->blind || no_lite()) i = i / 10;
1884         if (p_ptr->confused || p_ptr->image) i = i / 10;
1885
1886         /* Extract the difficulty */
1887         j = i - power;
1888
1889         /* Always have a small chance of success */
1890         if (j < 2) j = 2;
1891
1892         /* Success */
1893         if (randint0(100) < j)
1894         {
1895                 /* Message */
1896                 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
1897                 
1898                 /* Reward */
1899                 gain_exp(power);
1900
1901                 /* Remove the trap */
1902                 cave_alter_feat(y, x, FF_DISARM);
1903
1904 #ifdef ALLOW_EASY_DISARM /* TNB */
1905
1906                 /* Move the player onto the trap */
1907                 move_player(dir, easy_disarm, FALSE);
1908
1909 #else /* ALLOW_EASY_DISARM -- TNB */
1910
1911                 /* move the player onto the trap grid */
1912                 move_player(dir, FALSE, FALSE);
1913
1914 #endif /* ALLOW_EASY_DISARM -- TNB */
1915         }
1916
1917         /* Failure -- Keep trying */
1918         else if ((i > 5) && (randint1(i) > 5))
1919         {
1920                 /* Failure */
1921                 if (flush_failure) flush();
1922
1923                 /* Message */
1924                 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
1925
1926                 /* We may keep trying */
1927                 more = TRUE;
1928         }
1929
1930         /* Failure -- Set off the trap */
1931         else
1932         {
1933                 /* Message */
1934                 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
1935
1936 #ifdef ALLOW_EASY_DISARM /* TNB */
1937
1938                 /* Move the player onto the trap */
1939                 move_player(dir, easy_disarm, FALSE);
1940
1941 #else /* ALLOW_EASY_DISARM -- TNB */
1942
1943                 /* Move the player onto the trap */
1944                 move_player(dir, FALSE, FALSE);
1945
1946 #endif /* ALLOW_EASY_DISARM -- TNB */
1947         }
1948
1949         /* Result */
1950         return (more);
1951 }
1952
1953
1954 /*!
1955  * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
1956  * Disarms a trap, or chest
1957  * @return なし
1958  */
1959 void do_cmd_disarm(void)
1960 {
1961         POSITION y, x;
1962         DIRECTION dir;
1963         s16b o_idx;
1964
1965         bool more = FALSE;
1966
1967         if (p_ptr->special_defense & KATA_MUSOU)
1968         {
1969                 set_action(ACTION_NONE);
1970         }
1971
1972 #ifdef ALLOW_EASY_DISARM /* TNB */
1973
1974         /* Option: Pick a direction */
1975         if (easy_disarm)
1976         {
1977                 int num_traps, num_chests;
1978
1979                 /* Count visible traps */
1980                 num_traps = count_dt(&y, &x, is_trap, TRUE);
1981
1982                 /* Count chests (trapped) */
1983                 num_chests = count_chests(&y, &x, TRUE);
1984
1985                 /* See if only one target */
1986                 if (num_traps || num_chests)
1987                 {
1988                         bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
1989                         if (!too_many) command_dir = coords_to_dir(y, x);
1990                 }
1991         }
1992
1993 #endif /* ALLOW_EASY_DISARM -- TNB */
1994
1995         /* Allow repeated command */
1996         if (command_arg)
1997         {
1998                 /* Set repeat count */
1999                 command_rep = command_arg - 1;
2000
2001                 /* Redraw the state */
2002                 p_ptr->redraw |= (PR_STATE);
2003
2004                 /* Cancel the arg */
2005                 command_arg = 0;
2006         }
2007
2008         /* Get a direction (or abort) */
2009         if (get_rep_dir(&dir,TRUE))
2010         {
2011                 cave_type *c_ptr;
2012                 s16b feat;
2013
2014                 /* Get location */
2015                 y = p_ptr->y + ddy[dir];
2016                 x = p_ptr->x + ddx[dir];
2017
2018                 /* Get grid and contents */
2019                 c_ptr = &cave[y][x];
2020
2021                 /* Feature code (applying "mimic" field) */
2022                 feat = get_feat_mimic(c_ptr);
2023
2024                 /* Check for chests */
2025                 o_idx = chest_check(y, x, TRUE);
2026
2027                 /* Disarm a trap */
2028                 if (!is_trap(feat) && !o_idx)
2029                 {
2030                         /* Message */
2031                         msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
2032                 }
2033
2034                 /* Monster in the way */
2035                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
2036                 {
2037                         /* Message */
2038                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2039
2040                         /* Attack */
2041                         py_attack(y, x, 0);
2042                 }
2043
2044                 /* Disarm chest */
2045                 else if (o_idx)
2046                 {
2047                         /* Disarm the chest */
2048                         more = do_cmd_disarm_chest(y, x, o_idx);
2049                 }
2050
2051                 /* Disarm trap */
2052                 else
2053                 {
2054                         /* Disarm the trap */
2055                         more = do_cmd_disarm_aux(y, x, dir);
2056                 }
2057         }
2058
2059         /* Cancel repeat unless told not to */
2060         if (!more) disturb(0, 0);
2061 }
2062
2063
2064 /*!
2065  * @brief 「打ち破る」動作コマンドのサブルーチン /
2066  * Perform the basic "bash" command
2067  * @param y 対象を行うマスのY座標
2068  * @param x 対象を行うマスのX座標
2069  * @param dir プレイヤーから見たターゲットの方角ID
2070  * @return 実際に処理が行われた場合TRUEを返す。
2071  * @details
2072  * <pre>
2073  * Assume destination is a closed/locked/jammed door
2074  * Assume there is no monster blocking the destination
2075  * Returns TRUE if repeated commands may continue
2076  * </pre>
2077  */
2078 static bool do_cmd_bash_aux(int y, int x, int dir)
2079 {
2080         /* Get grid */
2081         cave_type       *c_ptr = &cave[y][x];
2082
2083         /* Get feature */
2084         feature_type *f_ptr = &f_info[c_ptr->feat];
2085
2086         /* Hack -- Bash power based on strength */
2087         /* (Ranges from 3 to 20 to 100 to 200) */
2088         int bash = adj_str_blow[p_ptr->stat_ind[A_STR]];
2089
2090         /* Extract door power */
2091         int temp = f_ptr->power;
2092
2093         bool            more = FALSE;
2094
2095         cptr name = f_name + f_info[get_feat_mimic(c_ptr)].name;
2096
2097         /* Take a turn */
2098         p_ptr->energy_use = 100;
2099
2100         /* Message */
2101         msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
2102
2103         /* Compare bash power to door power XXX XXX XXX */
2104         temp = (bash - (temp * 10));
2105
2106         if (p_ptr->pclass == CLASS_BERSERKER) temp *= 2;
2107
2108         /* Hack -- always have a chance */
2109         if (temp < 1) temp = 1;
2110
2111         /* Hack -- attempt to bash down the door */
2112         if (randint0(100) < temp)
2113         {
2114                 /* Message */
2115                 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
2116
2117                 /* Sound */
2118                 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
2119
2120                 /* Break down the door */
2121                 if ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
2122                 {
2123                         cave_alter_feat(y, x, FF_BASH);
2124                 }
2125
2126                 /* Open the door */
2127                 else
2128                 {
2129                         cave_alter_feat(y, x, FF_OPEN);
2130                 }
2131
2132                 /* Hack -- Fall through the door */
2133                 move_player(dir, FALSE, FALSE);
2134         }
2135
2136         /* Saving throw against stun */
2137         else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
2138                  p_ptr->lev)
2139         {
2140                 /* Message */
2141                 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
2142
2143                 /* Allow repeated bashing */
2144                 more = TRUE;
2145         }
2146
2147         /* High dexterity yields coolness */
2148         else
2149         {
2150                 /* Message */
2151                 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
2152
2153                 /* Hack -- Lose balance ala paralysis */
2154                 (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
2155         }
2156
2157         /* Result */
2158         return (more);
2159 }
2160
2161
2162 /*!
2163  * @brief 「打ち破る」動作コマンドのメインルーチン /
2164  * Bash open a door, success based on character strength
2165  * @return なし
2166  * @details
2167  * <pre>
2168  * For a closed door, pval is positive if locked; negative if stuck.
2169  *
2170  * For an open door, pval is positive for a broken door.
2171  *
2172  * A closed door can be opened - harder if locked. Any door might be
2173  * bashed open (and thereby broken). Bashing a door is (potentially)
2174  * faster! You move into the door way. To open a stuck door, it must
2175  * be bashed. A closed door can be jammed (see do_cmd_spike()).
2176  *
2177  * Creatures can also open or bash doors, see elsewhere.
2178  * </pre>
2179  */
2180 void do_cmd_bash(void)
2181 {
2182         int                     y, x, dir;
2183
2184         cave_type       *c_ptr;
2185
2186         bool            more = FALSE;
2187
2188
2189         if (p_ptr->special_defense & KATA_MUSOU)
2190         {
2191                 set_action(ACTION_NONE);
2192         }
2193
2194         /* Allow repeated command */
2195         if (command_arg)
2196         {
2197                 /* Set repeat count */
2198                 command_rep = command_arg - 1;
2199
2200                 /* Redraw the state */
2201                 p_ptr->redraw |= (PR_STATE);
2202
2203                 /* Cancel the arg */
2204                 command_arg = 0;
2205         }
2206
2207         /* Get a "repeated" direction */
2208         if (get_rep_dir(&dir,FALSE))
2209         {
2210                 s16b feat;
2211
2212                 /* Bash location */
2213                 y = p_ptr->y + ddy[dir];
2214                 x = p_ptr->x + ddx[dir];
2215
2216                 /* Get grid */
2217                 c_ptr = &cave[y][x];
2218
2219                 /* Feature code (applying "mimic" field) */
2220                 feat = get_feat_mimic(c_ptr);
2221
2222                 /* Nothing useful */
2223                 if (!have_flag(f_info[feat].flags, FF_BASH))
2224                 {
2225                         /* Message */
2226                         msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
2227                 }
2228
2229                 /* Monster in the way */
2230                 else if (c_ptr->m_idx)
2231                 {
2232                         /* Take a turn */
2233                         p_ptr->energy_use = 100;
2234
2235                         /* Message */
2236                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2237
2238                         /* Attack */
2239                         py_attack(y, x, 0);
2240                 }
2241
2242                 /* Bash a closed door */
2243                 else
2244                 {
2245                         /* Bash the door */
2246                         more = do_cmd_bash_aux(y, x, dir);
2247                 }
2248         }
2249
2250         /* Unless valid action taken, cancel bash */
2251         if (!more) disturb(0, 0);
2252 }
2253
2254
2255 /*!
2256  * @brief 特定のマスに影響を及ぼすための汎用的コマンド
2257  * @return なし
2258  * @details
2259  * <pre>
2260  * Manipulate an adjacent grid in some way
2261  *
2262  * Attack monsters, tunnel through walls, disarm traps, open doors.
2263  *
2264  * Consider confusion XXX XXX XXX
2265  *
2266  * This command must always take a turn, to prevent free detection
2267  * of invisible monsters.
2268  * </pre>
2269  */
2270 void do_cmd_alter(void)
2271 {
2272         int                     y, x, dir;
2273
2274         cave_type       *c_ptr;
2275
2276         bool            more = FALSE;
2277
2278
2279         if (p_ptr->special_defense & KATA_MUSOU)
2280         {
2281                 set_action(ACTION_NONE);
2282         }
2283
2284         /* Allow repeated command */
2285         if (command_arg)
2286         {
2287                 /* Set repeat count */
2288                 command_rep = command_arg - 1;
2289
2290                 /* Redraw the state */
2291                 p_ptr->redraw |= (PR_STATE);
2292
2293                 /* Cancel the arg */
2294                 command_arg = 0;
2295         }
2296
2297         /* Get a direction */
2298         if (get_rep_dir(&dir,TRUE))
2299         {
2300                 s16b feat;
2301                 feature_type *f_ptr;
2302
2303                 /* Get location */
2304                 y = p_ptr->y + ddy[dir];
2305                 x = p_ptr->x + ddx[dir];
2306
2307                 /* Get grid */
2308                 c_ptr = &cave[y][x];
2309
2310                 /* Feature code (applying "mimic" field) */
2311                 feat = get_feat_mimic(c_ptr);
2312                 f_ptr = &f_info[feat];
2313
2314                 /* Take a turn */
2315                 p_ptr->energy_use = 100;
2316
2317                 /* Attack monsters */
2318                 if (c_ptr->m_idx)
2319                 {
2320                         /* Attack */
2321                         py_attack(y, x, 0);
2322                 }
2323
2324                 /* Locked doors */
2325                 else if (have_flag(f_ptr->flags, FF_OPEN))
2326                 {
2327                         more = do_cmd_open_aux(y, x);
2328                 }
2329
2330                 /* Bash jammed doors */
2331                 else if (have_flag(f_ptr->flags, FF_BASH))
2332                 {
2333                         more = do_cmd_bash_aux(y, x, dir);
2334                 }
2335
2336                 /* Tunnel through walls */
2337                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
2338                 {
2339                         more = do_cmd_tunnel_aux(y, x);
2340                 }
2341
2342                 /* Close open doors */
2343                 else if (have_flag(f_ptr->flags, FF_CLOSE))
2344                 {
2345                         more = do_cmd_close_aux(y, x);
2346                 }
2347
2348                 /* Disarm traps */
2349                 else if (have_flag(f_ptr->flags, FF_DISARM))
2350                 {
2351                         more = do_cmd_disarm_aux(y, x, dir);
2352                 }
2353
2354                 /* Oops */
2355                 else
2356                 {
2357                         /* Oops */
2358                         msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
2359                 }
2360         }
2361
2362         /* Cancel repetition unless we can continue */
2363         if (!more) disturb(0, 0);
2364 }
2365
2366
2367
2368 /*!
2369  * @brief 「くさびを打つ」ために必要なオブジェクトがあるかどうかの判定を返す /
2370  * Find the index of some "spikes", if possible.
2371  * @param ip くさびとして打てるオブジェクトのID
2372  * @return オブジェクトがある場合TRUEを返す
2373  * @details
2374  * <pre>
2375  * XXX XXX XXX Let user choose a pile of spikes, perhaps?
2376  * </pre>
2377  */
2378 static bool get_spike(int *ip)
2379 {
2380         int i;
2381
2382         /* Check every item in the pack */
2383         for (i = 0; i < INVEN_PACK; i++)
2384         {
2385                 object_type *o_ptr = &inventory[i];
2386
2387                 /* Skip non-objects */
2388                 if (!o_ptr->k_idx) continue;
2389
2390                 /* Check the "tval" code */
2391                 if (o_ptr->tval == TV_SPIKE)
2392                 {
2393                         /* Save the spike index */
2394                         (*ip) = i;
2395
2396                         /* Success */
2397                         return (TRUE);
2398                 }
2399         }
2400
2401         /* Oops */
2402         return (FALSE);
2403 }
2404
2405
2406 /*!
2407  * @brief 「くさびを打つ」動作コマンドのメインルーチン /
2408  * Jam a closed door with a spike
2409  * @return なし
2410  * @details
2411  * <pre>
2412  * This command may NOT be repeated
2413  * </pre>
2414  */
2415 void do_cmd_spike(void)
2416 {
2417         int dir;
2418
2419         if (p_ptr->special_defense & KATA_MUSOU)
2420         {
2421                 set_action(ACTION_NONE);
2422         }
2423
2424         /* Get a "repeated" direction */
2425         if (get_rep_dir(&dir,FALSE))
2426         {
2427                 int y, x, item;
2428                 cave_type *c_ptr;
2429                 s16b feat;
2430
2431                 /* Get location */
2432                 y = p_ptr->y + ddy[dir];
2433                 x = p_ptr->x + ddx[dir];
2434
2435                 /* Get grid and contents */
2436                 c_ptr = &cave[y][x];
2437
2438                 /* Feature code (applying "mimic" field) */
2439                 feat = get_feat_mimic(c_ptr);
2440
2441                 /* Require closed door */
2442                 if (!have_flag(f_info[feat].flags, FF_SPIKE))
2443                 {
2444                         /* Message */
2445                         msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
2446                 }
2447
2448                 /* Get a spike */
2449                 else if (!get_spike(&item))
2450                 {
2451                         /* Message */
2452                         msg_print(_("くさびを持っていない!", "You have no spikes!"));
2453                 }
2454
2455                 /* Is a monster in the way? */
2456                 else if (c_ptr->m_idx)
2457                 {
2458                         /* Take a turn */
2459                         p_ptr->energy_use = 100;
2460
2461                         /* Message */
2462                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2463
2464                         /* Attack */
2465                         py_attack(y, x, 0);
2466                 }
2467
2468                 /* Go for it */
2469                 else
2470                 {
2471                         /* Take a turn */
2472                         p_ptr->energy_use = 100;
2473
2474                         /* Successful jamming */
2475                         msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_name + f_info[feat].name);
2476                         cave_alter_feat(y, x, FF_SPIKE);
2477
2478                         /* Use up, and describe, a single spike, from the bottom */
2479                         inven_item_increase(item, -1);
2480                         inven_item_describe(item);
2481                         inven_item_optimize(item);
2482                 }
2483         }
2484 }
2485
2486
2487
2488 /*!
2489  * @brief 「歩く」動作コマンドのメインルーチン /
2490  * Support code for the "Walk" and "Jump" commands
2491  * @param pickup アイテムの自動拾いを行うならTRUE
2492  * @return なし
2493  */
2494 void do_cmd_walk(bool pickup)
2495 {
2496         int dir;
2497
2498         bool more = FALSE;
2499
2500
2501         /* Allow repeated command */
2502         if (command_arg)
2503         {
2504                 /* Set repeat count */
2505                 command_rep = command_arg - 1;
2506
2507                 /* Redraw the state */
2508                 p_ptr->redraw |= (PR_STATE);
2509
2510                 /* Cancel the arg */
2511                 command_arg = 0;
2512         }
2513
2514         /* Get a "repeated" direction */
2515         if (get_rep_dir(&dir,FALSE))
2516         {
2517                 /* Take a turn */
2518                 p_ptr->energy_use = 100;
2519
2520                 if ((dir != 5) && (p_ptr->special_defense & KATA_MUSOU))
2521                 {
2522                         set_action(ACTION_NONE);
2523                 }
2524
2525                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2526                 if (p_ptr->wild_mode) p_ptr->energy_use *= ((MAX_HGT + MAX_WID) / 2);
2527                 if (p_ptr->action == ACTION_HAYAGAKE) p_ptr->energy_use = p_ptr->energy_use * (45-(p_ptr->lev/2)) / 100;
2528
2529                 /* Actually move the character */
2530                 move_player(dir, pickup, FALSE);
2531
2532                 /* Allow more walking */
2533                 more = TRUE;
2534         }
2535
2536         /* Hack again -- Is there a special encounter ??? */
2537         if (p_ptr->wild_mode && !cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_TOWN))
2538         {
2539                 int tmp = 120 + p_ptr->lev*10 - wilderness[p_ptr->y][p_ptr->x].level + 5;
2540                 if (tmp < 1) 
2541                         tmp = 1;
2542                 if (((wilderness[p_ptr->y][p_ptr->x].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
2543                 {
2544                         /* Inform the player of his horrible fate :=) */
2545                         msg_print(_("襲撃だ!", "You are ambushed !"));
2546
2547                         /* Go into large wilderness view */
2548                         p_ptr->oldpy = randint1(MAX_HGT-2);
2549                         p_ptr->oldpx = randint1(MAX_WID-2);
2550                         change_wild_mode();
2551
2552                         /* Give first move to monsters */
2553                         p_ptr->energy_use = 100;
2554
2555                         /* HACk -- set the encouter flag for the wilderness generation */
2556                         generate_encounter = TRUE;
2557                 }
2558         }
2559
2560         /* Cancel repeat unless we may continue */
2561         if (!more) disturb(0, 0);
2562 }
2563
2564
2565 /*!
2566  * @brief 「走る」動作コマンドのメインルーチン /
2567  * Start running.
2568  * @return なし
2569  */
2570 void do_cmd_run(void)
2571 {
2572         int dir;
2573
2574         /* Hack -- no running when confused */
2575         if (p_ptr->confused)
2576         {
2577                 msg_print(_("混乱していて走れない!", "You are too confused!"));
2578                 return;
2579         }
2580
2581         if (p_ptr->special_defense & KATA_MUSOU)
2582         {
2583                 set_action(ACTION_NONE);
2584         }
2585
2586         /* Get a "repeated" direction */
2587         if (get_rep_dir(&dir,FALSE))
2588         {
2589                 /* Hack -- Set the run counter */
2590                 running = (command_arg ? command_arg : 1000);
2591
2592                 /* First step */
2593                 run_step(dir);
2594         }
2595 }
2596
2597
2598 /*!
2599  * @brief 「留まる」動作コマンドのメインルーチン /
2600  * Stay still.  Search.  Enter stores.
2601  * Pick up treasure if "pickup" is true.
2602  * @param pickup アイテムの自動拾いを行うならTRUE
2603  * @return なし
2604  */
2605 void do_cmd_stay(bool pickup)
2606 {
2607         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2608
2609         /* Allow repeated command */
2610         if (command_arg)
2611         {
2612                 /* Set repeat count */
2613                 command_rep = command_arg - 1;
2614
2615                 /* Redraw the state */
2616                 p_ptr->redraw |= (PR_STATE);
2617
2618                 /* Cancel the arg */
2619                 command_arg = 0;
2620         }
2621
2622         /* Take a turn */
2623         p_ptr->energy_use = 100;
2624
2625         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2626         (void)move_player_effect(p_ptr->y, p_ptr->x, mpe_mode);
2627 }
2628
2629
2630 /*!
2631  * @brief 「休む」動作コマンドのメインルーチン /
2632  * Resting allows a player to safely restore his hp     -RAK-
2633  * @return なし
2634  */
2635 void do_cmd_rest(void)
2636 {
2637
2638         set_action(ACTION_NONE);
2639
2640         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] || p_ptr->magic_num1[1]))
2641         {
2642                 stop_singing();
2643         }
2644
2645         /* Hex */
2646         if (hex_spelling_any()) stop_hex_spell_all();
2647
2648         /* Prompt for time if needed */
2649         if (command_arg <= 0)
2650         {
2651                 cptr p = _("休憩 (0-9999, '*' で HP/MP全快, '&' で必要なだけ): ", 
2652                                    "Rest (0-9999, '*' for HP/SP, '&' as needed): ");
2653
2654
2655                 char out_val[80];
2656
2657                 /* Default */
2658                 strcpy(out_val, "&");
2659
2660                 /* Ask for duration */
2661                 if (!get_string(p, out_val, 4)) return;
2662
2663                 /* Rest until done */
2664                 if (out_val[0] == '&')
2665                 {
2666                         command_arg = (-2);
2667                 }
2668
2669                 /* Rest a lot */
2670                 else if (out_val[0] == '*')
2671                 {
2672                         command_arg = (-1);
2673                 }
2674
2675                 /* Rest some */
2676                 else
2677                 {
2678                         command_arg = (COMMAND_ARG)atoi(out_val);
2679                         if (command_arg <= 0) return;
2680                 }
2681         }
2682
2683
2684         /* Paranoia */
2685         if (command_arg > 9999) command_arg = 9999;
2686
2687         if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
2688
2689         /* Take a turn XXX XXX XXX (?) */
2690         p_ptr->energy_use = 100;
2691
2692         /* The sin of sloth */
2693         if (command_arg > 100)
2694                 chg_virtue(V_DILIGENCE, -1);
2695         
2696         /* Why are you sleeping when there's no need?  WAKE UP!*/
2697         if ((p_ptr->chp == p_ptr->mhp) &&
2698             (p_ptr->csp == p_ptr->msp) &&
2699             !p_ptr->blind && !p_ptr->confused &&
2700             !p_ptr->poisoned && !p_ptr->afraid &&
2701             !p_ptr->stun && !p_ptr->cut &&
2702             !p_ptr->slow && !p_ptr->paralyzed &&
2703             !p_ptr->image && !p_ptr->word_recall &&
2704             !p_ptr->alter_reality)
2705                         chg_virtue(V_DILIGENCE, -1);
2706
2707         /* Save the rest code */
2708         resting = command_arg;
2709         p_ptr->action = ACTION_REST;
2710
2711         /* Recalculate bonuses */
2712         p_ptr->update |= (PU_BONUS);
2713
2714         /* Redraw the state */
2715         p_ptr->redraw |= (PR_STATE);
2716
2717         /* Handle stuff */
2718         handle_stuff();
2719
2720         /* Refresh */
2721         Term_fresh();
2722 }
2723
2724
2725 /*!
2726  * @brief 矢弾を射撃した場合の破損確率を返す /
2727  * Determines the odds of an object breaking when thrown at a monster
2728  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2729  * @return 破損確率(%)
2730  * @details
2731  * Note that artifacts never break, see the "drop_near()" function.
2732  */
2733 static int breakage_chance(object_type *o_ptr)
2734 {
2735         int archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (p_ptr->lev-1)/7 + 4: 0);
2736
2737         /* Examine the snipe type */
2738         if (snipe_type)
2739         {
2740                 if (snipe_type == SP_KILL_WALL) return (100);
2741                 if (snipe_type == SP_EXPLODE) return (100);
2742                 if (snipe_type == SP_PIERCE) return (100);
2743                 if (snipe_type == SP_FINAL) return (100);
2744                 if (snipe_type == SP_NEEDLE) return (100);
2745                 if (snipe_type == SP_EVILNESS) return (40);
2746                 if (snipe_type == SP_HOLYNESS) return (40);
2747         }
2748
2749         /* Examine the item type */
2750         switch (o_ptr->tval)
2751         {
2752                 /* Always break */
2753                 case TV_FLASK:
2754                 case TV_POTION:
2755                 case TV_BOTTLE:
2756                 case TV_FOOD:
2757                 case TV_JUNK:
2758                         return (100);
2759
2760                 /* Often break */
2761                 case TV_LITE:
2762                 case TV_SCROLL:
2763                 case TV_SKELETON:
2764                         return (50);
2765
2766                 /* Sometimes break */
2767                 case TV_WAND:
2768                 case TV_SPIKE:
2769                         return (25);
2770                 case TV_ARROW:
2771                         return (20 - archer_bonus * 2);
2772
2773                 /* Rarely break */
2774                 case TV_SHOT:
2775                 case TV_BOLT:
2776                         return (10 - archer_bonus);
2777                 default:
2778                         return (10);
2779         }
2780 }
2781
2782
2783 /*!
2784  * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
2785  * Determines the odds of an object breaking when thrown at a monster
2786  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2787  * @param tdam 計算途中のダメージ量
2788  * @param m_ptr 目標モンスターの構造体参照ポインタ
2789  * @return スレイ倍率をかけたダメージ量
2790  */
2791 static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
2792 {
2793         int mult = 10;
2794
2795         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2796
2797         u32b flgs[TR_FLAG_SIZE];
2798
2799         /* Extract the flags */
2800         object_flags(o_ptr, flgs);
2801
2802         /* Some "weapons" and "ammo" do extra damage */
2803         switch (o_ptr->tval)
2804         {
2805                 case TV_SHOT:
2806                 case TV_ARROW:
2807                 case TV_BOLT:
2808                 {
2809                         /* Slay Animal */
2810                         if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
2811                             (r_ptr->flags3 & RF3_ANIMAL))
2812                         {
2813                                 if (is_original_ap_and_seen(m_ptr))
2814                                 {
2815                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2816                                 }
2817
2818                                 if (mult < 17) mult = 17;
2819                         }
2820
2821                         /* Kill Animal */
2822                         if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
2823                             (r_ptr->flags3 & RF3_ANIMAL))
2824                         {
2825                                 if (is_original_ap_and_seen(m_ptr))
2826                                 {
2827                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2828                                 }
2829
2830                                 if (mult < 27) mult = 27;
2831                         }
2832
2833                         /* Slay Evil */
2834                         if ((have_flag(flgs, TR_SLAY_EVIL)) &&
2835                             (r_ptr->flags3 & RF3_EVIL))
2836                         {
2837                                 if (is_original_ap_and_seen(m_ptr))
2838                                 {
2839                                         r_ptr->r_flags3 |= RF3_EVIL;
2840                                 }
2841
2842                                 if (mult < 15) mult = 15;
2843                         }
2844
2845                         /* Kill Evil */
2846                         if ((have_flag(flgs, TR_KILL_EVIL)) &&
2847                             (r_ptr->flags3 & RF3_EVIL))
2848                         {
2849                                 if (is_original_ap_and_seen(m_ptr))
2850                                 {
2851                                         r_ptr->r_flags3 |= RF3_EVIL;
2852                                 }
2853
2854                                 if (mult < 25) mult = 25;
2855                         }
2856
2857                         /* Slay Human */
2858                         if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
2859                             (r_ptr->flags2 & RF2_HUMAN))
2860                         {
2861                                 if (is_original_ap_and_seen(m_ptr))
2862                                 {
2863                                         r_ptr->r_flags2 |= RF2_HUMAN;
2864                                 }
2865
2866                                 if (mult < 17) mult = 17;
2867                         }
2868
2869                         /* Kill Human */
2870                         if ((have_flag(flgs, TR_KILL_HUMAN)) &&
2871                             (r_ptr->flags2 & RF2_HUMAN))
2872                         {
2873                                 if (is_original_ap_and_seen(m_ptr))
2874                                 {
2875                                         r_ptr->r_flags2 |= RF2_HUMAN;
2876                                 }
2877
2878                                 if (mult < 27) mult = 27;
2879                         }
2880
2881                         /* Slay Undead */
2882                         if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
2883                             (r_ptr->flags3 & RF3_UNDEAD))
2884                         {
2885                                 if (is_original_ap_and_seen(m_ptr))
2886                                 {
2887                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2888                                 }
2889
2890                                 if (mult < 20) mult = 20;
2891                         }
2892
2893                         /* Kill Undead */
2894                         if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
2895                             (r_ptr->flags3 & RF3_UNDEAD))
2896                         {
2897                                 if (is_original_ap_and_seen(m_ptr))
2898                                 {
2899                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2900                                 }
2901
2902                                 if (mult < 30) mult = 30;
2903                         }
2904
2905                         /* Slay Demon */
2906                         if ((have_flag(flgs, TR_SLAY_DEMON)) &&
2907                             (r_ptr->flags3 & RF3_DEMON))
2908                         {
2909                                 if (is_original_ap_and_seen(m_ptr))
2910                                 {
2911                                         r_ptr->r_flags3 |= RF3_DEMON;
2912                                 }
2913
2914                                 if (mult < 20) mult = 20;
2915                         }
2916
2917                         /* Kill Demon */
2918                         if ((have_flag(flgs, TR_KILL_DEMON)) &&
2919                             (r_ptr->flags3 & RF3_DEMON))
2920                         {
2921                                 if (is_original_ap_and_seen(m_ptr))
2922                                 {
2923                                         r_ptr->r_flags3 |= RF3_DEMON;
2924                                 }
2925
2926                                 if (mult < 30) mult = 30;
2927                         }
2928
2929                         /* Slay Orc */
2930                         if ((have_flag(flgs, TR_SLAY_ORC)) &&
2931                             (r_ptr->flags3 & RF3_ORC))
2932                         {
2933                                 if (is_original_ap_and_seen(m_ptr))
2934                                 {
2935                                         r_ptr->r_flags3 |= RF3_ORC;
2936                                 }
2937
2938                                 if (mult < 20) mult = 20;
2939                         }
2940
2941                         /* Kill Orc */
2942                         if ((have_flag(flgs, TR_KILL_ORC)) &&
2943                             (r_ptr->flags3 & RF3_ORC))
2944                         {
2945                                 if (is_original_ap_and_seen(m_ptr))
2946                                 {
2947                                         r_ptr->r_flags3 |= RF3_ORC;
2948                                 }
2949
2950                                 if (mult < 30) mult = 30;
2951                         }
2952
2953                         /* Slay Troll */
2954                         if ((have_flag(flgs, TR_SLAY_TROLL)) &&
2955                             (r_ptr->flags3 & RF3_TROLL))
2956                         {
2957                                 if (is_original_ap_and_seen(m_ptr))
2958                                 {
2959                                         r_ptr->r_flags3 |= RF3_TROLL;
2960                                 }
2961
2962                                 if (mult < 20) mult = 20;
2963                         }
2964
2965                         /* Kill Troll */
2966                         if ((have_flag(flgs, TR_KILL_TROLL)) &&
2967                             (r_ptr->flags3 & RF3_TROLL))
2968                         {
2969                                 if (is_original_ap_and_seen(m_ptr))
2970                                 {
2971                                         r_ptr->r_flags3 |= RF3_TROLL;
2972                                 }
2973
2974                                 if (mult < 30) mult = 30;
2975                         }
2976
2977                         /* Slay Giant */
2978                         if ((have_flag(flgs, TR_SLAY_GIANT)) &&
2979                             (r_ptr->flags3 & RF3_GIANT))
2980                         {
2981                                 if (is_original_ap_and_seen(m_ptr))
2982                                 {
2983                                         r_ptr->r_flags3 |= RF3_GIANT;
2984                                 }
2985
2986                                 if (mult < 20) mult = 20;
2987                         }
2988
2989                         /* Kill Giant */
2990                         if ((have_flag(flgs, TR_KILL_GIANT)) &&
2991                             (r_ptr->flags3 & RF3_GIANT))
2992                         {
2993                                 if (is_original_ap_and_seen(m_ptr))
2994                                 {
2995                                         r_ptr->r_flags3 |= RF3_GIANT;
2996                                 }
2997
2998                                 if (mult < 30) mult = 30;
2999                         }
3000
3001                         /* Slay Dragon  */
3002                         if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
3003                             (r_ptr->flags3 & RF3_DRAGON))
3004                         {
3005                                 if (is_original_ap_and_seen(m_ptr))
3006                                 {
3007                                         r_ptr->r_flags3 |= RF3_DRAGON;
3008                                 }
3009
3010                                 if (mult < 20) mult = 20;
3011                         }
3012
3013                         /* Execute Dragon */
3014                         if ((have_flag(flgs, TR_KILL_DRAGON)) &&
3015                             (r_ptr->flags3 & RF3_DRAGON))
3016                         {
3017                                 if (is_original_ap_and_seen(m_ptr))
3018                                 {
3019                                         r_ptr->r_flags3 |= RF3_DRAGON;
3020                                 }
3021
3022                                 if (mult < 30) mult = 30;
3023
3024                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
3025                                     (m_ptr->r_idx == MON_SMAUG) &&
3026                                     (inventory[INVEN_BOW].name1 == ART_BARD))
3027                                         mult *= 5;
3028                         }
3029
3030                         /* Brand (Acid) */
3031                         if (have_flag(flgs, TR_BRAND_ACID))
3032                         {
3033                                 /* Notice immunity */
3034                                 if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
3035                                 {
3036                                         if (is_original_ap_and_seen(m_ptr))
3037                                         {
3038                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
3039                                         }
3040                                 }
3041
3042                                 /* Otherwise, take the damage */
3043                                 else
3044                                 {
3045                                         if (mult < 17) mult = 17;
3046                                 }
3047                         }
3048
3049                         /* Brand (Elec) */
3050                         if (have_flag(flgs, TR_BRAND_ELEC))
3051                         {
3052                                 /* Notice immunity */
3053                                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
3054                                 {
3055                                         if (is_original_ap_and_seen(m_ptr))
3056                                         {
3057                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
3058                                         }
3059                                 }
3060
3061                                 /* Otherwise, take the damage */
3062                                 else
3063                                 {
3064                                         if (mult < 17) mult = 17;
3065                                 }
3066                         }
3067
3068                         /* Brand (Fire) */
3069                         if (have_flag(flgs, TR_BRAND_FIRE))
3070                         {
3071                                 /* Notice immunity */
3072                                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
3073                                 {
3074                                         if (is_original_ap_and_seen(m_ptr))
3075                                         {
3076                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
3077                                         }
3078                                 }
3079
3080                                 /* Otherwise, take the damage */
3081                                 else
3082                                 {
3083                                         if (r_ptr->flags3 & RF3_HURT_FIRE)
3084                                         {
3085                                                 if (mult < 25) mult = 25;
3086                                                 if (is_original_ap_and_seen(m_ptr))
3087                                                 {
3088                                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
3089                                                 }
3090                                         }
3091                                         else if (mult < 17) mult = 17;
3092                                 }
3093                         }
3094
3095                         /* Brand (Cold) */
3096                         if (have_flag(flgs, TR_BRAND_COLD))
3097                         {
3098                                 /* Notice immunity */
3099                                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
3100                                 {
3101                                         if (is_original_ap_and_seen(m_ptr))
3102                                         {
3103                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
3104                                         }
3105                                 }
3106                                 /* Otherwise, take the damage */
3107                                 else
3108                                 {
3109                                         if (r_ptr->flags3 & RF3_HURT_COLD)
3110                                         {
3111                                                 if (mult < 25) mult = 25;
3112                                                 if (is_original_ap_and_seen(m_ptr))
3113                                                 {
3114                                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
3115                                                 }
3116                                         }
3117                                         else if (mult < 17) mult = 17;
3118                                 }
3119                         }
3120
3121                         /* Brand (Poison) */
3122                         if (have_flag(flgs, TR_BRAND_POIS))
3123                         {
3124                                 /* Notice immunity */
3125                                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
3126                                 {
3127                                         if (is_original_ap_and_seen(m_ptr))
3128                                         {
3129                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
3130                                         }
3131                                 }
3132
3133                                 /* Otherwise, take the damage */
3134                                 else
3135                                 {
3136                                         if (mult < 17) mult = 17;
3137                                 }
3138                         }
3139
3140                         if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
3141                         {
3142                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
3143                                 p_ptr->redraw |= (PR_MANA);
3144                                 mult = mult * 5 / 2;
3145                         }
3146                         break;
3147                 }
3148         }
3149
3150         /* Sniper */
3151         if (snipe_type) mult = tot_dam_aux_snipe(mult, m_ptr);
3152
3153         /* Return the total damage */
3154         return (tdam * mult / 10);
3155 }
3156
3157
3158 /*!
3159  * @brief 射撃処理のサブルーチン /
3160  * Fire an object from the pack or floor.
3161  * @param item 射撃するオブジェクトの所持ID
3162  * @param j_ptr 射撃武器のオブジェクト参照ポインタ
3163  * @return なし
3164  * @details
3165  * <pre>
3166  * You may only fire items that "match" your missile launcher.
3167  *
3168  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
3169  *
3170  * See "calc_bonuses()" for more calculations and such.
3171  *
3172  * Note that "firing" a missile is MUCH better than "throwing" it.
3173  *
3174  * Note: "unseen" monsters are very hard to hit.
3175  *
3176  * Objects are more likely to break if they "attempt" to hit a monster.
3177  *
3178  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
3179  *
3180  * The "extra shot" code works by decreasing the amount of energy
3181  * required to make each shot, spreading the shots out over time.
3182  *
3183  * Note that when firing missiles, the launcher multiplier is applied
3184  * after all the bonuses are added in, making multipliers very useful.
3185  *
3186  * Note that Bows of "Extra Might" get extra range and an extra bonus
3187  * for the damage multiplier.
3188  *
3189  * Note that Bows of "Extra Shots" give an extra shot.
3190  * </pre>
3191  */
3192 void do_cmd_fire_aux(int item, object_type *j_ptr)
3193 {
3194         int dir;
3195         int i, j, y, x, ny, nx, ty, tx, prev_y, prev_x;
3196         int tdam_base, tdis, thits, tmul;
3197         int bonus, chance;
3198         int cur_dis, visible;
3199
3200         object_type forge;
3201         object_type *q_ptr;
3202
3203         object_type *o_ptr;
3204
3205         bool hit_body = FALSE;
3206
3207         char o_name[MAX_NLEN];
3208
3209         u16b path_g[512];       /* For calcuration of path length */
3210
3211         int msec = delay_factor * delay_factor * delay_factor;
3212
3213         /* STICK TO */
3214         bool stick_to = FALSE;
3215
3216         /* Access the item (if in the pack) */
3217         if (item >= 0)
3218         {
3219                 o_ptr = &inventory[item];
3220         }
3221         else
3222         {
3223                 o_ptr = &o_list[0 - item];
3224         }
3225
3226         /* Sniper - Cannot shot a single arrow twice */
3227         if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) snipe_type = SP_NONE;
3228
3229         /* Describe the object */
3230         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
3231
3232         /* Use the proper number of shots */
3233         thits = p_ptr->num_fire;
3234
3235         /* Use a base distance */
3236         tdis = 10;
3237
3238         /* Base damage from thrown object plus launcher bonus */
3239         tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
3240
3241         /* Actually "fire" the object */
3242         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
3243         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3244                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
3245         else
3246                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
3247
3248         p_ptr->energy_use = bow_energy(j_ptr->sval);
3249         tmul = bow_tmul(j_ptr->sval);
3250
3251         /* Get extra "power" from "extra might" */
3252         if (p_ptr->xtra_might) tmul++;
3253
3254         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
3255
3256         /* Boost the damage */
3257         tdam_base *= tmul;
3258         tdam_base /= 100;
3259
3260         /* Base range */
3261         tdis = 13 + tmul/80;
3262         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3263         {
3264                 if (p_ptr->concent)
3265                         tdis -= (5 - (p_ptr->concent + 1) / 2);
3266                 else
3267                         tdis -= 5;
3268         }
3269
3270         project_length = tdis + 1;
3271
3272         /* Get a direction (or cancel) */
3273         if (!get_aim_dir(&dir))
3274         {
3275                 p_ptr->energy_use = 0;
3276
3277                 if (snipe_type == SP_AWAY) snipe_type = SP_NONE;
3278
3279                 /* need not to reset project_length (already did)*/
3280
3281                 return;
3282         }
3283
3284         /* Predict the "target" location */
3285         tx = p_ptr->x + 99 * ddx[dir];
3286         ty = p_ptr->y + 99 * ddy[dir];
3287
3288         /* Check for "target request" */
3289         if ((dir == 5) && target_okay())
3290         {
3291                 tx = target_col;
3292                 ty = target_row;
3293         }
3294
3295         /* Get projection path length */
3296         tdis = project_path(path_g, project_length, p_ptr->y, p_ptr->x, ty, tx, PROJECT_PATH|PROJECT_THRU) - 1;
3297
3298         project_length = 0; /* reset to default */
3299
3300         /* Don't shoot at my feet */
3301         if (tx == p_ptr->x && ty == p_ptr->y)
3302         {
3303                 p_ptr->energy_use = 0;
3304
3305                 /* project_length is already reset to 0 */
3306
3307                 return;
3308         }
3309
3310
3311         /* Take a (partial) turn */
3312         p_ptr->energy_use = (p_ptr->energy_use / thits);
3313         is_fired = TRUE;
3314
3315         /* Sniper - Difficult to shot twice at 1 turn */
3316         if (snipe_type == SP_DOUBLE)  p_ptr->concent = (p_ptr->concent + 1) / 2;
3317
3318         /* Sniper - Repeat shooting when double shots */
3319         for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++)
3320         {
3321
3322         /* Start at the player */
3323         y = p_ptr->y;
3324         x = p_ptr->x;
3325
3326         /* Get local object */
3327         q_ptr = &forge;
3328
3329         /* Obtain a local object */
3330         object_copy(q_ptr, o_ptr);
3331
3332         /* Single object */
3333         q_ptr->number = 1;
3334
3335         /* Reduce and describe inventory */
3336         if (item >= 0)
3337         {
3338                 inven_item_increase(item, -1);
3339                 inven_item_describe(item);
3340                 inven_item_optimize(item);
3341         }
3342
3343         /* Reduce and describe floor item */
3344         else
3345         {
3346                 floor_item_increase(0 - item, -1);
3347                 floor_item_optimize(0 - item);
3348         }
3349
3350         /* Sound */
3351         sound(SOUND_SHOOT);
3352
3353         /* Hack -- Handle stuff */
3354         handle_stuff();
3355
3356         /* Save the old location */
3357         prev_y = y;
3358         prev_x = x;
3359
3360         /* The shot does not hit yet */
3361         hit_body = FALSE;
3362
3363         /* Travel until stopped */
3364         for (cur_dis = 0; cur_dis <= tdis; )
3365         {
3366                 cave_type *c_ptr;
3367
3368                 /* Hack -- Stop at the target */
3369                 if ((y == ty) && (x == tx)) break;
3370
3371                 /* Calculate the new location (see "project()") */
3372                 ny = y;
3373                 nx = x;
3374                 mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
3375
3376                 /* Shatter Arrow */
3377                 if (snipe_type == SP_KILL_WALL)
3378                 {
3379                         c_ptr = &cave[ny][nx];
3380
3381                         if (cave_have_flag_grid(c_ptr, FF_HURT_ROCK) && !c_ptr->m_idx)
3382                         {
3383                                 if (c_ptr->info & (CAVE_MARK)) msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
3384                                 /* Forget the wall */
3385                                 c_ptr->info &= ~(CAVE_MARK);
3386
3387                                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
3388
3389                                 /* Destroy the wall */
3390                                 cave_alter_feat(ny, nx, FF_HURT_ROCK);
3391
3392                                 hit_body = TRUE;
3393                                 break;
3394                         }
3395                 }
3396
3397                 /* Stopped by walls/doors */
3398                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
3399
3400                 /* Advance the distance */
3401                 cur_dis++;
3402
3403                 /* Sniper */
3404                 if (snipe_type == SP_LITE)
3405                 {
3406                         cave[ny][nx].info |= (CAVE_GLOW);
3407
3408                         /* Notice */
3409                         note_spot(ny, nx);
3410
3411                         /* Redraw */
3412                         lite_spot(ny, nx);
3413                 }
3414
3415                 /* The player can see the (on screen) missile */
3416                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
3417                 {
3418                         char c = object_char(q_ptr);
3419                         byte a = object_attr(q_ptr);
3420
3421                         /* Draw, Hilite, Fresh, Pause, Erase */
3422                         print_rel(c, a, ny, nx);
3423                         move_cursor_relative(ny, nx);
3424                         Term_fresh();
3425                         Term_xtra(TERM_XTRA_DELAY, msec);
3426                         lite_spot(ny, nx);
3427                         Term_fresh();
3428                 }
3429
3430                 /* The player cannot see the missile */
3431                 else
3432                 {
3433                         /* Pause anyway, for consistancy */
3434                         Term_xtra(TERM_XTRA_DELAY, msec);
3435                 }
3436
3437                 /* Sniper */
3438                 if (snipe_type == SP_KILL_TRAP)
3439                 {
3440                         project(0, 0, ny, nx, 0, GF_KILL_TRAP,
3441                                 (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM), -1);
3442                 }
3443
3444                 /* Sniper */
3445                 if (snipe_type == SP_EVILNESS)
3446                 {
3447                         cave[ny][nx].info &= ~(CAVE_GLOW | CAVE_MARK);
3448
3449                         /* Notice */
3450                         note_spot(ny, nx);
3451
3452                         /* Redraw */
3453                         lite_spot(ny, nx);
3454                 }
3455
3456                 /* Save the old location */
3457                 prev_y = y;
3458                 prev_x = x;
3459
3460                 /* Save the new location */
3461                 x = nx;
3462                 y = ny;
3463
3464
3465                 /* Monster here, Try to hit it */
3466                 if (cave[y][x].m_idx)
3467                 {
3468                         cave_type *c_mon_ptr = &cave[y][x];
3469
3470                         monster_type *m_ptr = &m_list[c_mon_ptr->m_idx];
3471                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3472
3473                         /* Check the visibility */
3474                         visible = m_ptr->ml;
3475
3476                         /* Note the collision */
3477                         hit_body = TRUE;
3478
3479                         if (MON_CSLEEP(m_ptr))
3480                         {
3481                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
3482                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
3483                         }
3484
3485                         if ((r_ptr->level + 10) > p_ptr->lev)
3486                         {
3487                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
3488                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
3489                                 {
3490                                         SUB_EXP amount = 0;
3491                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
3492                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
3493                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
3494                                         else if (p_ptr->lev > 34) amount = 2;
3495                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
3496                                         p_ptr->update |= (PU_BONUS);
3497                                 }
3498                         }
3499
3500                         if (p_ptr->riding)
3501                         {
3502                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
3503                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
3504                                         && one_in_(2))
3505                                 {
3506                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
3507                                         p_ptr->update |= (PU_BONUS);
3508                                 }
3509                         }
3510
3511                         /* Did we hit it (penalize range) */
3512                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3513                         {
3514                                 bool fear = FALSE;
3515                                 int tdam = tdam_base;
3516
3517                                 /* Get extra damage from concentration */
3518                                 if (p_ptr->concent) tdam = boost_concentration_damage(tdam);
3519
3520                                 /* Handle unseen monster */
3521                                 if (!visible)
3522                                 {
3523                                         /* Invisible monster */
3524                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
3525                                 }
3526
3527                                 /* Handle visible monster */
3528                                 else
3529                                 {
3530                                         char m_name[80];
3531
3532                                         /* Get "the monster" or "it" */
3533                                         monster_desc(m_name, m_ptr, 0);
3534
3535                                         /* Message */
3536                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3537
3538                                         if (m_ptr->ml)
3539                                         {
3540                                                 /* Hack -- Track this monster race */
3541                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3542
3543                                                 /* Hack -- Track this monster */
3544                                                 health_track(c_mon_ptr->m_idx);
3545                                         }
3546                                 }
3547
3548                                 if (snipe_type == SP_NEEDLE)
3549                                 {
3550                                         if ((randint1(randint1(r_ptr->level / (3 + p_ptr->concent)) + (8 - p_ptr->concent)) == 1)
3551                                                 && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
3552                                         {
3553                                                 char m_name[80];
3554
3555                                                 /* Get "the monster" or "it" */
3556                                                 monster_desc(m_name, m_ptr, 0);
3557
3558                                                 tdam = m_ptr->hp + 1;
3559                                                 msg_format(_("%sの急所に突き刺さった!", "Your shot sticked on a fatal spot of %s!"), m_name);
3560                                         }
3561                                         else tdam = 1;
3562                                 }
3563                                 else
3564                                 {
3565                                         /* Apply special damage XXX XXX XXX */
3566                                         tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3567                                         tdam = critical_shot(q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
3568
3569                                         /* No negative damage */
3570                                         if (tdam < 0) tdam = 0;
3571
3572                                         /* Modify the damage */
3573                                         tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3574                                 }
3575
3576                                 msg_format_wizard(CHEAT_MONSTER,
3577                                         _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3578                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3579
3580                                 /* Sniper */
3581                                 if (snipe_type == SP_EXPLODE)
3582                                 {
3583                                         u16b flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
3584
3585                                         sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
3586                                         project(0, ((p_ptr->concent + 1) / 2 + 1), ny, nx, tdam, GF_MISSILE, flg, -1);
3587                                         break;
3588                                 }
3589
3590                                 /* Sniper */
3591                                 if (snipe_type == SP_HOLYNESS)
3592                                 {
3593                                         cave[ny][nx].info |= (CAVE_GLOW);
3594
3595                                         /* Notice */
3596                                         note_spot(ny, nx);
3597
3598                                         /* Redraw */
3599                                         lite_spot(ny, nx);
3600                                 }
3601
3602                                 /* Hit the monster, check for death */
3603                                 if (mon_take_hit(c_mon_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3604                                 {
3605                                         /* Dead monster */
3606                                 }
3607
3608                                 /* No death */
3609                                 else
3610                                 {
3611                                         /* STICK TO */
3612                                         if (object_is_fixed_artifact(q_ptr) &&
3613                                                 (p_ptr->pclass != CLASS_SNIPER || p_ptr->concent == 0))
3614                                         {
3615                                                 char m_name[80];
3616
3617                                                 monster_desc(m_name, m_ptr, 0);
3618
3619                                                 stick_to = TRUE;
3620                                                 msg_format(_("%sは%sに突き刺さった!", "%^s have stuck into %s!"),o_name, m_name);
3621                                         }
3622
3623                                         /* Message */
3624                                         message_pain(c_mon_ptr->m_idx, tdam);
3625
3626                                         /* Anger the monster */
3627                                         if (tdam > 0) anger_monster(m_ptr);
3628
3629                                         /* Take note */
3630                                         if (fear && m_ptr->ml)
3631                                         {
3632                                                 char m_name[80];
3633
3634                                                 /* Sound */
3635                                                 sound(SOUND_FLEE);
3636
3637                                                 /* Get the monster name (or "it") */
3638                                                 monster_desc(m_name, m_ptr, 0);
3639
3640                                                 /* Message */
3641                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3642                                         }
3643
3644                                         set_target(m_ptr, p_ptr->y, p_ptr->x);
3645
3646                                         /* Sniper */
3647                                         if (snipe_type == SP_RUSH)
3648                                         {
3649                                                 int n = randint1(5) + 3;
3650                                                 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
3651
3652                                                 for ( ; cur_dis <= tdis; )
3653                                                 {
3654                                                         POSITION ox = nx;
3655                                                         POSITION oy = ny;
3656
3657                                                         if (!n) break;
3658
3659                                                         /* Calculate the new location (see "project()") */
3660                                                         mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
3661
3662                                                         /* Stopped by wilderness boundary */
3663                                                         if (!in_bounds2(ny, nx)) break;
3664
3665                                                         /* Stopped by walls/doors */
3666                                                         if (!player_can_enter(cave[ny][nx].feat, 0)) break;
3667
3668                                                         /* Stopped by monsters */
3669                                                         if (!cave_empty_bold(ny, nx)) break;
3670
3671                                                         cave[ny][nx].m_idx = m_idx;
3672                                                         cave[oy][ox].m_idx = 0;
3673
3674                                                         m_ptr->fx = nx;
3675                                                         m_ptr->fy = ny;
3676
3677                                                         /* Update the monster (new location) */
3678                                                         update_mon(c_mon_ptr->m_idx, TRUE);
3679
3680                                                         lite_spot(ny, nx);
3681                                                         lite_spot(oy, ox);
3682
3683                                                         Term_fresh();
3684                                                         Term_xtra(TERM_XTRA_DELAY, msec);
3685
3686                                                         x = nx;
3687                                                         y = ny;
3688                                                         cur_dis++;
3689                                                         n--;
3690                                                 }
3691                                         }
3692                                 }
3693                         }
3694
3695                         /* Sniper */
3696                         if (snipe_type == SP_PIERCE)
3697                         {
3698                                 if(p_ptr->concent < 1) break;
3699                                 p_ptr->concent--;
3700                                 continue;
3701                         }
3702
3703                         /* Stop looking */
3704                         break;
3705                 }
3706         }
3707
3708         /* Chance of breakage (during attacks) */
3709         j = (hit_body ? breakage_chance(q_ptr) : 0);
3710
3711         if (stick_to)
3712         {
3713                 MONSTER_IDX m_idx = cave[y][x].m_idx;
3714                 monster_type *m_ptr = &m_list[m_idx];
3715                 IDX o_idx = o_pop();
3716
3717                 if (!o_idx)
3718                 {
3719                         msg_format(_("%sはどこかへ行った。", "The %s have gone to somewhere."), o_name);
3720                         if (object_is_fixed_artifact(q_ptr))
3721                         {
3722                                 a_info[j_ptr->name1].cur_num = 0;
3723                         }
3724                         return;
3725                 }
3726
3727                 o_ptr = &o_list[o_idx];
3728                 object_copy(o_ptr, q_ptr);
3729
3730                 /* Forget mark */
3731                 o_ptr->marked &= OM_TOUCHED;
3732
3733                 /* Forget location */
3734                 o_ptr->iy = o_ptr->ix = 0;
3735
3736                 /* Memorize monster */
3737                 o_ptr->held_m_idx = m_idx;
3738
3739                 /* Build a stack */
3740                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3741
3742                 /* Carry object */
3743                 m_ptr->hold_o_idx = o_idx;
3744         }
3745         else if (cave_have_flag_bold(y, x, FF_PROJECT))
3746         {
3747                 /* Drop (or break) near that location */
3748                 (void)drop_near(q_ptr, j, y, x);
3749         }
3750         else
3751         {
3752                 /* Drop (or break) near that location */
3753                 (void)drop_near(q_ptr, j, prev_y, prev_x);
3754         }
3755
3756         /* Sniper - Repeat shooting when double shots */
3757         }
3758
3759         /* Sniper - Loose his/her concentration after any shot */
3760         if (p_ptr->concent) reset_concentration(FALSE);
3761 }
3762
3763 /*!
3764  * @brief 射撃処理のメインルーチン
3765  * @return なし
3766  */
3767 void do_cmd_fire(void)
3768 {
3769         OBJECT_IDX item;
3770         object_type *j_ptr;
3771         cptr q, s;
3772
3773         is_fired = FALSE;       /* not fired yet */
3774
3775         /* Get the "bow" (if any) */
3776         j_ptr = &inventory[INVEN_BOW];
3777
3778         /* Require a launcher */
3779         if (!j_ptr->tval)
3780         {
3781                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
3782                 flush();
3783                 return;
3784         }
3785
3786         if (j_ptr->sval == SV_CRIMSON)
3787         {
3788                 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
3789                 flush();
3790                 return;
3791         }
3792
3793         if (j_ptr->sval == SV_HARP)
3794         {
3795                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
3796                 flush();
3797                 return;
3798         }
3799
3800
3801         if (p_ptr->special_defense & KATA_MUSOU)
3802         {
3803                 set_action(ACTION_NONE);
3804         }
3805
3806         /* Require proper missile */
3807         item_tester_tval = p_ptr->tval_ammo;
3808
3809         /* Get an item */
3810         q = _("どれを撃ちますか? ", "Fire which item? ");
3811         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
3812         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
3813         {
3814                 flush();
3815                 return;
3816         }
3817
3818         /* Fire the item */
3819         do_cmd_fire_aux(item, j_ptr);
3820
3821         if (!is_fired || p_ptr->pclass != CLASS_SNIPER) return;
3822
3823         /* Sniper actions after some shootings */
3824         if (snipe_type == SP_AWAY)
3825         {
3826                 teleport_player(10 + (p_ptr->concent * 2), 0L);
3827         }
3828         if (snipe_type == SP_FINAL)
3829         {
3830                 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
3831                 (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
3832                 (void)set_stun(p_ptr->stun + randint1(25));
3833         }
3834 }
3835
3836 /*!
3837  * @brief オブジェクトが投射可能な武器かどうかを返す。
3838  * @param o_ptr 判定するオブジェクトの構造体参照ポインタ
3839  * @return 投射可能な武器ならばTRUE
3840  */
3841 static bool item_tester_hook_boomerang(object_type *o_ptr)
3842 {
3843         if ((o_ptr->tval==TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED)) return (TRUE);
3844
3845         /* Assume not */
3846         return (FALSE);
3847 }
3848
3849
3850 /*!
3851  * @brief 投射処理のサブルーチン /
3852  * Throw an object from the pack or floor.
3853  * @param mult 威力の倍率
3854  * @param boomerang ブーメラン処理ならばTRUE
3855  * @param shuriken 忍者の手裏剣処理ならばTRUE
3856  * @return ターンを消費した場合TRUEを返す
3857  * @details
3858  * <pre>
3859  * Note: "unseen" monsters are very hard to hit.
3860  *
3861  * Should throwing a weapon do full damage?  Should it allow the magic
3862  * to hit bonus of the weapon to have an effect?  Should it ever cause
3863  * the item to be destroyed?  Should it do any damage at all?
3864  * </pre>
3865  */
3866 bool do_cmd_throw_aux(int mult, bool boomerang, OBJECT_IDX shuriken)
3867 {
3868         DIRECTION dir;
3869         OBJECT_IDX item;
3870         int i, j, y, x, ty, tx, prev_y, prev_x;
3871         int ny[19], nx[19];
3872         int chance, tdam, tdis;
3873         int mul, div, dd, ds;
3874         int cur_dis, visible;
3875
3876         object_type forge;
3877         object_type *q_ptr;
3878
3879         object_type *o_ptr;
3880
3881         bool hit_body = FALSE;
3882         bool hit_wall = FALSE;
3883         bool equiped_item = FALSE;
3884         bool return_when_thrown = FALSE;
3885
3886         char o_name[MAX_NLEN];
3887
3888         int msec = delay_factor * delay_factor * delay_factor;
3889
3890         u32b flgs[TR_FLAG_SIZE];
3891         cptr q, s;
3892         bool come_back = FALSE;
3893         bool do_drop = TRUE;
3894
3895
3896         if (p_ptr->special_defense & KATA_MUSOU)
3897         {
3898                 set_action(ACTION_NONE);
3899         }
3900
3901         if (shuriken >= 0)
3902         {
3903                 item = shuriken;
3904         }
3905         else if (boomerang)
3906         {
3907                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
3908                 {
3909                         item_tester_hook = item_tester_hook_boomerang;
3910                         q = _("どの武器を投げますか? ", "Throw which item? ");
3911                         s = _("投げる武器がない。", "You have nothing to throw.");
3912                         if (!get_item(&item, q, s, (USE_EQUIP)))
3913                         {
3914                                 flush();
3915                                 return FALSE;
3916                         }
3917                 }
3918                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
3919                 else item = INVEN_RARM;
3920         }
3921         else
3922         {
3923                 /* Get an item */
3924                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
3925                 s = _("投げるアイテムがない。", "You have nothing to throw.");
3926                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
3927                 {
3928                         flush();
3929                         return FALSE;
3930                 }
3931         }
3932
3933         /* Access the item (if in the pack) */
3934         if (item >= 0)
3935         {
3936                 o_ptr = &inventory[item];
3937         }
3938         else
3939         {
3940                 o_ptr = &o_list[0 - item];
3941         }
3942
3943
3944         /* Item is cursed */
3945         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
3946         {
3947                 /* Oops */
3948                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
3949
3950                 /* Nope */
3951                 return FALSE;
3952         }
3953
3954         if (p_ptr->inside_arena && !boomerang)
3955         {
3956                 if (o_ptr->tval != TV_SPIKE)
3957                 {
3958                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
3959                         msg_print(NULL);
3960
3961                         /* Nope */
3962                         return FALSE;
3963                 }
3964         }
3965
3966         /* Get local object */
3967         q_ptr = &forge;
3968
3969         /* Obtain a local object */
3970         object_copy(q_ptr, o_ptr);
3971
3972         /* Extract the thrown object's flags. */
3973         object_flags(q_ptr, flgs);
3974         torch_flags(q_ptr, flgs);
3975
3976         /* Distribute the charges of rods/wands between the stacks */
3977         distribute_charges(o_ptr, q_ptr, 1);
3978
3979         /* Single object */
3980         q_ptr->number = 1;
3981
3982         /* Description */
3983         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
3984
3985         if (p_ptr->mighty_throw) mult += 3;
3986
3987         /* Extract a "distance multiplier" */
3988         /* Changed for 'launcher' mutation */
3989         mul = 10 + 2 * (mult - 1);
3990
3991         /* Enforce a minimum "weight" of one pound */
3992         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
3993         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
3994
3995         /* Hack -- Distance -- Reward strength, penalize weight */
3996         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
3997
3998         /* Max distance of 10-18 */
3999         if (tdis > mul) tdis = mul;
4000
4001         if (shuriken >= 0)
4002         {
4003                 ty = randint0(101)-50+p_ptr->y;
4004                 tx = randint0(101)-50+p_ptr->x;
4005         }
4006         else
4007         {
4008                 project_length = tdis + 1;
4009
4010                 /* Get a direction (or cancel) */
4011                 if (!get_aim_dir(&dir)) return FALSE;
4012
4013                 /* Predict the "target" location */
4014                 tx = p_ptr->x + 99 * ddx[dir];
4015                 ty = p_ptr->y + 99 * ddy[dir];
4016
4017                 /* Check for "target request" */
4018                 if ((dir == 5) && target_okay())
4019                 {
4020                         tx = target_col;
4021                         ty = target_row;
4022                 }
4023
4024                 project_length = 0;  /* reset to default */
4025         }
4026
4027         if ((q_ptr->name1 == ART_MJOLLNIR) ||
4028             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
4029                 return_when_thrown = TRUE;
4030
4031         /* Reduce and describe inventory */
4032         if (item >= 0)
4033         {
4034                 inven_item_increase(item, -1);
4035                 if (!return_when_thrown)
4036                         inven_item_describe(item);
4037                 inven_item_optimize(item);
4038         }
4039
4040         /* Reduce and describe floor item */
4041         else
4042         {
4043                 floor_item_increase(0 - item, -1);
4044                 floor_item_optimize(0 - item);
4045         }
4046         if (item >= INVEN_RARM)
4047         {
4048                 equiped_item = TRUE;
4049                 p_ptr->redraw |= (PR_EQUIPPY);
4050         }
4051
4052         /* Take a turn */
4053         p_ptr->energy_use = 100;
4054
4055         /* Rogue and Ninja gets bonus */
4056         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
4057                 p_ptr->energy_use -= p_ptr->lev;
4058
4059         /* Start at the player */
4060         y = p_ptr->y;
4061         x = p_ptr->x;
4062
4063
4064         /* Hack -- Handle stuff */
4065         handle_stuff();
4066
4067         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
4068         else shuriken = FALSE;
4069
4070         /* Chance of hitting */
4071         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
4072                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
4073         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
4074
4075         if (shuriken) chance *= 2;
4076
4077         /* Save the old location */
4078         prev_y = y;
4079         prev_x = x;
4080
4081         /* Travel until stopped */
4082         for (cur_dis = 0; cur_dis <= tdis; )
4083         {
4084                 /* Hack -- Stop at the target */
4085                 if ((y == ty) && (x == tx)) break;
4086
4087                 /* Calculate the new location (see "project()") */
4088                 ny[cur_dis] = y;
4089                 nx[cur_dis] = x;
4090                 mmove2(&ny[cur_dis], &nx[cur_dis], p_ptr->y, p_ptr->x, ty, tx);
4091
4092                 /* Stopped by walls/doors */
4093                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
4094                 {
4095                         hit_wall = TRUE;
4096                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
4097                 }
4098
4099                 /* The player can see the (on screen) missile */
4100                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
4101                 {
4102                         char c = object_char(q_ptr);
4103                         byte a = object_attr(q_ptr);
4104
4105                         /* Draw, Hilite, Fresh, Pause, Erase */
4106                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
4107                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
4108                         Term_fresh();
4109                         Term_xtra(TERM_XTRA_DELAY, msec);
4110                         lite_spot(ny[cur_dis], nx[cur_dis]);
4111                         Term_fresh();
4112                 }
4113
4114                 /* The player cannot see the missile */
4115                 else
4116                 {
4117                         /* Pause anyway, for consistancy */
4118                         Term_xtra(TERM_XTRA_DELAY, msec);
4119                 }
4120
4121                 /* Save the old location */
4122                 prev_y = y;
4123                 prev_x = x;
4124
4125                 /* Save the new location */
4126                 x = nx[cur_dis];
4127                 y = ny[cur_dis];
4128
4129                 /* Advance the distance */
4130                 cur_dis++;
4131
4132                 /* Monster here, Try to hit it */
4133                 if (cave[y][x].m_idx)
4134                 {
4135                         cave_type *c_ptr = &cave[y][x];
4136
4137                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4138
4139                         /* Check the visibility */
4140                         visible = m_ptr->ml;
4141
4142                         /* Note the collision */
4143                         hit_body = TRUE;
4144
4145                         /* Did we hit it (penalize range) */
4146                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
4147                         {
4148                                 bool fear = FALSE;
4149
4150                                 /* Handle unseen monster */
4151                                 if (!visible)
4152                                 {
4153                                         /* Invisible monster */
4154                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
4155                                 }
4156
4157                                 /* Handle visible monster */
4158                                 else
4159                                 {
4160                                         char m_name[80];
4161
4162                                         /* Get "the monster" or "it" */
4163                                         monster_desc(m_name, m_ptr, 0);
4164
4165                                         /* Message */
4166                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
4167
4168                                         if (m_ptr->ml)
4169                                         {
4170                                                 /* Hack -- Track this monster race */
4171                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
4172
4173                                                 /* Hack -- Track this monster */
4174                                                 health_track(c_ptr->m_idx);
4175                                         }
4176                                 }
4177
4178                                 /* Hack -- Base damage from thrown object */
4179                                 dd = q_ptr->dd;
4180                                 ds = q_ptr->ds;
4181                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
4182                                 tdam = damroll(dd, ds);
4183                                 /* Apply special damage XXX XXX XXX */
4184                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
4185                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
4186                                 if (q_ptr->to_d > 0)
4187                                         tdam += q_ptr->to_d;
4188                                 else
4189                                         tdam += -q_ptr->to_d;
4190
4191                                 if (boomerang)
4192                                 {
4193                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
4194                                         tdam += p_ptr->to_d_m;
4195                                 }
4196                                 else if (have_flag(flgs, TR_THROW))
4197                                 {
4198                                         tdam *= (3+mult);
4199                                         tdam += p_ptr->to_d_m;
4200                                 }
4201                                 else
4202                                 {
4203                                         tdam *= mult;
4204                                 }
4205                                 if (shuriken)
4206                                 {
4207                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
4208                                 }
4209
4210                                 /* No negative damage */
4211                                 if (tdam < 0) tdam = 0;
4212
4213                                 /* Modify the damage */
4214                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
4215
4216                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
4217                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
4218
4219                                 /* Hit the monster, check for death */
4220                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
4221                                 {
4222                                         /* Dead monster */
4223                                 }
4224
4225                                 /* No death */
4226                                 else
4227                                 {
4228                                         /* Message */
4229                                         message_pain(c_ptr->m_idx, tdam);
4230
4231                                         /* Anger the monster */
4232                                         if ((tdam > 0) && !object_is_potion(q_ptr))
4233                                                 anger_monster(m_ptr);
4234
4235                                         /* Take note */
4236                                         if (fear && m_ptr->ml)
4237                                         {
4238                                                 char m_name[80];
4239
4240                                                 /* Sound */
4241                                                 sound(SOUND_FLEE);
4242
4243                                                 /* Get the monster name (or "it") */
4244                                                 monster_desc(m_name, m_ptr, 0);
4245
4246                                                 /* Message */
4247                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
4248                                         }
4249                                 }
4250                         }
4251
4252                         /* Stop looking */
4253                         break;
4254                 }
4255         }
4256
4257         /* decrease toach's fuel */
4258         if (hit_body) torch_lost_fuel(q_ptr);
4259
4260         /* Chance of breakage (during attacks) */
4261         j = (hit_body ? breakage_chance(q_ptr) : 0);
4262
4263         /* Figurines transform */
4264         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
4265         {
4266                 j = 100;
4267
4268                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
4269                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
4270                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
4271                 else if (object_is_cursed(q_ptr))
4272                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
4273
4274         }
4275
4276
4277         /* Potions smash open */
4278         if (object_is_potion(q_ptr))
4279         {
4280                 if (hit_body || hit_wall || (randint1(100) < j))
4281                 {
4282                         /* Message */
4283                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
4284
4285                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
4286                         {
4287                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
4288
4289                                 /* ToDo (Robert): fix the invulnerability */
4290                                 if (cave[y][x].m_idx &&
4291                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
4292                                     !MON_INVULNER(m_ptr))
4293                                 {
4294                                         char m_name[80];
4295                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
4296                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
4297                                         set_hostile(&m_list[cave[y][x].m_idx]);
4298                                 }
4299                         }
4300                         do_drop = FALSE;
4301                 }
4302                 else
4303                 {
4304                         j = 0;
4305                 }
4306         }
4307
4308         if (return_when_thrown)
4309         {
4310                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4311                 char o2_name[MAX_NLEN];
4312                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
4313
4314                 j = -1;
4315                 if (boomerang) back_chance += 4+randint1(5);
4316                 if (super_boomerang) back_chance += 100;
4317                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4318
4319                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
4320                 {
4321                         for (i = cur_dis - 1; i > 0; i--)
4322                         {
4323                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
4324                                 {
4325                                         char c = object_char(q_ptr);
4326                                         byte a = object_attr(q_ptr);
4327
4328                                         /* Draw, Hilite, Fresh, Pause, Erase */
4329                                         print_rel(c, a, ny[i], nx[i]);
4330                                         move_cursor_relative(ny[i], nx[i]);
4331                                         Term_fresh();
4332                                         Term_xtra(TERM_XTRA_DELAY, msec);
4333                                         lite_spot(ny[i], nx[i]);
4334                                         Term_fresh();
4335                                 }
4336                                 else
4337                                 {
4338                                         /* Pause anyway, for consistancy */
4339                                         Term_xtra(TERM_XTRA_DELAY, msec);
4340                                 }
4341                         }
4342                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
4343                         {
4344                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
4345                                 come_back = TRUE;
4346                         }
4347                         else
4348                         {
4349                                 if (item >= 0)
4350                                 {
4351                                         msg_format(_("%sを受け損ねた!", "%s backs, but you can't catch!"), o2_name);
4352                                 }
4353                                 else
4354                                 {
4355                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
4356                                 }
4357                                 y = p_ptr->y;
4358                                 x = p_ptr->x;
4359                         }
4360                 }
4361                 else
4362                 {
4363                         msg_format(_("%sが返ってこなかった!", "%s doesn't back!"), o2_name);
4364                 }
4365         }
4366
4367         if (come_back)
4368         {
4369                 if (item == INVEN_RARM || item == INVEN_LARM)
4370                 {
4371                         /* Access the wield slot */
4372                         o_ptr = &inventory[item];
4373
4374                         /* Wear the new stuff */
4375                         object_copy(o_ptr, q_ptr);
4376
4377                         /* Increase the weight */
4378                         p_ptr->total_weight += q_ptr->weight;
4379
4380                         /* Increment the equip counter by hand */
4381                         equip_cnt++;
4382
4383                         /* Recalculate bonuses */
4384                         p_ptr->update |= (PU_BONUS);
4385
4386                         /* Recalculate torch */
4387                         p_ptr->update |= (PU_TORCH);
4388
4389                         /* Recalculate mana XXX */
4390                         p_ptr->update |= (PU_MANA);
4391
4392                         /* Window stuff */
4393                         p_ptr->window |= (PW_EQUIP);
4394                 }
4395                 else
4396                 {
4397                         inven_carry(q_ptr);
4398                 }
4399                 do_drop = FALSE;
4400         }
4401         else if (equiped_item)
4402         {
4403                 kamaenaoshi(item);
4404                 calc_android_exp();
4405         }
4406
4407         /* Drop (or break) near that location */
4408         if (do_drop)
4409         {
4410                 if (cave_have_flag_bold(y, x, FF_PROJECT))
4411                 {
4412                         /* Drop (or break) near that location */
4413                         (void)drop_near(q_ptr, j, y, x);
4414                 }
4415                 else
4416                 {
4417                         /* Drop (or break) near that location */
4418                         (void)drop_near(q_ptr, j, prev_y, prev_x);
4419                 }
4420         }
4421
4422         return TRUE;
4423 }
4424
4425
4426 /*!
4427  * @brief 投射処理のメインルーチン /
4428  * Throw an object from the pack or floor.
4429  * @return なし
4430  */
4431 void do_cmd_throw(void)
4432 {
4433         do_cmd_throw_aux(1, FALSE, -1);
4434 }
4435
4436
4437 #ifdef TRAVEL
4438 /*
4439  * Hack: travel command
4440  */
4441 #define TRAVEL_UNABLE 9999
4442
4443 static int flow_head = 0;
4444 static int flow_tail = 0;
4445 static POSITION temp2_x[MAX_SHORT];
4446 static POSITION temp2_y[MAX_SHORT];
4447
4448 /*!
4449  * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information 
4450  * @return なし
4451  */
4452 void forget_travel_flow(void)
4453 {
4454         int x, y;
4455
4456         /* Check the entire dungeon */
4457         for (y = 0; y < cur_hgt; y++)
4458         {
4459                 for (x = 0; x < cur_wid; x++)
4460                 {
4461                         /* Forget the old data */
4462                         travel.cost[y][x] = MAX_SHORT;
4463                 }
4464         }
4465
4466         travel.y = travel.x = 0;
4467 }
4468
4469 /*!
4470  * @brief トラベル処理中に地形に応じた移動コスト基準を返す
4471  * @param y 該当地点のY座標
4472  * @param x 該当地点のX座標
4473  * @return コスト値
4474  */
4475 static int travel_flow_cost(int y, int x)
4476 {
4477         feature_type *f_ptr = &f_info[cave[y][x].feat];
4478         int cost = 1;
4479
4480         /* Avoid obstacles (ex. trees) */
4481         if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
4482
4483         /* Water */
4484         if (have_flag(f_ptr->flags, FF_WATER))
4485         {
4486                 if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
4487         }
4488
4489         /* Lava */
4490         if (have_flag(f_ptr->flags, FF_LAVA))
4491         {
4492                 int lava = 2;
4493                 if (!p_ptr->resist_fire) lava *= 2;
4494                 if (!p_ptr->levitation) lava *= 2;
4495                 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
4496
4497                 cost += lava;
4498         }
4499
4500         /* Detected traps and doors */
4501         if (cave[y][x].info & (CAVE_MARK))
4502         {
4503                 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
4504                 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
4505         }
4506
4507         return (cost);
4508 }
4509
4510 /*!
4511  * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
4512  * @param y 目標地点のY座標
4513  * @param x 目標地点のX座標
4514  * @param n 現在のコスト
4515  * @param wall プレイヤーが壁の中にいるならばTRUE
4516  * @return なし
4517  */
4518 static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
4519 {
4520         cave_type *c_ptr = &cave[y][x];
4521         feature_type *f_ptr = &f_info[c_ptr->feat];
4522         int old_head = flow_head;
4523         int add_cost = 1;
4524         int base_cost = (n % TRAVEL_UNABLE);
4525         int from_wall = (n / TRAVEL_UNABLE);
4526         int cost;
4527
4528         /* Ignore out of bounds */
4529         if (!in_bounds(y, x)) return;
4530
4531         /* Ignore unknown grid except in wilderness */
4532         if (dun_level > 0 && !(c_ptr->info & CAVE_KNOWN)) return;
4533
4534         /* Ignore "walls" and "rubble" (include "secret doors") */
4535         if (have_flag(f_ptr->flags, FF_WALL) ||
4536                 have_flag(f_ptr->flags, FF_CAN_DIG) ||
4537                 (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic) ||
4538                 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
4539         {
4540                 if (!wall || !from_wall) return;
4541                 add_cost += TRAVEL_UNABLE;
4542         }
4543         else
4544         {
4545                 add_cost = travel_flow_cost(y, x);
4546         }
4547
4548         cost = base_cost + add_cost;
4549
4550         /* Ignore lower cost entries */
4551         if (travel.cost[y][x] <= cost) return;
4552
4553         /* Save the flow cost */
4554         travel.cost[y][x] = cost;
4555
4556         /* Enqueue that entry */
4557         temp2_y[flow_head] = y;
4558         temp2_x[flow_head] = x;
4559
4560         /* Advance the queue */
4561         if (++flow_head == MAX_SHORT) flow_head = 0;
4562
4563         /* Hack -- notice overflow by forgetting new entry */
4564         if (flow_head == flow_tail) flow_head = old_head;
4565
4566         return;
4567 }
4568
4569 /*!
4570  * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
4571  * @param ty 目標地点のY座標
4572  * @param tx 目標地点のX座標
4573  * @return なし
4574  */
4575 static void travel_flow(int ty, int tx)
4576 {
4577         int x, y, d;
4578         bool wall = FALSE;
4579         feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
4580
4581         /* Reset the "queue" */
4582         flow_head = flow_tail = 0;
4583
4584         /* is player in the wall? */
4585         if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
4586
4587         /* Start at the target grid */
4588         travel_flow_aux(ty, tx, 0, wall);
4589
4590         /* Now process the queue */
4591         while (flow_head != flow_tail)
4592         {
4593                 /* Extract the next entry */
4594                 y = temp2_y[flow_tail];
4595                 x = temp2_x[flow_tail];
4596
4597                 /* Forget that entry */
4598                 if (++flow_tail == MAX_SHORT) flow_tail = 0;
4599
4600                 /* Ignore too far entries */
4601                 //if (distance(ty, tx, y, x) > 100) continue;
4602
4603                 /* Add the "children" */
4604                 for (d = 0; d < 8; d++)
4605                 {
4606                         /* Add that child if "legal" */
4607                         travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
4608                 }
4609         }
4610
4611         /* Forget the flow info */
4612         flow_head = flow_tail = 0;
4613 }
4614
4615 /*!
4616  * @brief トラベル処理のメインルーチン
4617  * @return なし
4618  */
4619 void do_cmd_travel(void)
4620 {
4621         POSITION x, y;
4622         int i;
4623         int dx, dy, sx, sy;
4624         feature_type *f_ptr;
4625
4626         if (travel.x != 0 && travel.y != 0 &&
4627             get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
4628         {
4629                 y = travel.y;
4630                 x = travel.x;
4631         }
4632         else if (!tgt_pt(&x, &y)) return;
4633
4634         if ((x == p_ptr->x) && (y == p_ptr->y))
4635         {
4636                 msg_print(_("すでにそこにいます!", "You are already there!!"));
4637                 return;
4638         }
4639
4640         f_ptr = &f_info[cave[y][x].feat];
4641
4642         if ((cave[y][x].info & CAVE_MARK) &&
4643                 (have_flag(f_ptr->flags, FF_WALL) ||
4644                         have_flag(f_ptr->flags, FF_CAN_DIG) ||
4645                         (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic)))
4646         {
4647                 msg_print(_("そこには行くことができません!", "You cannot travel there!"));
4648                 return;
4649         }
4650
4651         forget_travel_flow();
4652         travel_flow(y, x);
4653
4654         travel.x = x;
4655         travel.y = y;
4656
4657         /* Travel till 255 steps */
4658         travel.run = 255;
4659
4660         /* Paranoia */
4661         travel.dir = 0;
4662
4663         /* Decides first direction */
4664         dx = abs(p_ptr->x - x);
4665         dy = abs(p_ptr->y - y);
4666         sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
4667         sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
4668
4669         for (i = 1; i <= 9; i++)
4670         {
4671                 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
4672         }
4673 }
4674 #endif