OSDN Git Service

Merge branch 'xoroshiro128plus'
[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(int 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(int *y, int *x, bool (*test)(int 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(int *y, int *x, bool trapped)
950 {
951         int d, count, o_idx;
952
953         object_type *o_ptr;
954
955         /* Count how many matches */
956         count = 0;
957
958         /* Check around (and under) the character */
959         for (d = 0; d < 9; d++)
960         {
961                 /* Extract adjacent (legal) location */
962                 int yy = p_ptr->y + ddy_ddd[d];
963                 int xx = p_ptr->x + ddx_ddd[d];
964
965                 /* No (visible) chest is there */
966                 if ((o_idx = chest_check(yy, xx, FALSE)) == 0) continue;
967
968                 /* Grab the object */
969                 o_ptr = &o_list[o_idx];
970
971                 /* Already open */
972                 if (o_ptr->pval == 0) continue;
973
974                 /* No (known) traps here */
975                 if (trapped && (!object_is_known(o_ptr) ||
976                         !chest_traps[o_ptr->pval])) continue;
977
978                 /* OK */
979                 ++count;
980
981                 /* Remember the location. Only useful if only one match */
982                 *y = yy;
983                 *x = xx;
984         }
985
986         /* All done */
987         return count;
988 }
989
990
991 /*!
992  * @brief プレイヤーから指定の座標がどの方角にあるかを返す /
993  * Convert an adjacent location to a direction.
994  * @param y 方角を確認したY座標
995  * @param x 方角を確認したX座標
996  * @return 方向ID
997  */
998 static int coords_to_dir(int y, int x)
999 {
1000         int d[3][3] = { {7, 4, 1}, {8, 5, 2}, {9, 6, 3} };
1001         int dy, dx;
1002
1003         dy = y - p_ptr->y;
1004         dx = x - p_ptr->x;
1005
1006         /* Paranoia */
1007         if (ABS(dx) > 1 || ABS(dy) > 1) return (0);
1008
1009         return d[dx + 1][dy + 1];
1010 }
1011
1012 #endif /* defined(ALLOW_EASY_OPEN) || defined(ALLOW_EASY_DISARM) -- TNB */
1013
1014
1015 /*!
1016  * @brief 「開ける」動作コマンドのサブルーチン /
1017  * Perform the basic "open" command on doors
1018  * @param y 対象を行うマスのY座標
1019  * @param x 対象を行うマスのX座標
1020  * @return 実際に処理が行われた場合TRUEを返す。
1021  * @details
1022  * Assume destination is a closed/locked/jammed door
1023  * Assume there is no monster blocking the destination
1024  * Returns TRUE if repeated commands may continue
1025  */
1026 static bool do_cmd_open_aux(int y, int x)
1027 {
1028         int i, j;
1029
1030         /* Get requested grid */
1031         cave_type *c_ptr = &cave[y][x];
1032
1033         feature_type *f_ptr = &f_info[c_ptr->feat];
1034
1035         bool more = FALSE;
1036
1037
1038         /* Take a turn */
1039         p_ptr->energy_use = 100;
1040
1041         /* Seeing true feature code (ignore mimic) */
1042
1043         /* Jammed door */
1044         if (!have_flag(f_ptr->flags, FF_OPEN))
1045         {
1046                 /* Stuck */
1047                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(c_ptr)].name);
1048         }
1049
1050         /* Locked door */
1051         else if (f_ptr->power)
1052         {
1053                 /* Disarm factor */
1054                 i = p_ptr->skill_dis;
1055
1056                 /* Penalize some conditions */
1057                 if (p_ptr->blind || no_lite()) i = i / 10;
1058                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1059
1060                 /* Extract the lock power */
1061                 j = f_ptr->power;
1062
1063                 /* Extract the difficulty XXX XXX XXX */
1064                 j = i - (j * 4);
1065
1066                 /* Always have a small chance of success */
1067                 if (j < 2) j = 2;
1068
1069                 /* Success */
1070                 if (randint0(100) < j)
1071                 {
1072                         /* Message */
1073                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1074
1075                         /* Open the door */
1076                         cave_alter_feat(y, x, FF_OPEN);
1077
1078                         /* Sound */
1079                         sound(SOUND_OPENDOOR);
1080
1081                         /* Experience */
1082                         gain_exp(1);
1083                 }
1084
1085                 /* Failure */
1086                 else
1087                 {
1088                         /* Failure */
1089                         if (flush_failure) flush();
1090
1091                         /* Message */
1092                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1093
1094                         /* We may keep trying */
1095                         more = TRUE;
1096                 }
1097         }
1098
1099         /* Closed door */
1100         else
1101         {
1102                 /* Open the door */
1103                 cave_alter_feat(y, x, FF_OPEN);
1104
1105                 /* Sound */
1106                 sound(SOUND_OPENDOOR);
1107         }
1108
1109         /* Result */
1110         return (more);
1111 }
1112
1113 /*!
1114  * @brief 「開ける」コマンドのメインルーチン /
1115  * Open a closed/locked/jammed door or a closed/locked chest.
1116  * @return なし
1117  * @details
1118  * Unlocking a locked door/chest is worth one experience point.
1119  */
1120 void do_cmd_open(void)
1121 {
1122         int y, x, dir;
1123
1124         s16b o_idx;
1125
1126         bool more = FALSE;
1127
1128         if (p_ptr->special_defense & KATA_MUSOU)
1129         {
1130                 set_action(ACTION_NONE);
1131         }
1132
1133 #ifdef ALLOW_EASY_OPEN /* TNB */
1134
1135         /* Option: Pick a direction */
1136         if (easy_open)
1137         {
1138                 int num_doors, num_chests;
1139
1140                 /* Count closed doors (locked or jammed) */
1141                 num_doors = count_dt(&y, &x, is_closed_door, FALSE);
1142
1143                 /* Count chests (locked) */
1144                 num_chests = count_chests(&y, &x, FALSE);
1145
1146                 /* See if only one target */
1147                 if (num_doors || num_chests)
1148                 {
1149                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
1150                             (num_chests > 1);
1151                         if (!too_many) command_dir = coords_to_dir(y, x);
1152                 }
1153         }
1154
1155 #endif /* ALLOW_EASY_OPEN -- TNB */
1156
1157         /* Allow repeated command */
1158         if (command_arg)
1159         {
1160                 /* Set repeat count */
1161                 command_rep = command_arg - 1;
1162
1163                 /* Redraw the state */
1164                 p_ptr->redraw |= (PR_STATE);
1165
1166                 /* Cancel the arg */
1167                 command_arg = 0;
1168         }
1169
1170         /* Get a "repeated" direction */
1171         if (get_rep_dir(&dir, TRUE))
1172         {
1173                 s16b feat;
1174                 cave_type *c_ptr;
1175
1176                 /* Get requested location */
1177                 y = p_ptr->y + ddy[dir];
1178                 x = p_ptr->x + ddx[dir];
1179
1180                 /* Get requested grid */
1181                 c_ptr = &cave[y][x];
1182
1183                 /* Feature code (applying "mimic" field) */
1184                 feat = get_feat_mimic(c_ptr);
1185
1186                 /* Check for chest */
1187                 o_idx = chest_check(y, x, FALSE);
1188
1189                 /* Nothing useful */
1190                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
1191                 {
1192                         /* Message */
1193                         msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
1194                 }
1195
1196                 /* Monster in the way */
1197                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
1198                 {
1199                         /* Take a turn */
1200                         p_ptr->energy_use = 100;
1201
1202                         /* Message */
1203                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1204                         
1205                         /* Attack */
1206                         py_attack(y, x, 0);
1207                 }
1208
1209                 /* Handle chests */
1210                 else if (o_idx)
1211                 {
1212                         /* Open the chest */
1213                         more = do_cmd_open_chest(y, x, o_idx);
1214                 }
1215
1216                 /* Handle doors */
1217                 else
1218                 {
1219                         /* Open the door */
1220                         more = do_cmd_open_aux(y, x);
1221                 }
1222         }
1223
1224         /* Cancel repeat unless we may continue */
1225         if (!more) disturb(0, 0);
1226 }
1227
1228
1229
1230 /*!
1231  * @brief 「閉じる」動作コマンドのサブルーチン /
1232  * Perform the basic "close" command
1233  * @param y 対象を行うマスのY座標
1234  * @param x 対象を行うマスのX座標
1235  * @return 実際に処理が行われた場合TRUEを返す。
1236  * @details
1237  * Assume destination is an open/broken door
1238  * Assume there is no monster blocking the destination
1239  * Returns TRUE if repeated commands may continue
1240  */
1241 static bool do_cmd_close_aux(int y, int x)
1242 {
1243         /* Get grid and contents */
1244         cave_type *c_ptr = &cave[y][x];
1245         s16b      old_feat = c_ptr->feat;
1246         bool      more = FALSE;
1247
1248         /* Take a turn */
1249         p_ptr->energy_use = 100;
1250
1251         /* Seeing true feature code (ignore mimic) */
1252
1253         /* Open door */
1254         if (have_flag(f_info[old_feat].flags, FF_CLOSE))
1255         {
1256                 s16b closed_feat = feat_state(old_feat, FF_CLOSE);
1257
1258                 /* Hack -- object in the way */
1259                 if ((c_ptr->o_idx || (c_ptr->info & CAVE_OBJECT)) &&
1260                     (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
1261                 {
1262                         /* Message */
1263                         msg_print(_("何かがつっかえて閉まらない。", "There seems stuck."));
1264                 }
1265                 else
1266                 {
1267                         /* Close the door */
1268                         cave_alter_feat(y, x, FF_CLOSE);
1269
1270                         /* Broken door */
1271                         if (old_feat == c_ptr->feat)
1272                         {
1273                                 /* Message */
1274                                 msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
1275                         }
1276                         else
1277                         {
1278                                 /* Sound */
1279                                 sound(SOUND_SHUTDOOR);
1280                         }
1281                 }
1282         }
1283
1284         /* Result */
1285         return (more);
1286 }
1287
1288
1289 /*!
1290  * @brief 「閉じる」コマンドのメインルーチン /
1291  * Close an open door.
1292  * @return なし
1293  * @details
1294  * Unlocking a locked door/chest is worth one experience point.
1295  */
1296 void do_cmd_close(void)
1297 {
1298         int y, x, dir;
1299
1300         bool more = FALSE;
1301
1302         if (p_ptr->special_defense & KATA_MUSOU)
1303         {
1304                 set_action(ACTION_NONE);
1305         }
1306
1307 #ifdef ALLOW_EASY_OPEN /* TNB */
1308
1309         /* Option: Pick a direction */
1310         if (easy_open)
1311         {
1312                 /* Count open doors */
1313                 if (count_dt(&y, &x, is_open, FALSE) == 1)
1314                 {
1315                         command_dir = coords_to_dir(y, x);
1316                 }
1317         }
1318
1319 #endif /* ALLOW_EASY_OPEN -- TNB */
1320
1321         /* Allow repeated command */
1322         if (command_arg)
1323         {
1324                 /* Set repeat count */
1325                 command_rep = command_arg - 1;
1326
1327                 /* Redraw the state */
1328                 p_ptr->redraw |= (PR_STATE);
1329
1330                 /* Cancel the arg */
1331                 command_arg = 0;
1332         }
1333
1334         /* Get a "repeated" direction */
1335         if (get_rep_dir(&dir,FALSE))
1336         {
1337                 cave_type *c_ptr;
1338                 s16b feat;
1339
1340                 /* Get requested location */
1341                 y = p_ptr->y + ddy[dir];
1342                 x = p_ptr->x + ddx[dir];
1343
1344                 /* Get grid and contents */
1345                 c_ptr = &cave[y][x];
1346
1347                 /* Feature code (applying "mimic" field) */
1348                 feat = get_feat_mimic(c_ptr);
1349
1350                 /* Require open/broken door */
1351                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
1352                 {
1353                         /* Message */
1354                         msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
1355                 }
1356
1357                 /* Monster in the way */
1358                 else if (c_ptr->m_idx)
1359                 {
1360                         /* Take a turn */
1361                         p_ptr->energy_use = 100;
1362
1363                         /* Message */
1364                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1365
1366                         /* Attack */
1367                         py_attack(y, x, 0);
1368                 }
1369
1370                 /* Close the door */
1371                 else
1372                 {
1373                         /* Close the door */
1374                         more = do_cmd_close_aux(y, x);
1375                 }
1376         }
1377
1378         /* Cancel repeat unless we may continue */
1379         if (!more) disturb(0, 0);
1380 }
1381
1382
1383 /*!
1384  * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
1385  * Determine if a given grid may be "tunneled"
1386  * @param y 対象を行うマスのY座標
1387  * @param x 対象を行うマスのX座標
1388  * @return 
1389  */
1390 static bool do_cmd_tunnel_test(int y, int x)
1391 {
1392         cave_type *c_ptr = &cave[y][x];
1393
1394         /* Must have knowledge */
1395         if (!(c_ptr->info & CAVE_MARK))
1396         {
1397                 /* Message */
1398                 msg_print(_("そこには何も見当たらない。", "You see nothing there."));
1399
1400                 /* Nope */
1401                 return (FALSE);
1402         }
1403
1404         /* Must be a wall/door/etc */
1405         if (!cave_have_flag_grid(c_ptr, FF_TUNNEL))
1406         {
1407                 /* Message */
1408                 msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
1409
1410                 /* Nope */
1411                 return (FALSE);
1412         }
1413
1414         /* Okay */
1415         return (TRUE);
1416 }
1417
1418
1419 /*!
1420  * @brief 「掘る」動作コマンドのサブルーチン /
1421  * Perform the basic "tunnel" command
1422  * @param y 対象を行うマスのY座標
1423  * @param x 対象を行うマスのX座標
1424  * @return 実際に処理が行われた場合TRUEを返す。
1425  * @details
1426  * Assumes that no monster is blocking the destination
1427  * Do not use twall anymore
1428  * Returns TRUE if repeated commands may continue
1429  */
1430 static bool do_cmd_tunnel_aux(int y, int x)
1431 {
1432         cave_type *c_ptr;
1433         feature_type *f_ptr, *mimic_f_ptr;
1434         int power;
1435         cptr name;
1436         bool more = FALSE;
1437
1438         /* Verify legality */
1439         if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1440
1441         /* Take a turn */
1442         p_ptr->energy_use = 100;
1443
1444         /* Get grid */
1445         c_ptr = &cave[y][x];
1446         f_ptr = &f_info[c_ptr->feat];
1447         power = f_ptr->power;
1448
1449         /* Feature code (applying "mimic" field) */
1450         mimic_f_ptr = &f_info[get_feat_mimic(c_ptr)];
1451
1452         name = f_name + mimic_f_ptr->name;
1453
1454         /* Sound */
1455         sound(SOUND_DIG);
1456
1457         if (have_flag(f_ptr->flags, FF_PERMANENT))
1458         {
1459                 /* Titanium */
1460                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1461                 {
1462                         msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
1463                 }
1464
1465                 /* Map border (mimiccing Permanent wall) */
1466                 else
1467                 {
1468                         msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
1469                 }
1470         }
1471
1472         /* Dig or tunnel */
1473         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1474         {
1475                 /* Dig */
1476                 if (p_ptr->skill_dig > randint0(20 * power))
1477                 {
1478                         /* Message */
1479                         msg_format(_("%sをくずした。", "You have removed the %s."), name);
1480
1481                         /* Remove the feature */
1482                         cave_alter_feat(y, x, FF_TUNNEL);
1483
1484                         /* Update some things */
1485                         p_ptr->update |= (PU_FLOW);
1486                 }
1487                 else
1488                 {
1489                         /* Message, keep digging */
1490                         msg_format(_("%sをくずしている。", "You dig into the %s."), name);
1491                         
1492                         more = TRUE;
1493                 }
1494         }
1495
1496         else
1497         {
1498                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1499
1500                 /* Tunnel */
1501                 if (p_ptr->skill_dig > power + randint0(40 * power))
1502                 {
1503                         if (tree) msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
1504                         else
1505                         {
1506                                 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
1507                                 p_ptr->update |= (PU_FLOW);
1508                         }
1509                         
1510                         /* Sound */
1511                         if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1512
1513                         /* Remove the feature */
1514                         cave_alter_feat(y, x, FF_TUNNEL);
1515
1516                         chg_virtue(V_DILIGENCE, 1);
1517                         chg_virtue(V_NATURE, -1);
1518                 }
1519
1520                 /* Keep trying */
1521                 else
1522                 {
1523                         if (tree)
1524                         {
1525                                 /* We may continue chopping */
1526                                 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
1527                                 /* Occasional Search XXX XXX */
1528                                 if (randint0(100) < 25) search();
1529                         }
1530                         else
1531                         {
1532                                 /* We may continue tunelling */
1533                                 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
1534                         }
1535
1536                         more = TRUE;
1537                 }
1538         }
1539
1540         if (is_hidden_door(c_ptr))
1541         {
1542                 /* Occasional Search XXX XXX */
1543                 if (randint0(100) < 25) search();
1544         }
1545
1546         /* Result */
1547         return more;
1548 }
1549
1550
1551 /*!
1552  * @brief 「掘る」動作コマンドのメインルーチン /
1553  * Tunnels through "walls" (including rubble and closed doors)
1554  * @return なし
1555  * @details
1556  * <pre>
1557  * Note that you must tunnel in order to hit invisible monsters
1558  * in walls, though moving into walls still takes a turn anyway.
1559  *
1560  * Digging is very difficult without a "digger" weapon, but can be
1561  * accomplished by strong players using heavy weapons.
1562  * </pre>
1563  */
1564 void do_cmd_tunnel(void)
1565 {
1566         int                     y, x, dir;
1567
1568         cave_type       *c_ptr;
1569         s16b feat;
1570
1571         bool            more = FALSE;
1572
1573
1574         if (p_ptr->special_defense & KATA_MUSOU)
1575         {
1576                 set_action(ACTION_NONE);
1577         }
1578
1579         /* Allow repeated command */
1580         if (command_arg)
1581         {
1582                 /* Set repeat count */
1583                 command_rep = command_arg - 1;
1584
1585                 /* Redraw the state */
1586                 p_ptr->redraw |= (PR_STATE);
1587
1588                 /* Cancel the arg */
1589                 command_arg = 0;
1590         }
1591
1592         /* Get a direction to tunnel, or Abort */
1593         if (get_rep_dir(&dir,FALSE))
1594         {
1595                 /* Get location */
1596                 y = p_ptr->y + ddy[dir];
1597                 x = p_ptr->x + ddx[dir];
1598
1599                 /* Get grid */
1600                 c_ptr = &cave[y][x];
1601
1602                 /* Feature code (applying "mimic" field) */
1603                 feat = get_feat_mimic(c_ptr);
1604
1605                 /* No tunnelling through doors */
1606                 if (have_flag(f_info[feat].flags, FF_DOOR))
1607                 {
1608                         /* Message */
1609                         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
1610                 }
1611
1612                 /* No tunnelling through most features */
1613                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1614                 {
1615                         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
1616                 }
1617
1618                 /* A monster is in the way */
1619                 else if (c_ptr->m_idx)
1620                 {
1621                         /* Take a turn */
1622                         p_ptr->energy_use = 100;
1623
1624                         /* Message */
1625                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1626
1627                         /* Attack */
1628                         py_attack(y, x, 0);
1629                 }
1630
1631                 /* Try digging */
1632                 else
1633                 {
1634                         /* Tunnel through walls */
1635                         more = do_cmd_tunnel_aux(y, x);
1636                 }
1637         }
1638
1639         /* Cancel repetition unless we can continue */
1640         if (!more) disturb(0, 0);
1641 }
1642
1643
1644 #ifdef ALLOW_EASY_OPEN /* TNB */
1645
1646 /*!
1647  * @brief 移動処理による簡易な「開く」処理 /
1648  * easy_open_door --
1649  * @return 開く処理が実際に試みられた場合TRUEを返す
1650  * @details
1651  * <pre>
1652  *      If there is a jammed/closed/locked door at the given location,
1653  *      then attempt to unlock/open it. Return TRUE if an attempt was
1654  *      made (successful or not), otherwise return FALSE.
1655  *
1656  *      The code here should be nearly identical to that in
1657  *      do_cmd_open_test() and do_cmd_open_aux().
1658  * </pre>
1659  */
1660 bool easy_open_door(int y, int x)
1661 {
1662         int i, j;
1663
1664         cave_type *c_ptr = &cave[y][x];
1665         feature_type *f_ptr = &f_info[c_ptr->feat];
1666
1667         /* Must be a closed door */
1668         if (!is_closed_door(c_ptr->feat))
1669         {
1670                 /* Nope */
1671                 return (FALSE);
1672         }
1673
1674         /* Jammed door */
1675         if (!have_flag(f_ptr->flags, FF_OPEN))
1676         {
1677                 /* Stuck */
1678                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(c_ptr)].name);
1679
1680         }
1681
1682         /* Locked door */
1683         else if (f_ptr->power)
1684         {
1685                 /* Disarm factor */
1686                 i = p_ptr->skill_dis;
1687
1688                 /* Penalize some conditions */
1689                 if (p_ptr->blind || no_lite()) i = i / 10;
1690                 if (p_ptr->confused || p_ptr->image) i = i / 10;
1691
1692                 /* Extract the lock power */
1693                 j = f_ptr->power;
1694
1695                 /* Extract the difficulty XXX XXX XXX */
1696                 j = i - (j * 4);
1697
1698                 /* Always have a small chance of success */
1699                 if (j < 2) j = 2;
1700
1701                 /* Success */
1702                 if (randint0(100) < j)
1703                 {
1704                         /* Message */
1705                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1706
1707                         /* Open the door */
1708                         cave_alter_feat(y, x, FF_OPEN);
1709
1710                         /* Sound */
1711                         sound(SOUND_OPENDOOR);
1712
1713                         /* Experience */
1714                         gain_exp(1);
1715                 }
1716
1717                 /* Failure */
1718                 else
1719                 {
1720                         /* Failure */
1721                         if (flush_failure) flush();
1722
1723                         /* Message */
1724                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1725
1726                 }
1727         }
1728
1729         /* Closed door */
1730         else
1731         {
1732                 /* Open the door */
1733                 cave_alter_feat(y, x, FF_OPEN);
1734
1735                 /* Sound */
1736                 sound(SOUND_OPENDOOR);
1737         }
1738
1739         /* Result */
1740         return (TRUE);
1741 }
1742
1743 #endif /* ALLOW_EASY_OPEN -- TNB */
1744
1745
1746 /*!
1747  * @brief 箱のトラップを解除するコマンドのメインルーチン /
1748  * Perform the basic "disarm" command
1749  * @param y 解除を行うマスのY座標
1750  * @param x 解除を行うマスのX座標
1751  * @param o_idx 箱のオブジェクトID
1752  * @return ターンを消費する処理が行われた場合TRUEを返す
1753  * @details
1754  * <pre>
1755  * Assume destination is a visible trap
1756  * Assume there is no monster blocking the destination
1757  * Returns TRUE if repeated commands may continue
1758  * </pre>
1759  */
1760 static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
1761 {
1762         int i, j;
1763
1764         bool more = FALSE;
1765
1766         object_type *o_ptr = &o_list[o_idx];
1767
1768
1769         /* Take a turn */
1770         p_ptr->energy_use = 100;
1771
1772         /* Get the "disarm" factor */
1773         i = p_ptr->skill_dis;
1774
1775         /* Penalize some conditions */
1776         if (p_ptr->blind || no_lite()) i = i / 10;
1777         if (p_ptr->confused || p_ptr->image) i = i / 10;
1778
1779         /* Extract the difficulty */
1780         j = i - o_ptr->pval;
1781
1782         /* Always have a small chance of success */
1783         if (j < 2) j = 2;
1784
1785         /* Must find the trap first. */
1786         if (!object_is_known(o_ptr))
1787         {
1788                 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
1789
1790         }
1791
1792         /* Already disarmed/unlocked */
1793         else if (o_ptr->pval <= 0)
1794         {
1795                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1796         }
1797
1798         /* No traps to find. */
1799         else if (!chest_traps[o_ptr->pval])
1800         {
1801                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1802         }
1803
1804         /* Success (get a lot of experience) */
1805         else if (randint0(100) < j)
1806         {
1807                 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
1808                 gain_exp(o_ptr->pval);
1809                 o_ptr->pval = (0 - o_ptr->pval);
1810         }
1811
1812         /* Failure -- Keep trying */
1813         else if ((i > 5) && (randint1(i) > 5))
1814         {
1815                 /* We may keep trying */
1816                 more = TRUE;
1817                 if (flush_failure) flush();
1818                 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
1819         }
1820
1821         /* Failure -- Set off the trap */
1822         else
1823         {
1824                 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
1825                 sound(SOUND_FAIL);
1826                 chest_trap(y, x, o_idx);
1827         }
1828
1829         /* Result */
1830         return (more);
1831 }
1832
1833
1834 /*!
1835  * @brief 箱のトラップを解除するコマンドのサブルーチン /
1836  * Perform the basic "disarm" command
1837  * @param y 解除を行うマスのY座標
1838  * @param x 解除を行うマスのX座標
1839  * @param dir プレイヤーからみた方向ID
1840  * @return ターンを消費する処理が行われた場合TRUEを返す
1841  * @details
1842  * <pre>
1843  * Assume destination is a visible trap
1844  * Assume there is no monster blocking the destination
1845  * Returns TRUE if repeated commands may continue
1846  * </pre>
1847  */
1848 #ifdef ALLOW_EASY_DISARM /* TNB */
1849
1850 bool do_cmd_disarm_aux(int y, int x, int dir)
1851
1852 #else /* ALLOW_EASY_DISARM -- TNB */
1853
1854 static bool do_cmd_disarm_aux(int y, int x, int dir)
1855
1856 #endif /* ALLOW_EASY_DISARM -- TNB */
1857 {
1858         /* Get grid and contents */
1859         cave_type *c_ptr = &cave[y][x];
1860
1861         /* Get feature */
1862         feature_type *f_ptr = &f_info[c_ptr->feat];
1863
1864         /* Access trap name */
1865         cptr name = (f_name + f_ptr->name);
1866
1867         /* Extract trap "power" */
1868         int power = f_ptr->power;
1869
1870         bool more = FALSE;
1871
1872         /* Get the "disarm" factor */
1873         int i = p_ptr->skill_dis;
1874
1875         int j;
1876
1877         /* Take a turn */
1878         p_ptr->energy_use = 100;
1879
1880         /* Penalize some conditions */
1881         if (p_ptr->blind || no_lite()) i = i / 10;
1882         if (p_ptr->confused || p_ptr->image) i = i / 10;
1883
1884         /* Extract the difficulty */
1885         j = i - power;
1886
1887         /* Always have a small chance of success */
1888         if (j < 2) j = 2;
1889
1890         /* Success */
1891         if (randint0(100) < j)
1892         {
1893                 /* Message */
1894                 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
1895                 
1896                 /* Reward */
1897                 gain_exp(power);
1898
1899                 /* Remove the trap */
1900                 cave_alter_feat(y, x, FF_DISARM);
1901
1902 #ifdef ALLOW_EASY_DISARM /* TNB */
1903
1904                 /* Move the player onto the trap */
1905                 move_player(dir, easy_disarm, FALSE);
1906
1907 #else /* ALLOW_EASY_DISARM -- TNB */
1908
1909                 /* move the player onto the trap grid */
1910                 move_player(dir, FALSE, FALSE);
1911
1912 #endif /* ALLOW_EASY_DISARM -- TNB */
1913         }
1914
1915         /* Failure -- Keep trying */
1916         else if ((i > 5) && (randint1(i) > 5))
1917         {
1918                 /* Failure */
1919                 if (flush_failure) flush();
1920
1921                 /* Message */
1922                 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
1923
1924                 /* We may keep trying */
1925                 more = TRUE;
1926         }
1927
1928         /* Failure -- Set off the trap */
1929         else
1930         {
1931                 /* Message */
1932                 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
1933
1934 #ifdef ALLOW_EASY_DISARM /* TNB */
1935
1936                 /* Move the player onto the trap */
1937                 move_player(dir, easy_disarm, FALSE);
1938
1939 #else /* ALLOW_EASY_DISARM -- TNB */
1940
1941                 /* Move the player onto the trap */
1942                 move_player(dir, FALSE, FALSE);
1943
1944 #endif /* ALLOW_EASY_DISARM -- TNB */
1945         }
1946
1947         /* Result */
1948         return (more);
1949 }
1950
1951
1952 /*!
1953  * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
1954  * Disarms a trap, or chest
1955  * @return なし
1956  */
1957 void do_cmd_disarm(void)
1958 {
1959         int y, x, dir;
1960
1961         s16b o_idx;
1962
1963         bool more = FALSE;
1964
1965         if (p_ptr->special_defense & KATA_MUSOU)
1966         {
1967                 set_action(ACTION_NONE);
1968         }
1969
1970 #ifdef ALLOW_EASY_DISARM /* TNB */
1971
1972         /* Option: Pick a direction */
1973         if (easy_disarm)
1974         {
1975                 int num_traps, num_chests;
1976
1977                 /* Count visible traps */
1978                 num_traps = count_dt(&y, &x, is_trap, TRUE);
1979
1980                 /* Count chests (trapped) */
1981                 num_chests = count_chests(&y, &x, TRUE);
1982
1983                 /* See if only one target */
1984                 if (num_traps || num_chests)
1985                 {
1986                         bool too_many = (num_traps && num_chests) || (num_traps > 1) ||
1987                             (num_chests > 1);
1988                         if (!too_many) command_dir = coords_to_dir(y, x);
1989                 }
1990         }
1991
1992 #endif /* ALLOW_EASY_DISARM -- TNB */
1993
1994         /* Allow repeated command */
1995         if (command_arg)
1996         {
1997                 /* Set repeat count */
1998                 command_rep = command_arg - 1;
1999
2000                 /* Redraw the state */
2001                 p_ptr->redraw |= (PR_STATE);
2002
2003                 /* Cancel the arg */
2004                 command_arg = 0;
2005         }
2006
2007         /* Get a direction (or abort) */
2008         if (get_rep_dir(&dir,TRUE))
2009         {
2010                 cave_type *c_ptr;
2011                 s16b feat;
2012
2013                 /* Get location */
2014                 y = p_ptr->y + ddy[dir];
2015                 x = p_ptr->x + ddx[dir];
2016
2017                 /* Get grid and contents */
2018                 c_ptr = &cave[y][x];
2019
2020                 /* Feature code (applying "mimic" field) */
2021                 feat = get_feat_mimic(c_ptr);
2022
2023                 /* Check for chests */
2024                 o_idx = chest_check(y, x, TRUE);
2025
2026                 /* Disarm a trap */
2027                 if (!is_trap(feat) && !o_idx)
2028                 {
2029                         /* Message */
2030                         msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
2031                 }
2032
2033                 /* Monster in the way */
2034                 else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
2035                 {
2036                         /* Message */
2037                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2038
2039                         /* Attack */
2040                         py_attack(y, x, 0);
2041                 }
2042
2043                 /* Disarm chest */
2044                 else if (o_idx)
2045                 {
2046                         /* Disarm the chest */
2047                         more = do_cmd_disarm_chest(y, x, o_idx);
2048                 }
2049
2050                 /* Disarm trap */
2051                 else
2052                 {
2053                         /* Disarm the trap */
2054                         more = do_cmd_disarm_aux(y, x, dir);
2055                 }
2056         }
2057
2058         /* Cancel repeat unless told not to */
2059         if (!more) disturb(0, 0);
2060 }
2061
2062
2063 /*!
2064  * @brief 「打ち破る」動作コマンドのサブルーチン /
2065  * Perform the basic "bash" command
2066  * @param y 対象を行うマスのY座標
2067  * @param x 対象を行うマスのX座標
2068  * @param dir プレイヤーから見たターゲットの方角ID
2069  * @return 実際に処理が行われた場合TRUEを返す。
2070  * @details
2071  * <pre>
2072  * Assume destination is a closed/locked/jammed door
2073  * Assume there is no monster blocking the destination
2074  * Returns TRUE if repeated commands may continue
2075  * </pre>
2076  */
2077 static bool do_cmd_bash_aux(int y, int x, int dir)
2078 {
2079         /* Get grid */
2080         cave_type       *c_ptr = &cave[y][x];
2081
2082         /* Get feature */
2083         feature_type *f_ptr = &f_info[c_ptr->feat];
2084
2085         /* Hack -- Bash power based on strength */
2086         /* (Ranges from 3 to 20 to 100 to 200) */
2087         int bash = adj_str_blow[p_ptr->stat_ind[A_STR]];
2088
2089         /* Extract door power */
2090         int temp = f_ptr->power;
2091
2092         bool            more = FALSE;
2093
2094         cptr name = f_name + f_info[get_feat_mimic(c_ptr)].name;
2095
2096         /* Take a turn */
2097         p_ptr->energy_use = 100;
2098
2099         /* Message */
2100         msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
2101
2102         /* Compare bash power to door power XXX XXX XXX */
2103         temp = (bash - (temp * 10));
2104
2105         if (p_ptr->pclass == CLASS_BERSERKER) temp *= 2;
2106
2107         /* Hack -- always have a chance */
2108         if (temp < 1) temp = 1;
2109
2110         /* Hack -- attempt to bash down the door */
2111         if (randint0(100) < temp)
2112         {
2113                 /* Message */
2114                 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
2115
2116                 /* Sound */
2117                 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
2118
2119                 /* Break down the door */
2120                 if ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
2121                 {
2122                         cave_alter_feat(y, x, FF_BASH);
2123                 }
2124
2125                 /* Open the door */
2126                 else
2127                 {
2128                         cave_alter_feat(y, x, FF_OPEN);
2129                 }
2130
2131                 /* Hack -- Fall through the door */
2132                 move_player(dir, FALSE, FALSE);
2133         }
2134
2135         /* Saving throw against stun */
2136         else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
2137                  p_ptr->lev)
2138         {
2139                 /* Message */
2140                 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
2141
2142                 /* Allow repeated bashing */
2143                 more = TRUE;
2144         }
2145
2146         /* High dexterity yields coolness */
2147         else
2148         {
2149                 /* Message */
2150                 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
2151
2152                 /* Hack -- Lose balance ala paralysis */
2153                 (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
2154         }
2155
2156         /* Result */
2157         return (more);
2158 }
2159
2160
2161 /*!
2162  * @brief 「打ち破る」動作コマンドのメインルーチン /
2163  * Bash open a door, success based on character strength
2164  * @return なし
2165  * @details
2166  * <pre>
2167  * For a closed door, pval is positive if locked; negative if stuck.
2168  *
2169  * For an open door, pval is positive for a broken door.
2170  *
2171  * A closed door can be opened - harder if locked. Any door might be
2172  * bashed open (and thereby broken). Bashing a door is (potentially)
2173  * faster! You move into the door way. To open a stuck door, it must
2174  * be bashed. A closed door can be jammed (see do_cmd_spike()).
2175  *
2176  * Creatures can also open or bash doors, see elsewhere.
2177  * </pre>
2178  */
2179 void do_cmd_bash(void)
2180 {
2181         int                     y, x, dir;
2182
2183         cave_type       *c_ptr;
2184
2185         bool            more = FALSE;
2186
2187
2188         if (p_ptr->special_defense & KATA_MUSOU)
2189         {
2190                 set_action(ACTION_NONE);
2191         }
2192
2193         /* Allow repeated command */
2194         if (command_arg)
2195         {
2196                 /* Set repeat count */
2197                 command_rep = command_arg - 1;
2198
2199                 /* Redraw the state */
2200                 p_ptr->redraw |= (PR_STATE);
2201
2202                 /* Cancel the arg */
2203                 command_arg = 0;
2204         }
2205
2206         /* Get a "repeated" direction */
2207         if (get_rep_dir(&dir,FALSE))
2208         {
2209                 s16b feat;
2210
2211                 /* Bash location */
2212                 y = p_ptr->y + ddy[dir];
2213                 x = p_ptr->x + ddx[dir];
2214
2215                 /* Get grid */
2216                 c_ptr = &cave[y][x];
2217
2218                 /* Feature code (applying "mimic" field) */
2219                 feat = get_feat_mimic(c_ptr);
2220
2221                 /* Nothing useful */
2222                 if (!have_flag(f_info[feat].flags, FF_BASH))
2223                 {
2224                         /* Message */
2225                         msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
2226                 }
2227
2228                 /* Monster in the way */
2229                 else if (c_ptr->m_idx)
2230                 {
2231                         /* Take a turn */
2232                         p_ptr->energy_use = 100;
2233
2234                         /* Message */
2235                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2236
2237                         /* Attack */
2238                         py_attack(y, x, 0);
2239                 }
2240
2241                 /* Bash a closed door */
2242                 else
2243                 {
2244                         /* Bash the door */
2245                         more = do_cmd_bash_aux(y, x, dir);
2246                 }
2247         }
2248
2249         /* Unless valid action taken, cancel bash */
2250         if (!more) disturb(0, 0);
2251 }
2252
2253
2254 /*!
2255  * @brief 特定のマスに影響を及ぼすための汎用的コマンド
2256  * @return なし
2257  * @details
2258  * <pre>
2259  * Manipulate an adjacent grid in some way
2260  *
2261  * Attack monsters, tunnel through walls, disarm traps, open doors.
2262  *
2263  * Consider confusion XXX XXX XXX
2264  *
2265  * This command must always take a turn, to prevent free detection
2266  * of invisible monsters.
2267  * </pre>
2268  */
2269 void do_cmd_alter(void)
2270 {
2271         int                     y, x, dir;
2272
2273         cave_type       *c_ptr;
2274
2275         bool            more = FALSE;
2276
2277
2278         if (p_ptr->special_defense & KATA_MUSOU)
2279         {
2280                 set_action(ACTION_NONE);
2281         }
2282
2283         /* Allow repeated command */
2284         if (command_arg)
2285         {
2286                 /* Set repeat count */
2287                 command_rep = command_arg - 1;
2288
2289                 /* Redraw the state */
2290                 p_ptr->redraw |= (PR_STATE);
2291
2292                 /* Cancel the arg */
2293                 command_arg = 0;
2294         }
2295
2296         /* Get a direction */
2297         if (get_rep_dir(&dir,TRUE))
2298         {
2299                 s16b feat;
2300                 feature_type *f_ptr;
2301
2302                 /* Get location */
2303                 y = p_ptr->y + ddy[dir];
2304                 x = p_ptr->x + ddx[dir];
2305
2306                 /* Get grid */
2307                 c_ptr = &cave[y][x];
2308
2309                 /* Feature code (applying "mimic" field) */
2310                 feat = get_feat_mimic(c_ptr);
2311                 f_ptr = &f_info[feat];
2312
2313                 /* Take a turn */
2314                 p_ptr->energy_use = 100;
2315
2316                 /* Attack monsters */
2317                 if (c_ptr->m_idx)
2318                 {
2319                         /* Attack */
2320                         py_attack(y, x, 0);
2321                 }
2322
2323                 /* Locked doors */
2324                 else if (have_flag(f_ptr->flags, FF_OPEN))
2325                 {
2326                         more = do_cmd_open_aux(y, x);
2327                 }
2328
2329                 /* Bash jammed doors */
2330                 else if (have_flag(f_ptr->flags, FF_BASH))
2331                 {
2332                         more = do_cmd_bash_aux(y, x, dir);
2333                 }
2334
2335                 /* Tunnel through walls */
2336                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
2337                 {
2338                         more = do_cmd_tunnel_aux(y, x);
2339                 }
2340
2341                 /* Close open doors */
2342                 else if (have_flag(f_ptr->flags, FF_CLOSE))
2343                 {
2344                         more = do_cmd_close_aux(y, x);
2345                 }
2346
2347                 /* Disarm traps */
2348                 else if (have_flag(f_ptr->flags, FF_DISARM))
2349                 {
2350                         more = do_cmd_disarm_aux(y, x, dir);
2351                 }
2352
2353                 /* Oops */
2354                 else
2355                 {
2356                         /* Oops */
2357                         msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
2358                 }
2359         }
2360
2361         /* Cancel repetition unless we can continue */
2362         if (!more) disturb(0, 0);
2363 }
2364
2365
2366
2367 /*!
2368  * @brief 「くさびを打つ」ために必要なオブジェクトがあるかどうかの判定を返す /
2369  * Find the index of some "spikes", if possible.
2370  * @param ip くさびとして打てるオブジェクトのID
2371  * @return オブジェクトがある場合TRUEを返す
2372  * @details
2373  * <pre>
2374  * XXX XXX XXX Let user choose a pile of spikes, perhaps?
2375  * </pre>
2376  */
2377 static bool get_spike(int *ip)
2378 {
2379         int i;
2380
2381         /* Check every item in the pack */
2382         for (i = 0; i < INVEN_PACK; i++)
2383         {
2384                 object_type *o_ptr = &inventory[i];
2385
2386                 /* Skip non-objects */
2387                 if (!o_ptr->k_idx) continue;
2388
2389                 /* Check the "tval" code */
2390                 if (o_ptr->tval == TV_SPIKE)
2391                 {
2392                         /* Save the spike index */
2393                         (*ip) = i;
2394
2395                         /* Success */
2396                         return (TRUE);
2397                 }
2398         }
2399
2400         /* Oops */
2401         return (FALSE);
2402 }
2403
2404
2405 /*!
2406  * @brief 「くさびを打つ」動作コマンドのメインルーチン /
2407  * Jam a closed door with a spike
2408  * @return なし
2409  * @details
2410  * <pre>
2411  * This command may NOT be repeated
2412  * </pre>
2413  */
2414 void do_cmd_spike(void)
2415 {
2416         int dir;
2417
2418         if (p_ptr->special_defense & KATA_MUSOU)
2419         {
2420                 set_action(ACTION_NONE);
2421         }
2422
2423         /* Get a "repeated" direction */
2424         if (get_rep_dir(&dir,FALSE))
2425         {
2426                 int y, x, item;
2427                 cave_type *c_ptr;
2428                 s16b feat;
2429
2430                 /* Get location */
2431                 y = p_ptr->y + ddy[dir];
2432                 x = p_ptr->x + ddx[dir];
2433
2434                 /* Get grid and contents */
2435                 c_ptr = &cave[y][x];
2436
2437                 /* Feature code (applying "mimic" field) */
2438                 feat = get_feat_mimic(c_ptr);
2439
2440                 /* Require closed door */
2441                 if (!have_flag(f_info[feat].flags, FF_SPIKE))
2442                 {
2443                         /* Message */
2444                         msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
2445                 }
2446
2447                 /* Get a spike */
2448                 else if (!get_spike(&item))
2449                 {
2450                         /* Message */
2451                         msg_print(_("くさびを持っていない!", "You have no spikes!"));
2452                 }
2453
2454                 /* Is a monster in the way? */
2455                 else if (c_ptr->m_idx)
2456                 {
2457                         /* Take a turn */
2458                         p_ptr->energy_use = 100;
2459
2460                         /* Message */
2461                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2462
2463                         /* Attack */
2464                         py_attack(y, x, 0);
2465                 }
2466
2467                 /* Go for it */
2468                 else
2469                 {
2470                         /* Take a turn */
2471                         p_ptr->energy_use = 100;
2472
2473                         /* Successful jamming */
2474                         msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_name + f_info[feat].name);
2475                         cave_alter_feat(y, x, FF_SPIKE);
2476
2477                         /* Use up, and describe, a single spike, from the bottom */
2478                         inven_item_increase(item, -1);
2479                         inven_item_describe(item);
2480                         inven_item_optimize(item);
2481                 }
2482         }
2483 }
2484
2485
2486
2487 /*!
2488  * @brief 「歩く」動作コマンドのメインルーチン /
2489  * Support code for the "Walk" and "Jump" commands
2490  * @param pickup アイテムの自動拾いを行うならTRUE
2491  * @return なし
2492  */
2493 void do_cmd_walk(bool pickup)
2494 {
2495         int dir;
2496
2497         bool more = FALSE;
2498
2499
2500         /* Allow repeated command */
2501         if (command_arg)
2502         {
2503                 /* Set repeat count */
2504                 command_rep = command_arg - 1;
2505
2506                 /* Redraw the state */
2507                 p_ptr->redraw |= (PR_STATE);
2508
2509                 /* Cancel the arg */
2510                 command_arg = 0;
2511         }
2512
2513         /* Get a "repeated" direction */
2514         if (get_rep_dir(&dir,FALSE))
2515         {
2516                 /* Take a turn */
2517                 p_ptr->energy_use = 100;
2518
2519                 if ((dir != 5) && (p_ptr->special_defense & KATA_MUSOU))
2520                 {
2521                         set_action(ACTION_NONE);
2522                 }
2523
2524                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2525                 if (p_ptr->wild_mode) p_ptr->energy_use *= ((MAX_HGT + MAX_WID) / 2);
2526                 if (p_ptr->action == ACTION_HAYAGAKE) p_ptr->energy_use = p_ptr->energy_use * (45-(p_ptr->lev/2)) / 100;
2527
2528                 /* Actually move the character */
2529                 move_player(dir, pickup, FALSE);
2530
2531                 /* Allow more walking */
2532                 more = TRUE;
2533         }
2534
2535         /* Hack again -- Is there a special encounter ??? */
2536         if (p_ptr->wild_mode && !cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_TOWN))
2537         {
2538                 int tmp = 120 + p_ptr->lev*10 - wilderness[p_ptr->y][p_ptr->x].level + 5;
2539                 if (tmp < 1) 
2540                         tmp = 1;
2541                 if (((wilderness[p_ptr->y][p_ptr->x].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
2542                 {
2543                         /* Inform the player of his horrible fate :=) */
2544                         msg_print(_("襲撃だ!", "You are ambushed !"));
2545
2546                         /* Go into large wilderness view */
2547                         p_ptr->oldpy = randint1(MAX_HGT-2);
2548                         p_ptr->oldpx = randint1(MAX_WID-2);
2549                         change_wild_mode();
2550
2551                         /* Give first move to monsters */
2552                         p_ptr->energy_use = 100;
2553
2554                         /* HACk -- set the encouter flag for the wilderness generation */
2555                         generate_encounter = TRUE;
2556                 }
2557         }
2558
2559         /* Cancel repeat unless we may continue */
2560         if (!more) disturb(0, 0);
2561 }
2562
2563
2564 /*!
2565  * @brief 「走る」動作コマンドのメインルーチン /
2566  * Start running.
2567  * @return なし
2568  */
2569 void do_cmd_run(void)
2570 {
2571         int dir;
2572
2573         /* Hack -- no running when confused */
2574         if (p_ptr->confused)
2575         {
2576                 msg_print(_("混乱していて走れない!", "You are too confused!"));
2577                 return;
2578         }
2579
2580         if (p_ptr->special_defense & KATA_MUSOU)
2581         {
2582                 set_action(ACTION_NONE);
2583         }
2584
2585         /* Get a "repeated" direction */
2586         if (get_rep_dir(&dir,FALSE))
2587         {
2588                 /* Hack -- Set the run counter */
2589                 running = (command_arg ? command_arg : 1000);
2590
2591                 /* First step */
2592                 run_step(dir);
2593         }
2594 }
2595
2596
2597 /*!
2598  * @brief 「留まる」動作コマンドのメインルーチン /
2599  * Stay still.  Search.  Enter stores.
2600  * Pick up treasure if "pickup" is true.
2601  * @param pickup アイテムの自動拾いを行うならTRUE
2602  * @return なし
2603  */
2604 void do_cmd_stay(bool pickup)
2605 {
2606         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2607
2608         /* Allow repeated command */
2609         if (command_arg)
2610         {
2611                 /* Set repeat count */
2612                 command_rep = command_arg - 1;
2613
2614                 /* Redraw the state */
2615                 p_ptr->redraw |= (PR_STATE);
2616
2617                 /* Cancel the arg */
2618                 command_arg = 0;
2619         }
2620
2621         /* Take a turn */
2622         p_ptr->energy_use = 100;
2623
2624         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2625         (void)move_player_effect(p_ptr->y, p_ptr->x, mpe_mode);
2626 }
2627
2628
2629 /*!
2630  * @brief 「休む」動作コマンドのメインルーチン /
2631  * Resting allows a player to safely restore his hp     -RAK-
2632  * @return なし
2633  */
2634 void do_cmd_rest(void)
2635 {
2636
2637         set_action(ACTION_NONE);
2638
2639         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] || p_ptr->magic_num1[1]))
2640         {
2641                 stop_singing();
2642         }
2643
2644         /* Hex */
2645         if (hex_spelling_any()) stop_hex_spell_all();
2646
2647         /* Prompt for time if needed */
2648         if (command_arg <= 0)
2649         {
2650                 cptr p = _("休憩 (0-9999, '*' で HP/MP全快, '&' で必要なだけ): ", 
2651                                    "Rest (0-9999, '*' for HP/SP, '&' as needed): ");
2652
2653
2654                 char out_val[80];
2655
2656                 /* Default */
2657                 strcpy(out_val, "&");
2658
2659                 /* Ask for duration */
2660                 if (!get_string(p, out_val, 4)) return;
2661
2662                 /* Rest until done */
2663                 if (out_val[0] == '&')
2664                 {
2665                         command_arg = (-2);
2666                 }
2667
2668                 /* Rest a lot */
2669                 else if (out_val[0] == '*')
2670                 {
2671                         command_arg = (-1);
2672                 }
2673
2674                 /* Rest some */
2675                 else
2676                 {
2677                         command_arg = atoi(out_val);
2678                         if (command_arg <= 0) return;
2679                 }
2680         }
2681
2682
2683         /* Paranoia */
2684         if (command_arg > 9999) command_arg = 9999;
2685
2686         if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
2687
2688         /* Take a turn XXX XXX XXX (?) */
2689         p_ptr->energy_use = 100;
2690
2691         /* The sin of sloth */
2692         if (command_arg > 100)
2693                 chg_virtue(V_DILIGENCE, -1);
2694         
2695         /* Why are you sleeping when there's no need?  WAKE UP!*/
2696         if ((p_ptr->chp == p_ptr->mhp) &&
2697             (p_ptr->csp == p_ptr->msp) &&
2698             !p_ptr->blind && !p_ptr->confused &&
2699             !p_ptr->poisoned && !p_ptr->afraid &&
2700             !p_ptr->stun && !p_ptr->cut &&
2701             !p_ptr->slow && !p_ptr->paralyzed &&
2702             !p_ptr->image && !p_ptr->word_recall &&
2703             !p_ptr->alter_reality)
2704                         chg_virtue(V_DILIGENCE, -1);
2705
2706         /* Save the rest code */
2707         resting = command_arg;
2708         p_ptr->action = ACTION_REST;
2709
2710         /* Recalculate bonuses */
2711         p_ptr->update |= (PU_BONUS);
2712
2713         /* Redraw the state */
2714         p_ptr->redraw |= (PR_STATE);
2715
2716         /* Handle stuff */
2717         handle_stuff();
2718
2719         /* Refresh */
2720         Term_fresh();
2721 }
2722
2723
2724 /*!
2725  * @brief 矢弾を射撃した場合の破損確率を返す /
2726  * Determines the odds of an object breaking when thrown at a monster
2727  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2728  * @return 破損確率(%)
2729  * @details
2730  * Note that artifacts never break, see the "drop_near()" function.
2731  */
2732 static int breakage_chance(object_type *o_ptr)
2733 {
2734         int archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (p_ptr->lev-1)/7 + 4: 0);
2735
2736         /* Examine the snipe type */
2737         if (snipe_type)
2738         {
2739                 if (snipe_type == SP_KILL_WALL) return (100);
2740                 if (snipe_type == SP_EXPLODE) return (100);
2741                 if (snipe_type == SP_PIERCE) return (100);
2742                 if (snipe_type == SP_FINAL) return (100);
2743                 if (snipe_type == SP_NEEDLE) return (100);
2744                 if (snipe_type == SP_EVILNESS) return (40);
2745                 if (snipe_type == SP_HOLYNESS) return (40);
2746         }
2747
2748         /* Examine the item type */
2749         switch (o_ptr->tval)
2750         {
2751                 /* Always break */
2752                 case TV_FLASK:
2753                 case TV_POTION:
2754                 case TV_BOTTLE:
2755                 case TV_FOOD:
2756                 case TV_JUNK:
2757                         return (100);
2758
2759                 /* Often break */
2760                 case TV_LITE:
2761                 case TV_SCROLL:
2762                 case TV_SKELETON:
2763                         return (50);
2764
2765                 /* Sometimes break */
2766                 case TV_WAND:
2767                 case TV_SPIKE:
2768                         return (25);
2769                 case TV_ARROW:
2770                         return (20 - archer_bonus * 2);
2771
2772                 /* Rarely break */
2773                 case TV_SHOT:
2774                 case TV_BOLT:
2775                         return (10 - archer_bonus);
2776                 default:
2777                         return (10);
2778         }
2779 }
2780
2781
2782 /*!
2783  * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
2784  * Determines the odds of an object breaking when thrown at a monster
2785  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2786  * @param tdam 計算途中のダメージ量
2787  * @param m_ptr 目標モンスターの構造体参照ポインタ
2788  * @return スレイ倍率をかけたダメージ量
2789  */
2790 static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
2791 {
2792         int mult = 10;
2793
2794         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2795
2796         u32b flgs[TR_FLAG_SIZE];
2797
2798         /* Extract the flags */
2799         object_flags(o_ptr, flgs);
2800
2801         /* Some "weapons" and "ammo" do extra damage */
2802         switch (o_ptr->tval)
2803         {
2804                 case TV_SHOT:
2805                 case TV_ARROW:
2806                 case TV_BOLT:
2807                 {
2808                         /* Slay Animal */
2809                         if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
2810                             (r_ptr->flags3 & RF3_ANIMAL))
2811                         {
2812                                 if (is_original_ap_and_seen(m_ptr))
2813                                 {
2814                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2815                                 }
2816
2817                                 if (mult < 17) mult = 17;
2818                         }
2819
2820                         /* Kill Animal */
2821                         if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
2822                             (r_ptr->flags3 & RF3_ANIMAL))
2823                         {
2824                                 if (is_original_ap_and_seen(m_ptr))
2825                                 {
2826                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2827                                 }
2828
2829                                 if (mult < 27) mult = 27;
2830                         }
2831
2832                         /* Slay Evil */
2833                         if ((have_flag(flgs, TR_SLAY_EVIL)) &&
2834                             (r_ptr->flags3 & RF3_EVIL))
2835                         {
2836                                 if (is_original_ap_and_seen(m_ptr))
2837                                 {
2838                                         r_ptr->r_flags3 |= RF3_EVIL;
2839                                 }
2840
2841                                 if (mult < 15) mult = 15;
2842                         }
2843
2844                         /* Kill Evil */
2845                         if ((have_flag(flgs, TR_KILL_EVIL)) &&
2846                             (r_ptr->flags3 & RF3_EVIL))
2847                         {
2848                                 if (is_original_ap_and_seen(m_ptr))
2849                                 {
2850                                         r_ptr->r_flags3 |= RF3_EVIL;
2851                                 }
2852
2853                                 if (mult < 25) mult = 25;
2854                         }
2855
2856                         /* Slay Human */
2857                         if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
2858                             (r_ptr->flags2 & RF2_HUMAN))
2859                         {
2860                                 if (is_original_ap_and_seen(m_ptr))
2861                                 {
2862                                         r_ptr->r_flags2 |= RF2_HUMAN;
2863                                 }
2864
2865                                 if (mult < 17) mult = 17;
2866                         }
2867
2868                         /* Kill Human */
2869                         if ((have_flag(flgs, TR_KILL_HUMAN)) &&
2870                             (r_ptr->flags2 & RF2_HUMAN))
2871                         {
2872                                 if (is_original_ap_and_seen(m_ptr))
2873                                 {
2874                                         r_ptr->r_flags2 |= RF2_HUMAN;
2875                                 }
2876
2877                                 if (mult < 27) mult = 27;
2878                         }
2879
2880                         /* Slay Undead */
2881                         if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
2882                             (r_ptr->flags3 & RF3_UNDEAD))
2883                         {
2884                                 if (is_original_ap_and_seen(m_ptr))
2885                                 {
2886                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2887                                 }
2888
2889                                 if (mult < 20) mult = 20;
2890                         }
2891
2892                         /* Kill Undead */
2893                         if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
2894                             (r_ptr->flags3 & RF3_UNDEAD))
2895                         {
2896                                 if (is_original_ap_and_seen(m_ptr))
2897                                 {
2898                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2899                                 }
2900
2901                                 if (mult < 30) mult = 30;
2902                         }
2903
2904                         /* Slay Demon */
2905                         if ((have_flag(flgs, TR_SLAY_DEMON)) &&
2906                             (r_ptr->flags3 & RF3_DEMON))
2907                         {
2908                                 if (is_original_ap_and_seen(m_ptr))
2909                                 {
2910                                         r_ptr->r_flags3 |= RF3_DEMON;
2911                                 }
2912
2913                                 if (mult < 20) mult = 20;
2914                         }
2915
2916                         /* Kill Demon */
2917                         if ((have_flag(flgs, TR_KILL_DEMON)) &&
2918                             (r_ptr->flags3 & RF3_DEMON))
2919                         {
2920                                 if (is_original_ap_and_seen(m_ptr))
2921                                 {
2922                                         r_ptr->r_flags3 |= RF3_DEMON;
2923                                 }
2924
2925                                 if (mult < 30) mult = 30;
2926                         }
2927
2928                         /* Slay Orc */
2929                         if ((have_flag(flgs, TR_SLAY_ORC)) &&
2930                             (r_ptr->flags3 & RF3_ORC))
2931                         {
2932                                 if (is_original_ap_and_seen(m_ptr))
2933                                 {
2934                                         r_ptr->r_flags3 |= RF3_ORC;
2935                                 }
2936
2937                                 if (mult < 20) mult = 20;
2938                         }
2939
2940                         /* Kill Orc */
2941                         if ((have_flag(flgs, TR_KILL_ORC)) &&
2942                             (r_ptr->flags3 & RF3_ORC))
2943                         {
2944                                 if (is_original_ap_and_seen(m_ptr))
2945                                 {
2946                                         r_ptr->r_flags3 |= RF3_ORC;
2947                                 }
2948
2949                                 if (mult < 30) mult = 30;
2950                         }
2951
2952                         /* Slay Troll */
2953                         if ((have_flag(flgs, TR_SLAY_TROLL)) &&
2954                             (r_ptr->flags3 & RF3_TROLL))
2955                         {
2956                                 if (is_original_ap_and_seen(m_ptr))
2957                                 {
2958                                         r_ptr->r_flags3 |= RF3_TROLL;
2959                                 }
2960
2961                                 if (mult < 20) mult = 20;
2962                         }
2963
2964                         /* Kill Troll */
2965                         if ((have_flag(flgs, TR_KILL_TROLL)) &&
2966                             (r_ptr->flags3 & RF3_TROLL))
2967                         {
2968                                 if (is_original_ap_and_seen(m_ptr))
2969                                 {
2970                                         r_ptr->r_flags3 |= RF3_TROLL;
2971                                 }
2972
2973                                 if (mult < 30) mult = 30;
2974                         }
2975
2976                         /* Slay Giant */
2977                         if ((have_flag(flgs, TR_SLAY_GIANT)) &&
2978                             (r_ptr->flags3 & RF3_GIANT))
2979                         {
2980                                 if (is_original_ap_and_seen(m_ptr))
2981                                 {
2982                                         r_ptr->r_flags3 |= RF3_GIANT;
2983                                 }
2984
2985                                 if (mult < 20) mult = 20;
2986                         }
2987
2988                         /* Kill Giant */
2989                         if ((have_flag(flgs, TR_KILL_GIANT)) &&
2990                             (r_ptr->flags3 & RF3_GIANT))
2991                         {
2992                                 if (is_original_ap_and_seen(m_ptr))
2993                                 {
2994                                         r_ptr->r_flags3 |= RF3_GIANT;
2995                                 }
2996
2997                                 if (mult < 30) mult = 30;
2998                         }
2999
3000                         /* Slay Dragon  */
3001                         if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
3002                             (r_ptr->flags3 & RF3_DRAGON))
3003                         {
3004                                 if (is_original_ap_and_seen(m_ptr))
3005                                 {
3006                                         r_ptr->r_flags3 |= RF3_DRAGON;
3007                                 }
3008
3009                                 if (mult < 20) mult = 20;
3010                         }
3011
3012                         /* Execute Dragon */
3013                         if ((have_flag(flgs, TR_KILL_DRAGON)) &&
3014                             (r_ptr->flags3 & RF3_DRAGON))
3015                         {
3016                                 if (is_original_ap_and_seen(m_ptr))
3017                                 {
3018                                         r_ptr->r_flags3 |= RF3_DRAGON;
3019                                 }
3020
3021                                 if (mult < 30) mult = 30;
3022
3023                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
3024                                     (m_ptr->r_idx == MON_SMAUG) &&
3025                                     (inventory[INVEN_BOW].name1 == ART_BARD))
3026                                         mult *= 5;
3027                         }
3028
3029                         /* Brand (Acid) */
3030                         if (have_flag(flgs, TR_BRAND_ACID))
3031                         {
3032                                 /* Notice immunity */
3033                                 if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
3034                                 {
3035                                         if (is_original_ap_and_seen(m_ptr))
3036                                         {
3037                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
3038                                         }
3039                                 }
3040
3041                                 /* Otherwise, take the damage */
3042                                 else
3043                                 {
3044                                         if (mult < 17) mult = 17;
3045                                 }
3046                         }
3047
3048                         /* Brand (Elec) */
3049                         if (have_flag(flgs, TR_BRAND_ELEC))
3050                         {
3051                                 /* Notice immunity */
3052                                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
3053                                 {
3054                                         if (is_original_ap_and_seen(m_ptr))
3055                                         {
3056                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
3057                                         }
3058                                 }
3059
3060                                 /* Otherwise, take the damage */
3061                                 else
3062                                 {
3063                                         if (mult < 17) mult = 17;
3064                                 }
3065                         }
3066
3067                         /* Brand (Fire) */
3068                         if (have_flag(flgs, TR_BRAND_FIRE))
3069                         {
3070                                 /* Notice immunity */
3071                                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
3072                                 {
3073                                         if (is_original_ap_and_seen(m_ptr))
3074                                         {
3075                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
3076                                         }
3077                                 }
3078
3079                                 /* Otherwise, take the damage */
3080                                 else
3081                                 {
3082                                         if (r_ptr->flags3 & RF3_HURT_FIRE)
3083                                         {
3084                                                 if (mult < 25) mult = 25;
3085                                                 if (is_original_ap_and_seen(m_ptr))
3086                                                 {
3087                                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
3088                                                 }
3089                                         }
3090                                         else if (mult < 17) mult = 17;
3091                                 }
3092                         }
3093
3094                         /* Brand (Cold) */
3095                         if (have_flag(flgs, TR_BRAND_COLD))
3096                         {
3097                                 /* Notice immunity */
3098                                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
3099                                 {
3100                                         if (is_original_ap_and_seen(m_ptr))
3101                                         {
3102                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
3103                                         }
3104                                 }
3105                                 /* Otherwise, take the damage */
3106                                 else
3107                                 {
3108                                         if (r_ptr->flags3 & RF3_HURT_COLD)
3109                                         {
3110                                                 if (mult < 25) mult = 25;
3111                                                 if (is_original_ap_and_seen(m_ptr))
3112                                                 {
3113                                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
3114                                                 }
3115                                         }
3116                                         else if (mult < 17) mult = 17;
3117                                 }
3118                         }
3119
3120                         /* Brand (Poison) */
3121                         if (have_flag(flgs, TR_BRAND_POIS))
3122                         {
3123                                 /* Notice immunity */
3124                                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
3125                                 {
3126                                         if (is_original_ap_and_seen(m_ptr))
3127                                         {
3128                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
3129                                         }
3130                                 }
3131
3132                                 /* Otherwise, take the damage */
3133                                 else
3134                                 {
3135                                         if (mult < 17) mult = 17;
3136                                 }
3137                         }
3138
3139                         if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
3140                         {
3141                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
3142                                 p_ptr->redraw |= (PR_MANA);
3143                                 mult = mult * 5 / 2;
3144                         }
3145                         break;
3146                 }
3147         }
3148
3149         /* Sniper */
3150         if (snipe_type) mult = tot_dam_aux_snipe(mult, m_ptr);
3151
3152         /* Return the total damage */
3153         return (tdam * mult / 10);
3154 }
3155
3156
3157 /*!
3158  * @brief 射撃処理のサブルーチン /
3159  * Fire an object from the pack or floor.
3160  * @param item 射撃するオブジェクトの所持ID
3161  * @param j_ptr 射撃武器のオブジェクト参照ポインタ
3162  * @return なし
3163  * @details
3164  * <pre>
3165  * You may only fire items that "match" your missile launcher.
3166  *
3167  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
3168  *
3169  * See "calc_bonuses()" for more calculations and such.
3170  *
3171  * Note that "firing" a missile is MUCH better than "throwing" it.
3172  *
3173  * Note: "unseen" monsters are very hard to hit.
3174  *
3175  * Objects are more likely to break if they "attempt" to hit a monster.
3176  *
3177  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
3178  *
3179  * The "extra shot" code works by decreasing the amount of energy
3180  * required to make each shot, spreading the shots out over time.
3181  *
3182  * Note that when firing missiles, the launcher multiplier is applied
3183  * after all the bonuses are added in, making multipliers very useful.
3184  *
3185  * Note that Bows of "Extra Might" get extra range and an extra bonus
3186  * for the damage multiplier.
3187  *
3188  * Note that Bows of "Extra Shots" give an extra shot.
3189  * </pre>
3190  */
3191 void do_cmd_fire_aux(int item, object_type *j_ptr)
3192 {
3193         int dir;
3194         int i, j, y, x, ny, nx, ty, tx, prev_y, prev_x;
3195         int tdam_base, tdis, thits, tmul;
3196         int bonus, chance;
3197         int cur_dis, visible;
3198
3199         object_type forge;
3200         object_type *q_ptr;
3201
3202         object_type *o_ptr;
3203
3204         bool hit_body = FALSE;
3205
3206         char o_name[MAX_NLEN];
3207
3208         u16b path_g[512];       /* For calcuration of path length */
3209
3210         int msec = delay_factor * delay_factor * delay_factor;
3211
3212         /* STICK TO */
3213         bool stick_to = FALSE;
3214
3215         /* Access the item (if in the pack) */
3216         if (item >= 0)
3217         {
3218                 o_ptr = &inventory[item];
3219         }
3220         else
3221         {
3222                 o_ptr = &o_list[0 - item];
3223         }
3224
3225         /* Sniper - Cannot shot a single arrow twice */
3226         if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) snipe_type = SP_NONE;
3227
3228         /* Describe the object */
3229         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
3230
3231         /* Use the proper number of shots */
3232         thits = p_ptr->num_fire;
3233
3234         /* Use a base distance */
3235         tdis = 10;
3236
3237         /* Base damage from thrown object plus launcher bonus */
3238         tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
3239
3240         /* Actually "fire" the object */
3241         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
3242         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3243                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
3244         else
3245                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
3246
3247         p_ptr->energy_use = bow_energy(j_ptr->sval);
3248         tmul = bow_tmul(j_ptr->sval);
3249
3250         /* Get extra "power" from "extra might" */
3251         if (p_ptr->xtra_might) tmul++;
3252
3253         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
3254
3255         /* Boost the damage */
3256         tdam_base *= tmul;
3257         tdam_base /= 100;
3258
3259         /* Base range */
3260         tdis = 13 + tmul/80;
3261         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
3262         {
3263                 if (p_ptr->concent)
3264                         tdis -= (5 - (p_ptr->concent + 1) / 2);
3265                 else
3266                         tdis -= 5;
3267         }
3268
3269         project_length = tdis + 1;
3270
3271         /* Get a direction (or cancel) */
3272         if (!get_aim_dir(&dir))
3273         {
3274                 p_ptr->energy_use = 0;
3275
3276                 if (snipe_type == SP_AWAY) snipe_type = SP_NONE;
3277
3278                 /* need not to reset project_length (already did)*/
3279
3280                 return;
3281         }
3282
3283         /* Predict the "target" location */
3284         tx = p_ptr->x + 99 * ddx[dir];
3285         ty = p_ptr->y + 99 * ddy[dir];
3286
3287         /* Check for "target request" */
3288         if ((dir == 5) && target_okay())
3289         {
3290                 tx = target_col;
3291                 ty = target_row;
3292         }
3293
3294         /* Get projection path length */
3295         tdis = project_path(path_g, project_length, p_ptr->y, p_ptr->x, ty, tx, PROJECT_PATH|PROJECT_THRU) - 1;
3296
3297         project_length = 0; /* reset to default */
3298
3299         /* Don't shoot at my feet */
3300         if (tx == p_ptr->x && ty == p_ptr->y)
3301         {
3302                 p_ptr->energy_use = 0;
3303
3304                 /* project_length is already reset to 0 */
3305
3306                 return;
3307         }
3308
3309
3310         /* Take a (partial) turn */
3311         p_ptr->energy_use = (p_ptr->energy_use / thits);
3312         is_fired = TRUE;
3313
3314         /* Sniper - Difficult to shot twice at 1 turn */
3315         if (snipe_type == SP_DOUBLE)  p_ptr->concent = (p_ptr->concent + 1) / 2;
3316
3317         /* Sniper - Repeat shooting when double shots */
3318         for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++)
3319         {
3320
3321         /* Start at the player */
3322         y = p_ptr->y;
3323         x = p_ptr->x;
3324
3325         /* Get local object */
3326         q_ptr = &forge;
3327
3328         /* Obtain a local object */
3329         object_copy(q_ptr, o_ptr);
3330
3331         /* Single object */
3332         q_ptr->number = 1;
3333
3334         /* Reduce and describe inventory */
3335         if (item >= 0)
3336         {
3337                 inven_item_increase(item, -1);
3338                 inven_item_describe(item);
3339                 inven_item_optimize(item);
3340         }
3341
3342         /* Reduce and describe floor item */
3343         else
3344         {
3345                 floor_item_increase(0 - item, -1);
3346                 floor_item_optimize(0 - item);
3347         }
3348
3349         /* Sound */
3350         sound(SOUND_SHOOT);
3351
3352         /* Hack -- Handle stuff */
3353         handle_stuff();
3354
3355         /* Save the old location */
3356         prev_y = y;
3357         prev_x = x;
3358
3359         /* The shot does not hit yet */
3360         hit_body = FALSE;
3361
3362         /* Travel until stopped */
3363         for (cur_dis = 0; cur_dis <= tdis; )
3364         {
3365                 cave_type *c_ptr;
3366
3367                 /* Hack -- Stop at the target */
3368                 if ((y == ty) && (x == tx)) break;
3369
3370                 /* Calculate the new location (see "project()") */
3371                 ny = y;
3372                 nx = x;
3373                 mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
3374
3375                 /* Shatter Arrow */
3376                 if (snipe_type == SP_KILL_WALL)
3377                 {
3378                         c_ptr = &cave[ny][nx];
3379
3380                         if (cave_have_flag_grid(c_ptr, FF_HURT_ROCK) && !c_ptr->m_idx)
3381                         {
3382                                 if (c_ptr->info & (CAVE_MARK)) msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
3383                                 /* Forget the wall */
3384                                 c_ptr->info &= ~(CAVE_MARK);
3385
3386                                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
3387
3388                                 /* Destroy the wall */
3389                                 cave_alter_feat(ny, nx, FF_HURT_ROCK);
3390
3391                                 hit_body = TRUE;
3392                                 break;
3393                         }
3394                 }
3395
3396                 /* Stopped by walls/doors */
3397                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
3398
3399                 /* Advance the distance */
3400                 cur_dis++;
3401
3402                 /* Sniper */
3403                 if (snipe_type == SP_LITE)
3404                 {
3405                         cave[ny][nx].info |= (CAVE_GLOW);
3406
3407                         /* Notice */
3408                         note_spot(ny, nx);
3409
3410                         /* Redraw */
3411                         lite_spot(ny, nx);
3412                 }
3413
3414                 /* The player can see the (on screen) missile */
3415                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
3416                 {
3417                         char c = object_char(q_ptr);
3418                         byte a = object_attr(q_ptr);
3419
3420                         /* Draw, Hilite, Fresh, Pause, Erase */
3421                         print_rel(c, a, ny, nx);
3422                         move_cursor_relative(ny, nx);
3423                         Term_fresh();
3424                         Term_xtra(TERM_XTRA_DELAY, msec);
3425                         lite_spot(ny, nx);
3426                         Term_fresh();
3427                 }
3428
3429                 /* The player cannot see the missile */
3430                 else
3431                 {
3432                         /* Pause anyway, for consistancy */
3433                         Term_xtra(TERM_XTRA_DELAY, msec);
3434                 }
3435
3436                 /* Sniper */
3437                 if (snipe_type == SP_KILL_TRAP)
3438                 {
3439                         project(0, 0, ny, nx, 0, GF_KILL_TRAP,
3440                                 (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM), -1);
3441                 }
3442
3443                 /* Sniper */
3444                 if (snipe_type == SP_EVILNESS)
3445                 {
3446                         cave[ny][nx].info &= ~(CAVE_GLOW | CAVE_MARK);
3447
3448                         /* Notice */
3449                         note_spot(ny, nx);
3450
3451                         /* Redraw */
3452                         lite_spot(ny, nx);
3453                 }
3454
3455                 /* Save the old location */
3456                 prev_y = y;
3457                 prev_x = x;
3458
3459                 /* Save the new location */
3460                 x = nx;
3461                 y = ny;
3462
3463
3464                 /* Monster here, Try to hit it */
3465                 if (cave[y][x].m_idx)
3466                 {
3467                         cave_type *c_mon_ptr = &cave[y][x];
3468
3469                         monster_type *m_ptr = &m_list[c_mon_ptr->m_idx];
3470                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3471
3472                         /* Check the visibility */
3473                         visible = m_ptr->ml;
3474
3475                         /* Note the collision */
3476                         hit_body = TRUE;
3477
3478                         if (MON_CSLEEP(m_ptr))
3479                         {
3480                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
3481                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
3482                         }
3483
3484                         if ((r_ptr->level + 10) > p_ptr->lev)
3485                         {
3486                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
3487                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
3488                                 {
3489                                         int amount = 0;
3490                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
3491                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
3492                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
3493                                         else if (p_ptr->lev > 34) amount = 2;
3494                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
3495                                         p_ptr->update |= (PU_BONUS);
3496                                 }
3497                         }
3498
3499                         if (p_ptr->riding)
3500                         {
3501                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
3502                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
3503                                         && one_in_(2))
3504                                 {
3505                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
3506                                         p_ptr->update |= (PU_BONUS);
3507                                 }
3508                         }
3509
3510                         /* Did we hit it (penalize range) */
3511                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3512                         {
3513                                 bool fear = FALSE;
3514                                 int tdam = tdam_base;
3515
3516                                 /* Get extra damage from concentration */
3517                                 if (p_ptr->concent) tdam = boost_concentration_damage(tdam);
3518
3519                                 /* Handle unseen monster */
3520                                 if (!visible)
3521                                 {
3522                                         /* Invisible monster */
3523                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
3524                                 }
3525
3526                                 /* Handle visible monster */
3527                                 else
3528                                 {
3529                                         char m_name[80];
3530
3531                                         /* Get "the monster" or "it" */
3532                                         monster_desc(m_name, m_ptr, 0);
3533
3534                                         /* Message */
3535                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3536
3537                                         if (m_ptr->ml)
3538                                         {
3539                                                 /* Hack -- Track this monster race */
3540                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3541
3542                                                 /* Hack -- Track this monster */
3543                                                 health_track(c_mon_ptr->m_idx);
3544                                         }
3545                                 }
3546
3547                                 if (snipe_type == SP_NEEDLE)
3548                                 {
3549                                         if ((randint1(randint1(r_ptr->level / (3 + p_ptr->concent)) + (8 - p_ptr->concent)) == 1)
3550                                                 && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
3551                                         {
3552                                                 char m_name[80];
3553
3554                                                 /* Get "the monster" or "it" */
3555                                                 monster_desc(m_name, m_ptr, 0);
3556
3557                                                 tdam = m_ptr->hp + 1;
3558                                                 msg_format(_("%sの急所に突き刺さった!", "Your shot sticked on a fatal spot of %s!"), m_name);
3559                                         }
3560                                         else tdam = 1;
3561                                 }
3562                                 else
3563                                 {
3564                                         /* Apply special damage XXX XXX XXX */
3565                                         tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3566                                         tdam = critical_shot(q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
3567
3568                                         /* No negative damage */
3569                                         if (tdam < 0) tdam = 0;
3570
3571                                         /* Modify the damage */
3572                                         tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3573                                 }
3574
3575                                 msg_format_wizard(CHEAT_MONSTER,
3576                                         _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3577                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3578
3579                                 /* Sniper */
3580                                 if (snipe_type == SP_EXPLODE)
3581                                 {
3582                                         u16b flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
3583
3584                                         sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
3585                                         project(0, ((p_ptr->concent + 1) / 2 + 1), ny, nx, tdam, GF_MISSILE, flg, -1);
3586                                         break;
3587                                 }
3588
3589                                 /* Sniper */
3590                                 if (snipe_type == SP_HOLYNESS)
3591                                 {
3592                                         cave[ny][nx].info |= (CAVE_GLOW);
3593
3594                                         /* Notice */
3595                                         note_spot(ny, nx);
3596
3597                                         /* Redraw */
3598                                         lite_spot(ny, nx);
3599                                 }
3600
3601                                 /* Hit the monster, check for death */
3602                                 if (mon_take_hit(c_mon_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3603                                 {
3604                                         /* Dead monster */
3605                                 }
3606
3607                                 /* No death */
3608                                 else
3609                                 {
3610                                         /* STICK TO */
3611                                         if (object_is_fixed_artifact(q_ptr) &&
3612                                                 (p_ptr->pclass != CLASS_SNIPER || p_ptr->concent == 0))
3613                                         {
3614                                                 char m_name[80];
3615
3616                                                 monster_desc(m_name, m_ptr, 0);
3617
3618                                                 stick_to = TRUE;
3619                                                 msg_format(_("%sは%sに突き刺さった!", "%^s have stuck into %s!"),o_name, m_name);
3620                                         }
3621
3622                                         /* Message */
3623                                         message_pain(c_mon_ptr->m_idx, tdam);
3624
3625                                         /* Anger the monster */
3626                                         if (tdam > 0) anger_monster(m_ptr);
3627
3628                                         /* Take note */
3629                                         if (fear && m_ptr->ml)
3630                                         {
3631                                                 char m_name[80];
3632
3633                                                 /* Sound */
3634                                                 sound(SOUND_FLEE);
3635
3636                                                 /* Get the monster name (or "it") */
3637                                                 monster_desc(m_name, m_ptr, 0);
3638
3639                                                 /* Message */
3640                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3641                                         }
3642
3643                                         set_target(m_ptr, p_ptr->y, p_ptr->x);
3644
3645                                         /* Sniper */
3646                                         if (snipe_type == SP_RUSH)
3647                                         {
3648                                                 int n = randint1(5) + 3;
3649                                                 int m_idx = c_mon_ptr->m_idx;
3650
3651                                                 for ( ; cur_dis <= tdis; )
3652                                                 {
3653                                                         int ox = nx;
3654                                                         int oy = ny;
3655
3656                                                         if (!n) break;
3657
3658                                                         /* Calculate the new location (see "project()") */
3659                                                         mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
3660
3661                                                         /* Stopped by wilderness boundary */
3662                                                         if (!in_bounds2(ny, nx)) break;
3663
3664                                                         /* Stopped by walls/doors */
3665                                                         if (!player_can_enter(cave[ny][nx].feat, 0)) break;
3666
3667                                                         /* Stopped by monsters */
3668                                                         if (!cave_empty_bold(ny, nx)) break;
3669
3670                                                         cave[ny][nx].m_idx = m_idx;
3671                                                         cave[oy][ox].m_idx = 0;
3672
3673                                                         m_ptr->fx = nx;
3674                                                         m_ptr->fy = ny;
3675
3676                                                         /* Update the monster (new location) */
3677                                                         update_mon(c_mon_ptr->m_idx, TRUE);
3678
3679                                                         lite_spot(ny, nx);
3680                                                         lite_spot(oy, ox);
3681
3682                                                         Term_fresh();
3683                                                         Term_xtra(TERM_XTRA_DELAY, msec);
3684
3685                                                         x = nx;
3686                                                         y = ny;
3687                                                         cur_dis++;
3688                                                         n--;
3689                                                 }
3690                                         }
3691                                 }
3692                         }
3693
3694                         /* Sniper */
3695                         if (snipe_type == SP_PIERCE)
3696                         {
3697                                 if(p_ptr->concent < 1) break;
3698                                 p_ptr->concent--;
3699                                 continue;
3700                         }
3701
3702                         /* Stop looking */
3703                         break;
3704                 }
3705         }
3706
3707         /* Chance of breakage (during attacks) */
3708         j = (hit_body ? breakage_chance(q_ptr) : 0);
3709
3710         if (stick_to)
3711         {
3712                 int m_idx = cave[y][x].m_idx;
3713                 monster_type *m_ptr = &m_list[m_idx];
3714                 int o_idx = o_pop();
3715
3716                 if (!o_idx)
3717                 {
3718                         msg_format(_("%sはどこかへ行った。", "The %s have gone to somewhere."), o_name);
3719                         if (object_is_fixed_artifact(q_ptr))
3720                         {
3721                                 a_info[j_ptr->name1].cur_num = 0;
3722                         }
3723                         return;
3724                 }
3725
3726                 o_ptr = &o_list[o_idx];
3727                 object_copy(o_ptr, q_ptr);
3728
3729                 /* Forget mark */
3730                 o_ptr->marked &= OM_TOUCHED;
3731
3732                 /* Forget location */
3733                 o_ptr->iy = o_ptr->ix = 0;
3734
3735                 /* Memorize monster */
3736                 o_ptr->held_m_idx = m_idx;
3737
3738                 /* Build a stack */
3739                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3740
3741                 /* Carry object */
3742                 m_ptr->hold_o_idx = o_idx;
3743         }
3744         else if (cave_have_flag_bold(y, x, FF_PROJECT))
3745         {
3746                 /* Drop (or break) near that location */
3747                 (void)drop_near(q_ptr, j, y, x);
3748         }
3749         else
3750         {
3751                 /* Drop (or break) near that location */
3752                 (void)drop_near(q_ptr, j, prev_y, prev_x);
3753         }
3754
3755         /* Sniper - Repeat shooting when double shots */
3756         }
3757
3758         /* Sniper - Loose his/her concentration after any shot */
3759         if (p_ptr->concent) reset_concentration(FALSE);
3760 }
3761
3762 /*!
3763  * @brief 射撃処理のメインルーチン
3764  * @return なし
3765  */
3766 void do_cmd_fire(void)
3767 {
3768         int item;
3769         object_type *j_ptr;
3770         cptr q, s;
3771
3772         is_fired = FALSE;       /* not fired yet */
3773
3774         /* Get the "bow" (if any) */
3775         j_ptr = &inventory[INVEN_BOW];
3776
3777         /* Require a launcher */
3778         if (!j_ptr->tval)
3779         {
3780                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
3781                 flush();
3782                 return;
3783         }
3784
3785         if (j_ptr->sval == SV_CRIMSON)
3786         {
3787                 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
3788                 flush();
3789                 return;
3790         }
3791
3792         if (j_ptr->sval == SV_HARP)
3793         {
3794                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
3795                 flush();
3796                 return;
3797         }
3798
3799
3800         if (p_ptr->special_defense & KATA_MUSOU)
3801         {
3802                 set_action(ACTION_NONE);
3803         }
3804
3805         /* Require proper missile */
3806         item_tester_tval = p_ptr->tval_ammo;
3807
3808         /* Get an item */
3809         q = _("どれを撃ちますか? ", "Fire which item? ");
3810         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
3811         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
3812         {
3813                 flush();
3814                 return;
3815         }
3816
3817         /* Fire the item */
3818         do_cmd_fire_aux(item, j_ptr);
3819
3820         if (!is_fired || p_ptr->pclass != CLASS_SNIPER) return;
3821
3822         /* Sniper actions after some shootings */
3823         if (snipe_type == SP_AWAY)
3824         {
3825                 teleport_player(10 + (p_ptr->concent * 2), 0L);
3826         }
3827         if (snipe_type == SP_FINAL)
3828         {
3829                 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
3830                 (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
3831                 (void)set_stun(p_ptr->stun + randint1(25));
3832         }
3833 }
3834
3835 /*!
3836  * @brief オブジェクトが投射可能な武器かどうかを返す。
3837  * @param o_ptr 判定するオブジェクトの構造体参照ポインタ
3838  * @return 投射可能な武器ならばTRUE
3839  */
3840 static bool item_tester_hook_boomerang(object_type *o_ptr)
3841 {
3842         if ((o_ptr->tval==TV_DIGGING) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED)) return (TRUE);
3843
3844         /* Assume not */
3845         return (FALSE);
3846 }
3847
3848
3849 /*!
3850  * @brief 投射処理のサブルーチン /
3851  * Throw an object from the pack or floor.
3852  * @param mult 威力の倍率
3853  * @param boomerang ブーメラン処理ならばTRUE
3854  * @param shuriken 忍者の手裏剣処理ならばTRUE
3855  * @return ターンを消費した場合TRUEを返す
3856  * @details
3857  * <pre>
3858  * Note: "unseen" monsters are very hard to hit.
3859  *
3860  * Should throwing a weapon do full damage?  Should it allow the magic
3861  * to hit bonus of the weapon to have an effect?  Should it ever cause
3862  * the item to be destroyed?  Should it do any damage at all?
3863  * </pre>
3864  */
3865 bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
3866 {
3867         int dir, item;
3868         int i, j, y, x, ty, tx, prev_y, prev_x;
3869         int ny[19], nx[19];
3870         int chance, tdam, tdis;
3871         int mul, div, dd, ds;
3872         int cur_dis, visible;
3873
3874         object_type forge;
3875         object_type *q_ptr;
3876
3877         object_type *o_ptr;
3878
3879         bool hit_body = FALSE;
3880         bool hit_wall = FALSE;
3881         bool equiped_item = FALSE;
3882         bool return_when_thrown = FALSE;
3883
3884         char o_name[MAX_NLEN];
3885
3886         int msec = delay_factor * delay_factor * delay_factor;
3887
3888         u32b flgs[TR_FLAG_SIZE];
3889         cptr q, s;
3890         bool come_back = FALSE;
3891         bool do_drop = TRUE;
3892
3893
3894         if (p_ptr->special_defense & KATA_MUSOU)
3895         {
3896                 set_action(ACTION_NONE);
3897         }
3898
3899         if (shuriken >= 0)
3900         {
3901                 item = shuriken;
3902         }
3903         else if (boomerang)
3904         {
3905                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
3906                 {
3907                         item_tester_hook = item_tester_hook_boomerang;
3908                         q = _("どの武器を投げますか? ", "Throw which item? ");
3909                         s = _("投げる武器がない。", "You have nothing to throw.");
3910                         if (!get_item(&item, q, s, (USE_EQUIP)))
3911                         {
3912                                 flush();
3913                                 return FALSE;
3914                         }
3915                 }
3916                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
3917                 else item = INVEN_RARM;
3918         }
3919         else
3920         {
3921                 /* Get an item */
3922                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
3923                 s = _("投げるアイテムがない。", "You have nothing to throw.");
3924                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
3925                 {
3926                         flush();
3927                         return FALSE;
3928                 }
3929         }
3930
3931         /* Access the item (if in the pack) */
3932         if (item >= 0)
3933         {
3934                 o_ptr = &inventory[item];
3935         }
3936         else
3937         {
3938                 o_ptr = &o_list[0 - item];
3939         }
3940
3941
3942         /* Item is cursed */
3943         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
3944         {
3945                 /* Oops */
3946                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
3947
3948                 /* Nope */
3949                 return FALSE;
3950         }
3951
3952         if (p_ptr->inside_arena && !boomerang)
3953         {
3954                 if (o_ptr->tval != TV_SPIKE)
3955                 {
3956                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
3957                         msg_print(NULL);
3958
3959                         /* Nope */
3960                         return FALSE;
3961                 }
3962         }
3963
3964         /* Get local object */
3965         q_ptr = &forge;
3966
3967         /* Obtain a local object */
3968         object_copy(q_ptr, o_ptr);
3969
3970         /* Extract the thrown object's flags. */
3971         object_flags(q_ptr, flgs);
3972         torch_flags(q_ptr, flgs);
3973
3974         /* Distribute the charges of rods/wands between the stacks */
3975         distribute_charges(o_ptr, q_ptr, 1);
3976
3977         /* Single object */
3978         q_ptr->number = 1;
3979
3980         /* Description */
3981         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
3982
3983         if (p_ptr->mighty_throw) mult += 3;
3984
3985         /* Extract a "distance multiplier" */
3986         /* Changed for 'launcher' mutation */
3987         mul = 10 + 2 * (mult - 1);
3988
3989         /* Enforce a minimum "weight" of one pound */
3990         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
3991         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
3992
3993         /* Hack -- Distance -- Reward strength, penalize weight */
3994         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
3995
3996         /* Max distance of 10-18 */
3997         if (tdis > mul) tdis = mul;
3998
3999         if (shuriken >= 0)
4000         {
4001                 ty = randint0(101)-50+p_ptr->y;
4002                 tx = randint0(101)-50+p_ptr->x;
4003         }
4004         else
4005         {
4006                 project_length = tdis + 1;
4007
4008                 /* Get a direction (or cancel) */
4009                 if (!get_aim_dir(&dir)) return FALSE;
4010
4011                 /* Predict the "target" location */
4012                 tx = p_ptr->x + 99 * ddx[dir];
4013                 ty = p_ptr->y + 99 * ddy[dir];
4014
4015                 /* Check for "target request" */
4016                 if ((dir == 5) && target_okay())
4017                 {
4018                         tx = target_col;
4019                         ty = target_row;
4020                 }
4021
4022                 project_length = 0;  /* reset to default */
4023         }
4024
4025         if ((q_ptr->name1 == ART_MJOLLNIR) ||
4026             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
4027                 return_when_thrown = TRUE;
4028
4029         /* Reduce and describe inventory */
4030         if (item >= 0)
4031         {
4032                 inven_item_increase(item, -1);
4033                 if (!return_when_thrown)
4034                         inven_item_describe(item);
4035                 inven_item_optimize(item);
4036         }
4037
4038         /* Reduce and describe floor item */
4039         else
4040         {
4041                 floor_item_increase(0 - item, -1);
4042                 floor_item_optimize(0 - item);
4043         }
4044         if (item >= INVEN_RARM)
4045         {
4046                 equiped_item = TRUE;
4047                 p_ptr->redraw |= (PR_EQUIPPY);
4048         }
4049
4050         /* Take a turn */
4051         p_ptr->energy_use = 100;
4052
4053         /* Rogue and Ninja gets bonus */
4054         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
4055                 p_ptr->energy_use -= p_ptr->lev;
4056
4057         /* Start at the player */
4058         y = p_ptr->y;
4059         x = p_ptr->x;
4060
4061
4062         /* Hack -- Handle stuff */
4063         handle_stuff();
4064
4065         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
4066         else shuriken = FALSE;
4067
4068         /* Chance of hitting */
4069         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
4070                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
4071         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
4072
4073         if (shuriken) chance *= 2;
4074
4075         /* Save the old location */
4076         prev_y = y;
4077         prev_x = x;
4078
4079         /* Travel until stopped */
4080         for (cur_dis = 0; cur_dis <= tdis; )
4081         {
4082                 /* Hack -- Stop at the target */
4083                 if ((y == ty) && (x == tx)) break;
4084
4085                 /* Calculate the new location (see "project()") */
4086                 ny[cur_dis] = y;
4087                 nx[cur_dis] = x;
4088                 mmove2(&ny[cur_dis], &nx[cur_dis], p_ptr->y, p_ptr->x, ty, tx);
4089
4090                 /* Stopped by walls/doors */
4091                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
4092                 {
4093                         hit_wall = TRUE;
4094                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
4095                 }
4096
4097                 /* The player can see the (on screen) missile */
4098                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
4099                 {
4100                         char c = object_char(q_ptr);
4101                         byte a = object_attr(q_ptr);
4102
4103                         /* Draw, Hilite, Fresh, Pause, Erase */
4104                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
4105                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
4106                         Term_fresh();
4107                         Term_xtra(TERM_XTRA_DELAY, msec);
4108                         lite_spot(ny[cur_dis], nx[cur_dis]);
4109                         Term_fresh();
4110                 }
4111
4112                 /* The player cannot see the missile */
4113                 else
4114                 {
4115                         /* Pause anyway, for consistancy */
4116                         Term_xtra(TERM_XTRA_DELAY, msec);
4117                 }
4118
4119                 /* Save the old location */
4120                 prev_y = y;
4121                 prev_x = x;
4122
4123                 /* Save the new location */
4124                 x = nx[cur_dis];
4125                 y = ny[cur_dis];
4126
4127                 /* Advance the distance */
4128                 cur_dis++;
4129
4130                 /* Monster here, Try to hit it */
4131                 if (cave[y][x].m_idx)
4132                 {
4133                         cave_type *c_ptr = &cave[y][x];
4134
4135                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4136
4137                         /* Check the visibility */
4138                         visible = m_ptr->ml;
4139
4140                         /* Note the collision */
4141                         hit_body = TRUE;
4142
4143                         /* Did we hit it (penalize range) */
4144                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
4145                         {
4146                                 bool fear = FALSE;
4147
4148                                 /* Handle unseen monster */
4149                                 if (!visible)
4150                                 {
4151                                         /* Invisible monster */
4152                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
4153                                 }
4154
4155                                 /* Handle visible monster */
4156                                 else
4157                                 {
4158                                         char m_name[80];
4159
4160                                         /* Get "the monster" or "it" */
4161                                         monster_desc(m_name, m_ptr, 0);
4162
4163                                         /* Message */
4164                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
4165
4166                                         if (m_ptr->ml)
4167                                         {
4168                                                 /* Hack -- Track this monster race */
4169                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
4170
4171                                                 /* Hack -- Track this monster */
4172                                                 health_track(c_ptr->m_idx);
4173                                         }
4174                                 }
4175
4176                                 /* Hack -- Base damage from thrown object */
4177                                 dd = q_ptr->dd;
4178                                 ds = q_ptr->ds;
4179                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
4180                                 tdam = damroll(dd, ds);
4181                                 /* Apply special damage XXX XXX XXX */
4182                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
4183                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
4184                                 if (q_ptr->to_d > 0)
4185                                         tdam += q_ptr->to_d;
4186                                 else
4187                                         tdam += -q_ptr->to_d;
4188
4189                                 if (boomerang)
4190                                 {
4191                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
4192                                         tdam += p_ptr->to_d_m;
4193                                 }
4194                                 else if (have_flag(flgs, TR_THROW))
4195                                 {
4196                                         tdam *= (3+mult);
4197                                         tdam += p_ptr->to_d_m;
4198                                 }
4199                                 else
4200                                 {
4201                                         tdam *= mult;
4202                                 }
4203                                 if (shuriken)
4204                                 {
4205                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
4206                                 }
4207
4208                                 /* No negative damage */
4209                                 if (tdam < 0) tdam = 0;
4210
4211                                 /* Modify the damage */
4212                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
4213
4214                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
4215                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
4216
4217                                 /* Hit the monster, check for death */
4218                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
4219                                 {
4220                                         /* Dead monster */
4221                                 }
4222
4223                                 /* No death */
4224                                 else
4225                                 {
4226                                         /* Message */
4227                                         message_pain(c_ptr->m_idx, tdam);
4228
4229                                         /* Anger the monster */
4230                                         if ((tdam > 0) && !object_is_potion(q_ptr))
4231                                                 anger_monster(m_ptr);
4232
4233                                         /* Take note */
4234                                         if (fear && m_ptr->ml)
4235                                         {
4236                                                 char m_name[80];
4237
4238                                                 /* Sound */
4239                                                 sound(SOUND_FLEE);
4240
4241                                                 /* Get the monster name (or "it") */
4242                                                 monster_desc(m_name, m_ptr, 0);
4243
4244                                                 /* Message */
4245                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
4246                                         }
4247                                 }
4248                         }
4249
4250                         /* Stop looking */
4251                         break;
4252                 }
4253         }
4254
4255         /* decrease toach's fuel */
4256         if (hit_body) torch_lost_fuel(q_ptr);
4257
4258         /* Chance of breakage (during attacks) */
4259         j = (hit_body ? breakage_chance(q_ptr) : 0);
4260
4261         /* Figurines transform */
4262         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
4263         {
4264                 j = 100;
4265
4266                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
4267                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
4268                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
4269                 else if (object_is_cursed(q_ptr))
4270                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
4271
4272         }
4273
4274
4275         /* Potions smash open */
4276         if (object_is_potion(q_ptr))
4277         {
4278                 if (hit_body || hit_wall || (randint1(100) < j))
4279                 {
4280                         /* Message */
4281                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
4282
4283                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
4284                         {
4285                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
4286
4287                                 /* ToDo (Robert): fix the invulnerability */
4288                                 if (cave[y][x].m_idx &&
4289                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
4290                                     !MON_INVULNER(m_ptr))
4291                                 {
4292                                         char m_name[80];
4293                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
4294                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
4295                                         set_hostile(&m_list[cave[y][x].m_idx]);
4296                                 }
4297                         }
4298                         do_drop = FALSE;
4299                 }
4300                 else
4301                 {
4302                         j = 0;
4303                 }
4304         }
4305
4306         if (return_when_thrown)
4307         {
4308                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4309                 char o2_name[MAX_NLEN];
4310                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
4311
4312                 j = -1;
4313                 if (boomerang) back_chance += 4+randint1(5);
4314                 if (super_boomerang) back_chance += 100;
4315                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
4316
4317                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
4318                 {
4319                         for (i = cur_dis - 1; i > 0; i--)
4320                         {
4321                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
4322                                 {
4323                                         char c = object_char(q_ptr);
4324                                         byte a = object_attr(q_ptr);
4325
4326                                         /* Draw, Hilite, Fresh, Pause, Erase */
4327                                         print_rel(c, a, ny[i], nx[i]);
4328                                         move_cursor_relative(ny[i], nx[i]);
4329                                         Term_fresh();
4330                                         Term_xtra(TERM_XTRA_DELAY, msec);
4331                                         lite_spot(ny[i], nx[i]);
4332                                         Term_fresh();
4333                                 }
4334                                 else
4335                                 {
4336                                         /* Pause anyway, for consistancy */
4337                                         Term_xtra(TERM_XTRA_DELAY, msec);
4338                                 }
4339                         }
4340                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
4341                         {
4342                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
4343                                 come_back = TRUE;
4344                         }
4345                         else
4346                         {
4347                                 if (item >= 0)
4348                                 {
4349                                         msg_format(_("%sを受け損ねた!", "%s backs, but you can't catch!"), o2_name);
4350                                 }
4351                                 else
4352                                 {
4353                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
4354                                 }
4355                                 y = p_ptr->y;
4356                                 x = p_ptr->x;
4357                         }
4358                 }
4359                 else
4360                 {
4361                         msg_format(_("%sが返ってこなかった!", "%s doesn't back!"), o2_name);
4362                 }
4363         }
4364
4365         if (come_back)
4366         {
4367                 if (item == INVEN_RARM || item == INVEN_LARM)
4368                 {
4369                         /* Access the wield slot */
4370                         o_ptr = &inventory[item];
4371
4372                         /* Wear the new stuff */
4373                         object_copy(o_ptr, q_ptr);
4374
4375                         /* Increase the weight */
4376                         p_ptr->total_weight += q_ptr->weight;
4377
4378                         /* Increment the equip counter by hand */
4379                         equip_cnt++;
4380
4381                         /* Recalculate bonuses */
4382                         p_ptr->update |= (PU_BONUS);
4383
4384                         /* Recalculate torch */
4385                         p_ptr->update |= (PU_TORCH);
4386
4387                         /* Recalculate mana XXX */
4388                         p_ptr->update |= (PU_MANA);
4389
4390                         /* Window stuff */
4391                         p_ptr->window |= (PW_EQUIP);
4392                 }
4393                 else
4394                 {
4395                         inven_carry(q_ptr);
4396                 }
4397                 do_drop = FALSE;
4398         }
4399         else if (equiped_item)
4400         {
4401                 kamaenaoshi(item);
4402                 calc_android_exp();
4403         }
4404
4405         /* Drop (or break) near that location */
4406         if (do_drop)
4407         {
4408                 if (cave_have_flag_bold(y, x, FF_PROJECT))
4409                 {
4410                         /* Drop (or break) near that location */
4411                         (void)drop_near(q_ptr, j, y, x);
4412                 }
4413                 else
4414                 {
4415                         /* Drop (or break) near that location */
4416                         (void)drop_near(q_ptr, j, prev_y, prev_x);
4417                 }
4418         }
4419
4420         return TRUE;
4421 }
4422
4423
4424 /*!
4425  * @brief 投射処理のメインルーチン /
4426  * Throw an object from the pack or floor.
4427  * @return なし
4428  */
4429 void do_cmd_throw(void)
4430 {
4431         do_cmd_throw_aux(1, FALSE, -1);
4432 }
4433
4434
4435 #ifdef TRAVEL
4436 /*
4437  * Hack: travel command
4438  */
4439 #define TRAVEL_UNABLE 9999
4440
4441 static int flow_head = 0;
4442 static int flow_tail = 0;
4443 static s16b temp2_x[MAX_SHORT];
4444 static s16b temp2_y[MAX_SHORT];
4445
4446 /*!
4447  * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information 
4448  * @return なし
4449  */
4450 void forget_travel_flow(void)
4451 {
4452         int x, y;
4453
4454         /* Check the entire dungeon */
4455         for (y = 0; y < cur_hgt; y++)
4456         {
4457                 for (x = 0; x < cur_wid; x++)
4458                 {
4459                         /* Forget the old data */
4460                         travel.cost[y][x] = MAX_SHORT;
4461                 }
4462         }
4463
4464         travel.y = travel.x = 0;
4465 }
4466
4467 /*!
4468  * @brief トラベル処理中に地形に応じた移動コスト基準を返す
4469  * @param y 該当地点のY座標
4470  * @param x 該当地点のX座標
4471  * @return コスト値
4472  */
4473 static int travel_flow_cost(int y, int x)
4474 {
4475         feature_type *f_ptr = &f_info[cave[y][x].feat];
4476         int cost = 1;
4477
4478         /* Avoid obstacles (ex. trees) */
4479         if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
4480
4481         /* Water */
4482         if (have_flag(f_ptr->flags, FF_WATER))
4483         {
4484                 if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
4485         }
4486
4487         /* Lava */
4488         if (have_flag(f_ptr->flags, FF_LAVA))
4489         {
4490                 int lava = 2;
4491                 if (!p_ptr->resist_fire) lava *= 2;
4492                 if (!p_ptr->levitation) lava *= 2;
4493                 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
4494
4495                 cost += lava;
4496         }
4497
4498         /* Detected traps and doors */
4499         if (cave[y][x].info & (CAVE_MARK))
4500         {
4501                 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
4502                 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
4503         }
4504
4505         return (cost);
4506 }
4507
4508 /*!
4509  * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
4510  * @param y 目標地点のY座標
4511  * @param x 目標地点のX座標
4512  * @param n 現在のコスト
4513  * @param wall プレイヤーが壁の中にいるならばTRUE
4514  * @return なし
4515  */
4516 static void travel_flow_aux(int y, int x, int n, bool wall)
4517 {
4518         cave_type *c_ptr = &cave[y][x];
4519         feature_type *f_ptr = &f_info[c_ptr->feat];
4520         int old_head = flow_head;
4521         int add_cost = 1;
4522         int base_cost = (n % TRAVEL_UNABLE);
4523         int from_wall = (n / TRAVEL_UNABLE);
4524         int cost;
4525
4526         /* Ignore out of bounds */
4527         if (!in_bounds(y, x)) return;
4528
4529         /* Ignore unknown grid except in wilderness */
4530         if (dun_level > 0 && !(c_ptr->info & CAVE_KNOWN)) return;
4531
4532         /* Ignore "walls" and "rubble" (include "secret doors") */
4533         if (have_flag(f_ptr->flags, FF_WALL) ||
4534                 have_flag(f_ptr->flags, FF_CAN_DIG) ||
4535                 (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic) ||
4536                 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
4537         {
4538                 if (!wall || !from_wall) return;
4539                 add_cost += TRAVEL_UNABLE;
4540         }
4541         else
4542         {
4543                 add_cost = travel_flow_cost(y, x);
4544         }
4545
4546         cost = base_cost + add_cost;
4547
4548         /* Ignore lower cost entries */
4549         if (travel.cost[y][x] <= cost) return;
4550
4551         /* Save the flow cost */
4552         travel.cost[y][x] = cost;
4553
4554         /* Enqueue that entry */
4555         temp2_y[flow_head] = y;
4556         temp2_x[flow_head] = x;
4557
4558         /* Advance the queue */
4559         if (++flow_head == MAX_SHORT) flow_head = 0;
4560
4561         /* Hack -- notice overflow by forgetting new entry */
4562         if (flow_head == flow_tail) flow_head = old_head;
4563
4564         return;
4565 }
4566
4567 /*!
4568  * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
4569  * @param ty 目標地点のY座標
4570  * @param tx 目標地点のX座標
4571  * @return なし
4572  */
4573 static void travel_flow(int ty, int tx)
4574 {
4575         int x, y, d;
4576         bool wall = FALSE;
4577         feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
4578
4579         /* Reset the "queue" */
4580         flow_head = flow_tail = 0;
4581
4582         /* is player in the wall? */
4583         if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
4584
4585         /* Start at the target grid */
4586         travel_flow_aux(ty, tx, 0, wall);
4587
4588         /* Now process the queue */
4589         while (flow_head != flow_tail)
4590         {
4591                 /* Extract the next entry */
4592                 y = temp2_y[flow_tail];
4593                 x = temp2_x[flow_tail];
4594
4595                 /* Forget that entry */
4596                 if (++flow_tail == MAX_SHORT) flow_tail = 0;
4597
4598                 /* Ignore too far entries */
4599                 //if (distance(ty, tx, y, x) > 100) continue;
4600
4601                 /* Add the "children" */
4602                 for (d = 0; d < 8; d++)
4603                 {
4604                         /* Add that child if "legal" */
4605                         travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
4606                 }
4607         }
4608
4609         /* Forget the flow info */
4610         flow_head = flow_tail = 0;
4611 }
4612
4613 /*!
4614  * @brief トラベル処理のメインルーチン
4615  * @return なし
4616  */
4617 void do_cmd_travel(void)
4618 {
4619         int x, y, i;
4620         int dx, dy, sx, sy;
4621         feature_type *f_ptr;
4622
4623         if (travel.x != 0 && travel.y != 0 &&
4624             get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
4625         {
4626                 y = travel.y;
4627                 x = travel.x;
4628         }
4629         else if (!tgt_pt(&x, &y)) return;
4630
4631         if ((x == p_ptr->x) && (y == p_ptr->y))
4632         {
4633                 msg_print(_("すでにそこにいます!", "You are already there!!"));
4634                 return;
4635         }
4636
4637         f_ptr = &f_info[cave[y][x].feat];
4638
4639         if ((cave[y][x].info & CAVE_MARK) &&
4640                 (have_flag(f_ptr->flags, FF_WALL) ||
4641                         have_flag(f_ptr->flags, FF_CAN_DIG) ||
4642                         (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic)))
4643         {
4644                 msg_print(_("そこには行くことができません!", "You cannot travel there!"));
4645                 return;
4646         }
4647
4648         forget_travel_flow();
4649         travel_flow(y, x);
4650
4651         travel.x = x;
4652         travel.y = y;
4653
4654         /* Travel till 255 steps */
4655         travel.run = 255;
4656
4657         /* Paranoia */
4658         travel.dir = 0;
4659
4660         /* Decides first direction */
4661         dx = abs(p_ptr->x - x);
4662         dy = abs(p_ptr->y - y);
4663         sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
4664         sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
4665
4666         for (i = 1; i <= 9; i++)
4667         {
4668                 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
4669         }
4670 }
4671 #endif