OSDN Git Service

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