OSDN Git Service

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