OSDN Git Service

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