OSDN Git Service

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