OSDN Git Service

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