OSDN Git Service

[Refactor] #37481 melee.hを定義。 \ Add melee.h.
[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
2864                                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
2865
2866                                 /* Destroy the wall */
2867                                 cave_alter_feat(ny, nx, FF_HURT_ROCK);
2868
2869                                 hit_body = TRUE;
2870                                 break;
2871                         }
2872                 }
2873
2874                 /* Stopped by walls/doors */
2875                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
2876
2877                 /* Advance the distance */
2878                 cur_dis++;
2879
2880                 /* Sniper */
2881                 if (snipe_type == SP_LITE)
2882                 {
2883                         cave[ny][nx].info |= (CAVE_GLOW);
2884
2885                         note_spot(ny, nx);
2886
2887                         lite_spot(ny, nx);
2888                 }
2889
2890                 /* The player can see the (on screen) missile */
2891                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
2892                 {
2893                         char c = object_char(q_ptr);
2894                         byte a = object_attr(q_ptr);
2895
2896                         /* Draw, Hilite, Fresh, Pause, Erase */
2897                         print_rel(c, a, ny, nx);
2898                         move_cursor_relative(ny, nx);
2899                         Term_fresh();
2900                         Term_xtra(TERM_XTRA_DELAY, msec);
2901                         lite_spot(ny, nx);
2902                         Term_fresh();
2903                 }
2904
2905                 /* The player cannot see the missile */
2906                 else
2907                 {
2908                         /* Pause anyway, for consistancy */
2909                         Term_xtra(TERM_XTRA_DELAY, msec);
2910                 }
2911
2912                 /* Sniper */
2913                 if (snipe_type == SP_KILL_TRAP)
2914                 {
2915                         project(0, 0, ny, nx, 0, GF_KILL_TRAP,
2916                                 (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM), -1);
2917                 }
2918
2919                 /* Sniper */
2920                 if (snipe_type == SP_EVILNESS)
2921                 {
2922                         cave[ny][nx].info &= ~(CAVE_GLOW | CAVE_MARK);
2923
2924                         note_spot(ny, nx);
2925
2926                         lite_spot(ny, nx);
2927                 }
2928
2929                 /* Save the old location */
2930                 prev_y = y;
2931                 prev_x = x;
2932
2933                 /* Save the new location */
2934                 x = nx;
2935                 y = ny;
2936
2937
2938                 /* Monster here, Try to hit it */
2939                 if (cave[y][x].m_idx)
2940                 {
2941                         cave_type *c_mon_ptr = &cave[y][x];
2942
2943                         monster_type *m_ptr = &m_list[c_mon_ptr->m_idx];
2944                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2945
2946                         /* Check the visibility */
2947                         visible = m_ptr->ml;
2948
2949                         /* Note the collision */
2950                         hit_body = TRUE;
2951
2952                         if (MON_CSLEEP(m_ptr))
2953                         {
2954                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
2955                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
2956                         }
2957
2958                         if ((r_ptr->level + 10) > p_ptr->lev)
2959                         {
2960                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
2961                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
2962                                 {
2963                                         SUB_EXP amount = 0;
2964                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
2965                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
2966                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
2967                                         else if (p_ptr->lev > 34) amount = 2;
2968                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
2969                                         p_ptr->update |= (PU_BONUS);
2970                                 }
2971                         }
2972
2973                         if (p_ptr->riding)
2974                         {
2975                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
2976                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
2977                                         && one_in_(2))
2978                                 {
2979                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
2980                                         p_ptr->update |= (PU_BONUS);
2981                                 }
2982                         }
2983
2984                         /* Did we hit it (penalize range) */
2985                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
2986                         {
2987                                 bool fear = FALSE;
2988                                 int tdam = tdam_base;
2989
2990                                 /* Get extra damage from concentration */
2991                                 if (p_ptr->concent) tdam = boost_concentration_damage(tdam);
2992
2993                                 /* Handle unseen monster */
2994                                 if (!visible)
2995                                 {
2996                                         /* Invisible monster */
2997                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
2998                                 }
2999
3000                                 /* Handle visible monster */
3001                                 else
3002                                 {
3003                                         char m_name[80];
3004
3005                                         /* Get "the monster" or "it" */
3006                                         monster_desc(m_name, m_ptr, 0);
3007
3008                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3009
3010                                         if (m_ptr->ml)
3011                                         {
3012                                                 /* Hack -- Track this monster race */
3013                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3014
3015                                                 /* Hack -- Track this monster */
3016                                                 health_track(c_mon_ptr->m_idx);
3017                                         }
3018                                 }
3019
3020                                 if (snipe_type == SP_NEEDLE)
3021                                 {
3022                                         if ((randint1(randint1(r_ptr->level / (3 + p_ptr->concent)) + (8 - p_ptr->concent)) == 1)
3023                                                 && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
3024                                         {
3025                                                 char m_name[80];
3026
3027                                                 /* Get "the monster" or "it" */
3028                                                 monster_desc(m_name, m_ptr, 0);
3029
3030                                                 tdam = m_ptr->hp + 1;
3031                                                 msg_format(_("%sの急所に突き刺さった!", "Your shot sticked on a fatal spot of %s!"), m_name);
3032                                         }
3033                                         else tdam = 1;
3034                                 }
3035                                 else
3036                                 {
3037                                         /* Apply special damage */
3038                                         tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3039                                         tdam = critical_shot(q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
3040
3041                                         /* No negative damage */
3042                                         if (tdam < 0) tdam = 0;
3043
3044                                         /* Modify the damage */
3045                                         tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3046                                 }
3047
3048                                 msg_format_wizard(CHEAT_MONSTER,
3049                                         _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3050                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3051
3052                                 /* Sniper */
3053                                 if (snipe_type == SP_EXPLODE)
3054                                 {
3055                                         u16b flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
3056
3057                                         sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
3058                                         project(0, ((p_ptr->concent + 1) / 2 + 1), ny, nx, tdam, GF_MISSILE, flg, -1);
3059                                         break;
3060                                 }
3061
3062                                 /* Sniper */
3063                                 if (snipe_type == SP_HOLYNESS)
3064                                 {
3065                                         cave[ny][nx].info |= (CAVE_GLOW);
3066                                         note_spot(ny, nx);
3067                                         lite_spot(ny, nx);
3068                                 }
3069
3070                                 /* Hit the monster, check for death */
3071                                 if (mon_take_hit(c_mon_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr))))
3072                                 {
3073                                         /* Dead monster */
3074                                 }
3075
3076                                 /* No death */
3077                                 else
3078                                 {
3079                                         /* STICK TO */
3080                                         if (object_is_fixed_artifact(q_ptr) &&
3081                                                 (p_ptr->pclass != CLASS_SNIPER || p_ptr->concent == 0))
3082                                         {
3083                                                 char m_name[80];
3084
3085                                                 monster_desc(m_name, m_ptr, 0);
3086
3087                                                 stick_to = TRUE;
3088                                                 msg_format(_("%sは%sに突き刺さった!", "%^s have stuck into %s!"),o_name, m_name);
3089                                         }
3090
3091                                         message_pain(c_mon_ptr->m_idx, tdam);
3092
3093                                         /* Anger the monster */
3094                                         if (tdam > 0) anger_monster(m_ptr);
3095
3096                                         /* Take note */
3097                                         if (fear && m_ptr->ml)
3098                                         {
3099                                                 char m_name[80];
3100
3101                                                 sound(SOUND_FLEE);
3102
3103                                                 /* Get the monster name (or "it") */
3104                                                 monster_desc(m_name, m_ptr, 0);
3105
3106                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3107                                         }
3108
3109                                         set_target(m_ptr, p_ptr->y, p_ptr->x);
3110
3111                                         /* Sniper */
3112                                         if (snipe_type == SP_RUSH)
3113                                         {
3114                                                 int n = randint1(5) + 3;
3115                                                 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
3116
3117                                                 for ( ; cur_dis <= tdis; )
3118                                                 {
3119                                                         POSITION ox = nx;
3120                                                         POSITION oy = ny;
3121
3122                                                         if (!n) break;
3123
3124                                                         /* Calculate the new location (see "project()") */
3125                                                         mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
3126
3127                                                         /* Stopped by wilderness boundary */
3128                                                         if (!in_bounds2(ny, nx)) break;
3129
3130                                                         /* Stopped by walls/doors */
3131                                                         if (!player_can_enter(cave[ny][nx].feat, 0)) break;
3132
3133                                                         /* Stopped by monsters */
3134                                                         if (!cave_empty_bold(ny, nx)) break;
3135
3136                                                         cave[ny][nx].m_idx = m_idx;
3137                                                         cave[oy][ox].m_idx = 0;
3138
3139                                                         m_ptr->fx = nx;
3140                                                         m_ptr->fy = ny;
3141
3142                                                         /* Update the monster (new location) */
3143                                                         update_monster(c_mon_ptr->m_idx, TRUE);
3144
3145                                                         lite_spot(ny, nx);
3146                                                         lite_spot(oy, ox);
3147
3148                                                         Term_fresh();
3149                                                         Term_xtra(TERM_XTRA_DELAY, msec);
3150
3151                                                         x = nx;
3152                                                         y = ny;
3153                                                         cur_dis++;
3154                                                         n--;
3155                                                 }
3156                                         }
3157                                 }
3158                         }
3159
3160                         /* Sniper */
3161                         if (snipe_type == SP_PIERCE)
3162                         {
3163                                 if(p_ptr->concent < 1) break;
3164                                 p_ptr->concent--;
3165                                 continue;
3166                         }
3167
3168                         /* Stop looking */
3169                         break;
3170                 }
3171         }
3172
3173         /* Chance of breakage (during attacks) */
3174         j = (hit_body ? breakage_chance(q_ptr) : 0);
3175
3176         if (stick_to)
3177         {
3178                 MONSTER_IDX m_idx = cave[y][x].m_idx;
3179                 monster_type *m_ptr = &m_list[m_idx];
3180                 OBJECT_IDX o_idx = o_pop();
3181
3182                 if (!o_idx)
3183                 {
3184                         msg_format(_("%sはどこかへ行った。", "The %s have gone to somewhere."), o_name);
3185                         if (object_is_fixed_artifact(q_ptr))
3186                         {
3187                                 a_info[j_ptr->name1].cur_num = 0;
3188                         }
3189                         return;
3190                 }
3191
3192                 o_ptr = &o_list[o_idx];
3193                 object_copy(o_ptr, q_ptr);
3194
3195                 /* Forget mark */
3196                 o_ptr->marked &= OM_TOUCHED;
3197
3198                 /* Forget location */
3199                 o_ptr->iy = o_ptr->ix = 0;
3200
3201                 /* Memorize monster */
3202                 o_ptr->held_m_idx = m_idx;
3203
3204                 /* Build a stack */
3205                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3206
3207                 /* Carry object */
3208                 m_ptr->hold_o_idx = o_idx;
3209         }
3210         else if (cave_have_flag_bold(y, x, FF_PROJECT))
3211         {
3212                 /* Drop (or break) near that location */
3213                 (void)drop_near(q_ptr, j, y, x);
3214         }
3215         else
3216         {
3217                 /* Drop (or break) near that location */
3218                 (void)drop_near(q_ptr, j, prev_y, prev_x);
3219         }
3220
3221         /* Sniper - Repeat shooting when double shots */
3222         }
3223
3224         /* Sniper - Loose his/her concentration after any shot */
3225         if (p_ptr->concent) reset_concentration(FALSE);
3226 }
3227
3228 /*!
3229  * @brief 射撃処理のメインルーチン
3230  * @return なし
3231  */
3232 void do_cmd_fire(void)
3233 {
3234         OBJECT_IDX item;
3235         object_type *j_ptr;
3236         cptr q, s;
3237
3238         is_fired = FALSE;       /* not fired yet */
3239
3240         /* Get the "bow" (if any) */
3241         j_ptr = &inventory[INVEN_BOW];
3242
3243         /* Require a launcher */
3244         if (!j_ptr->tval)
3245         {
3246                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
3247                 flush();
3248                 return;
3249         }
3250
3251         if (j_ptr->sval == SV_CRIMSON)
3252         {
3253                 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
3254                 flush();
3255                 return;
3256         }
3257
3258         if (j_ptr->sval == SV_HARP)
3259         {
3260                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
3261                 flush();
3262                 return;
3263         }
3264
3265
3266         if (p_ptr->special_defense & KATA_MUSOU)
3267         {
3268                 set_action(ACTION_NONE);
3269         }
3270
3271         /* Require proper missile */
3272         item_tester_tval = p_ptr->tval_ammo;
3273
3274         q = _("どれを撃ちますか? ", "Fire which item? ");
3275         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
3276         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
3277         {
3278                 flush();
3279                 return;
3280         }
3281
3282         /* Fire the item */
3283         do_cmd_fire_aux(item, j_ptr);
3284
3285         if (!is_fired || p_ptr->pclass != CLASS_SNIPER) return;
3286
3287         /* Sniper actions after some shootings */
3288         if (snipe_type == SP_AWAY)
3289         {
3290                 teleport_player(10 + (p_ptr->concent * 2), 0L);
3291         }
3292         if (snipe_type == SP_FINAL)
3293         {
3294                 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
3295                 (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
3296                 (void)set_stun(p_ptr->stun + randint1(25));
3297         }
3298 }
3299
3300
3301 /*!
3302  * @brief 投射処理メインルーチン /
3303  * Throw an object from the pack or floor.
3304  * @param mult 威力の倍率
3305  * @param boomerang ブーメラン処理ならばTRUE
3306  * @param shuriken 忍者の手裏剣処理ならばTRUE
3307  * @return ターンを消費した場合TRUEを返す
3308  * @details
3309  * <pre>
3310  * Note: "unseen" monsters are very hard to hit.
3311  *
3312  * Should throwing a weapon do full damage?  Should it allow the magic
3313  * to hit bonus of the weapon to have an effect?  Should it ever cause
3314  * the item to be destroyed?  Should it do any damage at all?
3315  * </pre>
3316  */
3317 bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
3318 {
3319         DIRECTION dir;
3320         OBJECT_IDX item;
3321         int i;
3322         POSITION y, x, ty, tx, prev_y, prev_x;
3323         POSITION ny[19], nx[19];
3324         int chance, tdam, tdis;
3325         int mul, div, dd, ds;
3326         int cur_dis, visible;
3327         PERCENTAGE j;
3328
3329         object_type forge;
3330         object_type *q_ptr;
3331
3332         object_type *o_ptr;
3333
3334         bool hit_body = FALSE;
3335         bool hit_wall = FALSE;
3336         bool equiped_item = FALSE;
3337         bool return_when_thrown = FALSE;
3338
3339         char o_name[MAX_NLEN];
3340
3341         int msec = delay_factor * delay_factor * delay_factor;
3342
3343         BIT_FLAGS flgs[TR_FLAG_SIZE];
3344         cptr q, s;
3345         bool come_back = FALSE;
3346         bool do_drop = TRUE;
3347
3348
3349         if (p_ptr->special_defense & KATA_MUSOU)
3350         {
3351                 set_action(ACTION_NONE);
3352         }
3353
3354         if (shuriken >= 0)
3355         {
3356                 item = shuriken;
3357         }
3358         else if (boomerang)
3359         {
3360                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
3361                 {
3362                         item_tester_hook = item_tester_hook_boomerang;
3363                         q = _("どの武器を投げますか? ", "Throw which item? ");
3364                         s = _("投げる武器がない。", "You have nothing to throw.");
3365                         if (!get_item(&item, q, s, (USE_EQUIP)))
3366                         {
3367                                 flush();
3368                                 return FALSE;
3369                         }
3370                 }
3371                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
3372                 else item = INVEN_RARM;
3373         }
3374         else
3375         {
3376                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
3377                 s = _("投げるアイテムがない。", "You have nothing to throw.");
3378                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
3379                 {
3380                         flush();
3381                         return FALSE;
3382                 }
3383         }
3384
3385         /* Access the item (if in the pack) */
3386         if (item >= 0)
3387         {
3388                 o_ptr = &inventory[item];
3389         }
3390         else
3391         {
3392                 o_ptr = &o_list[0 - item];
3393         }
3394
3395         /* Item is cursed */
3396         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
3397         {
3398                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
3399
3400                 return FALSE;
3401         }
3402
3403         if (p_ptr->inside_arena && !boomerang)
3404         {
3405                 if (o_ptr->tval != TV_SPIKE)
3406                 {
3407                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
3408                         msg_print(NULL);
3409
3410                         return FALSE;
3411                 }
3412
3413         }
3414         q_ptr = &forge;
3415
3416         /* Obtain a local object */
3417         object_copy(q_ptr, o_ptr);
3418
3419         /* Extract the thrown object's flags. */
3420         object_flags(q_ptr, flgs);
3421         torch_flags(q_ptr, flgs);
3422
3423         /* Distribute the charges of rods/wands between the stacks */
3424         distribute_charges(o_ptr, q_ptr, 1);
3425
3426         /* Single object */
3427         q_ptr->number = 1;
3428
3429         /* Description */
3430         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
3431
3432         if (p_ptr->mighty_throw) mult += 3;
3433
3434         /* Extract a "distance multiplier" */
3435         /* Changed for 'launcher' mutation */
3436         mul = 10 + 2 * (mult - 1);
3437
3438         /* Enforce a minimum "weight" of one pound */
3439         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
3440         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
3441
3442         /* Hack -- Distance -- Reward strength, penalize weight */
3443         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
3444
3445         /* Max distance of 10-18 */
3446         if (tdis > mul) tdis = mul;
3447
3448         if (shuriken >= 0)
3449         {
3450                 ty = randint0(101) - 50 + p_ptr->y;
3451                 tx = randint0(101) - 50 + p_ptr->x;
3452         }
3453         else
3454         {
3455                 project_length = tdis + 1;
3456
3457                 /* Get a direction (or cancel) */
3458                 if (!get_aim_dir(&dir)) return FALSE;
3459
3460                 /* Predict the "target" location */
3461                 tx = p_ptr->x + 99 * ddx[dir];
3462                 ty = p_ptr->y + 99 * ddy[dir];
3463
3464                 /* Check for "target request" */
3465                 if ((dir == 5) && target_okay())
3466                 {
3467                         tx = target_col;
3468                         ty = target_row;
3469                 }
3470
3471                 project_length = 0;  /* reset to default */
3472         }
3473
3474         if ((q_ptr->name1 == ART_MJOLLNIR) ||
3475             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
3476                 return_when_thrown = TRUE;
3477
3478         /* Reduce and describe inventory */
3479         if (item >= 0)
3480         {
3481                 inven_item_increase(item, -1);
3482                 if (!return_when_thrown)
3483                         inven_item_describe(item);
3484                 inven_item_optimize(item);
3485         }
3486
3487         /* Reduce and describe floor item */
3488         else
3489         {
3490                 floor_item_increase(0 - item, -1);
3491                 floor_item_optimize(0 - item);
3492         }
3493         if (item >= INVEN_RARM)
3494         {
3495                 equiped_item = TRUE;
3496                 p_ptr->redraw |= (PR_EQUIPPY);
3497         }
3498
3499         p_ptr->energy_use = 100;
3500
3501         /* Rogue and Ninja gets bonus */
3502         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
3503                 p_ptr->energy_use -= p_ptr->lev;
3504
3505         /* Start at the player */
3506         y = p_ptr->y;
3507         x = p_ptr->x;
3508
3509         handle_stuff();
3510
3511         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
3512         else shuriken = FALSE;
3513
3514         /* Chance of hitting */
3515         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
3516                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
3517         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
3518
3519         if (shuriken) chance *= 2;
3520
3521         /* Save the old location */
3522         prev_y = y;
3523         prev_x = x;
3524
3525         /* Travel until stopped */
3526         for (cur_dis = 0; cur_dis <= tdis; )
3527         {
3528                 /* Hack -- Stop at the target */
3529                 if ((y == ty) && (x == tx)) break;
3530
3531                 /* Calculate the new location (see "project()") */
3532                 ny[cur_dis] = y;
3533                 nx[cur_dis] = x;
3534                 mmove2(&ny[cur_dis], &nx[cur_dis], p_ptr->y, p_ptr->x, ty, tx);
3535
3536                 /* Stopped by walls/doors */
3537                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
3538                 {
3539                         hit_wall = TRUE;
3540                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
3541                 }
3542
3543                 /* The player can see the (on screen) missile */
3544                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
3545                 {
3546                         char c = object_char(q_ptr);
3547                         byte a = object_attr(q_ptr);
3548
3549                         /* Draw, Hilite, Fresh, Pause, Erase */
3550                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
3551                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
3552                         Term_fresh();
3553                         Term_xtra(TERM_XTRA_DELAY, msec);
3554                         lite_spot(ny[cur_dis], nx[cur_dis]);
3555                         Term_fresh();
3556                 }
3557
3558                 /* The player cannot see the missile */
3559                 else
3560                 {
3561                         /* Pause anyway, for consistancy */
3562                         Term_xtra(TERM_XTRA_DELAY, msec);
3563                 }
3564
3565                 /* Save the old location */
3566                 prev_y = y;
3567                 prev_x = x;
3568
3569                 /* Save the new location */
3570                 x = nx[cur_dis];
3571                 y = ny[cur_dis];
3572
3573                 /* Advance the distance */
3574                 cur_dis++;
3575
3576                 /* Monster here, Try to hit it */
3577                 if (cave[y][x].m_idx)
3578                 {
3579                         cave_type *c_ptr = &cave[y][x];
3580                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3581
3582                         /* Check the visibility */
3583                         visible = m_ptr->ml;
3584
3585                         /* Note the collision */
3586                         hit_body = TRUE;
3587
3588                         /* Did we hit it (penalize range) */
3589                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3590                         {
3591                                 bool fear = FALSE;
3592
3593                                 /* Handle unseen monster */
3594                                 if (!visible)
3595                                 {
3596                                         /* Invisible monster */
3597                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
3598                                 }
3599
3600                                 /* Handle visible monster */
3601                                 else
3602                                 {
3603                                         char m_name[80];
3604
3605                                         /* Get "the monster" or "it" */
3606                                         monster_desc(m_name, m_ptr, 0);
3607
3608                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3609
3610                                         if (m_ptr->ml)
3611                                         {
3612                                                 /* Hack -- Track this monster race */
3613                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3614
3615                                                 /* Hack -- Track this monster */
3616                                                 health_track(c_ptr->m_idx);
3617                                         }
3618                                 }
3619
3620                                 /* Hack -- Base damage from thrown object */
3621                                 dd = q_ptr->dd;
3622                                 ds = q_ptr->ds;
3623                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
3624                                 tdam = damroll(dd, ds);
3625                                 /* Apply special damage */
3626                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
3627                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
3628                                 if (q_ptr->to_d > 0)
3629                                         tdam += q_ptr->to_d;
3630                                 else
3631                                         tdam += -q_ptr->to_d;
3632
3633                                 if (boomerang)
3634                                 {
3635                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
3636                                         tdam += p_ptr->to_d_m;
3637                                 }
3638                                 else if (have_flag(flgs, TR_THROW))
3639                                 {
3640                                         tdam *= (3+mult);
3641                                         tdam += p_ptr->to_d_m;
3642                                 }
3643                                 else
3644                                 {
3645                                         tdam *= mult;
3646                                 }
3647                                 if (shuriken)
3648                                 {
3649                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
3650                                 }
3651
3652                                 /* No negative damage */
3653                                 if (tdam < 0) tdam = 0;
3654
3655                                 /* Modify the damage */
3656                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3657
3658                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3659                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3660
3661                                 /* Hit the monster, check for death */
3662                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr))))
3663                                 {
3664                                         /* Dead monster */
3665                                 }
3666
3667                                 /* No death */
3668                                 else
3669                                 {
3670                                         message_pain(c_ptr->m_idx, tdam);
3671
3672                                         /* Anger the monster */
3673                                         if ((tdam > 0) && !object_is_potion(q_ptr))
3674                                                 anger_monster(m_ptr);
3675
3676                                         /* Take note */
3677                                         if (fear && m_ptr->ml)
3678                                         {
3679                                                 char m_name[80];
3680
3681                                                 sound(SOUND_FLEE);
3682
3683                                                 /* Get the monster name (or "it") */
3684                                                 monster_desc(m_name, m_ptr, 0);
3685
3686                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3687                                         }
3688                                 }
3689                         }
3690
3691                         /* Stop looking */
3692                         break;
3693                 }
3694         }
3695
3696         /* decrease toach's fuel */
3697         if (hit_body) torch_lost_fuel(q_ptr);
3698
3699         /* Chance of breakage (during attacks) */
3700         j = (hit_body ? breakage_chance(q_ptr) : 0);
3701
3702         /* Figurines transform */
3703         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
3704         {
3705                 j = 100;
3706
3707                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
3708                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
3709                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
3710                 else if (object_is_cursed(q_ptr))
3711                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
3712
3713         }
3714
3715
3716         /* Potions smash open */
3717         if (object_is_potion(q_ptr))
3718         {
3719                 if (hit_body || hit_wall || (randint1(100) < j))
3720                 {
3721                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
3722
3723                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
3724                         {
3725                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
3726
3727                                 /* ToDo (Robert): fix the invulnerability */
3728                                 if (cave[y][x].m_idx &&
3729                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
3730                                     !MON_INVULNER(m_ptr))
3731                                 {
3732                                         char m_name[80];
3733                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
3734                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
3735                                         set_hostile(&m_list[cave[y][x].m_idx]);
3736                                 }
3737                         }
3738                         do_drop = FALSE;
3739                 }
3740                 else
3741                 {
3742                         j = 0;
3743                 }
3744         }
3745
3746         if (return_when_thrown)
3747         {
3748                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
3749                 char o2_name[MAX_NLEN];
3750                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
3751
3752                 j = -1;
3753                 if (boomerang) back_chance += 4+randint1(5);
3754                 if (super_boomerang) back_chance += 100;
3755                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3756
3757                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
3758                 {
3759                         for (i = cur_dis - 1; i > 0; i--)
3760                         {
3761                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
3762                                 {
3763                                         char c = object_char(q_ptr);
3764                                         byte a = object_attr(q_ptr);
3765
3766                                         /* Draw, Hilite, Fresh, Pause, Erase */
3767                                         print_rel(c, a, ny[i], nx[i]);
3768                                         move_cursor_relative(ny[i], nx[i]);
3769                                         Term_fresh();
3770                                         Term_xtra(TERM_XTRA_DELAY, msec);
3771                                         lite_spot(ny[i], nx[i]);
3772                                         Term_fresh();
3773                                 }
3774                                 else
3775                                 {
3776                                         /* Pause anyway, for consistancy */
3777                                         Term_xtra(TERM_XTRA_DELAY, msec);
3778                                 }
3779                         }
3780                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
3781                         {
3782                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
3783                                 come_back = TRUE;
3784                         }
3785                         else
3786                         {
3787                                 if (item >= 0)
3788                                 {
3789                                         msg_format(_("%sを受け損ねた!", "%s backs, but you can't catch!"), o2_name);
3790                                 }
3791                                 else
3792                                 {
3793                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
3794                                 }
3795                                 y = p_ptr->y;
3796                                 x = p_ptr->x;
3797                         }
3798                 }
3799                 else
3800                 {
3801                         msg_format(_("%sが返ってこなかった!", "%s doesn't back!"), o2_name);
3802                 }
3803         }
3804
3805         if (come_back)
3806         {
3807                 if (item == INVEN_RARM || item == INVEN_LARM)
3808                 {
3809                         /* Access the wield slot */
3810                         o_ptr = &inventory[item];
3811
3812                         /* Wear the new stuff */
3813                         object_copy(o_ptr, q_ptr);
3814
3815                         /* Increase the weight */
3816                         p_ptr->total_weight += q_ptr->weight;
3817
3818                         /* Increment the equip counter by hand */
3819                         equip_cnt++;
3820
3821                         /* Recalculate bonuses */
3822                         p_ptr->update |= (PU_BONUS);
3823
3824                         /* Recalculate torch */
3825                         p_ptr->update |= (PU_TORCH);
3826
3827                         /* Recalculate mana XXX */
3828                         p_ptr->update |= (PU_MANA);
3829
3830                         p_ptr->window |= (PW_EQUIP);
3831                 }
3832                 else
3833                 {
3834                         inven_carry(q_ptr);
3835                 }
3836                 do_drop = FALSE;
3837         }
3838         else if (equiped_item)
3839         {
3840                 kamaenaoshi(item);
3841                 calc_android_exp();
3842         }
3843
3844         /* Drop (or break) near that location */
3845         if (do_drop)
3846         {
3847                 if (cave_have_flag_bold(y, x, FF_PROJECT))
3848                 {
3849                         /* Drop (or break) near that location */
3850                         (void)drop_near(q_ptr, j, y, x);
3851                 }
3852                 else
3853                 {
3854                         /* Drop (or break) near that location */
3855                         (void)drop_near(q_ptr, j, prev_y, prev_x);
3856                 }
3857         }
3858
3859         return TRUE;
3860 }
3861
3862
3863 #ifdef TRAVEL
3864 /*
3865  * Hack: travel command
3866  */
3867 #define TRAVEL_UNABLE 9999
3868
3869 static int flow_head = 0;
3870 static int flow_tail = 0;
3871 static POSITION temp2_x[MAX_SHORT];
3872 static POSITION temp2_y[MAX_SHORT];
3873
3874 /*!
3875  * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information 
3876  * @return なし
3877  */
3878 void forget_travel_flow(void)
3879 {
3880         POSITION x, y;
3881
3882         /* Check the entire dungeon */
3883         for (y = 0; y < cur_hgt; y++)
3884         {
3885                 for (x = 0; x < cur_wid; x++)
3886                 {
3887                         /* Forget the old data */
3888                         travel.cost[y][x] = MAX_SHORT;
3889                 }
3890         }
3891
3892         travel.y = travel.x = 0;
3893 }
3894
3895 /*!
3896  * @brief トラベル処理中に地形に応じた移動コスト基準を返す
3897  * @param y 該当地点のY座標
3898  * @param x 該当地点のX座標
3899  * @return コスト値
3900  */
3901 static int travel_flow_cost(POSITION y, POSITION x)
3902 {
3903         feature_type *f_ptr = &f_info[cave[y][x].feat];
3904         int cost = 1;
3905
3906         /* Avoid obstacles (ex. trees) */
3907         if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
3908
3909         /* Water */
3910         if (have_flag(f_ptr->flags, FF_WATER))
3911         {
3912                 if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
3913         }
3914
3915         /* Lava */
3916         if (have_flag(f_ptr->flags, FF_LAVA))
3917         {
3918                 int lava = 2;
3919                 if (!p_ptr->resist_fire) lava *= 2;
3920                 if (!p_ptr->levitation) lava *= 2;
3921                 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
3922
3923                 cost += lava;
3924         }
3925
3926         /* Detected traps and doors */
3927         if (cave[y][x].info & (CAVE_MARK))
3928         {
3929                 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
3930                 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
3931         }
3932
3933         return (cost);
3934 }
3935
3936 /*!
3937  * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
3938  * @param y 目標地点のY座標
3939  * @param x 目標地点のX座標
3940  * @param n 現在のコスト
3941  * @param wall プレイヤーが壁の中にいるならばTRUE
3942  * @return なし
3943  */
3944 static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
3945 {
3946         cave_type *c_ptr = &cave[y][x];
3947         feature_type *f_ptr = &f_info[c_ptr->feat];
3948         int old_head = flow_head;
3949         int add_cost = 1;
3950         int base_cost = (n % TRAVEL_UNABLE);
3951         int from_wall = (n / TRAVEL_UNABLE);
3952         int cost;
3953
3954         /* Ignore out of bounds */
3955         if (!in_bounds(y, x)) return;
3956
3957         /* Ignore unknown grid except in wilderness */
3958         if (dun_level > 0 && !(c_ptr->info & CAVE_KNOWN)) return;
3959
3960         /* Ignore "walls" and "rubble" (include "secret doors") */
3961         if (have_flag(f_ptr->flags, FF_WALL) ||
3962                 have_flag(f_ptr->flags, FF_CAN_DIG) ||
3963                 (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic) ||
3964                 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
3965         {
3966                 if (!wall || !from_wall) return;
3967                 add_cost += TRAVEL_UNABLE;
3968         }
3969         else
3970         {
3971                 add_cost = travel_flow_cost(y, x);
3972         }
3973
3974         cost = base_cost + add_cost;
3975
3976         /* Ignore lower cost entries */
3977         if (travel.cost[y][x] <= cost) return;
3978
3979         /* Save the flow cost */
3980         travel.cost[y][x] = cost;
3981
3982         /* Enqueue that entry */
3983         temp2_y[flow_head] = y;
3984         temp2_x[flow_head] = x;
3985
3986         /* Advance the queue */
3987         if (++flow_head == MAX_SHORT) flow_head = 0;
3988
3989         /* Hack -- notice overflow by forgetting new entry */
3990         if (flow_head == flow_tail) flow_head = old_head;
3991
3992         return;
3993 }
3994
3995 /*!
3996  * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
3997  * @param ty 目標地点のY座標
3998  * @param tx 目標地点のX座標
3999  * @return なし
4000  */
4001 static void travel_flow(POSITION ty, POSITION tx)
4002 {
4003         POSITION x, y, d;
4004         bool wall = FALSE;
4005         feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
4006
4007         /* Reset the "queue" */
4008         flow_head = flow_tail = 0;
4009
4010         /* is player in the wall? */
4011         if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
4012
4013         /* Start at the target grid */
4014         travel_flow_aux(ty, tx, 0, wall);
4015
4016         /* Now process the queue */
4017         while (flow_head != flow_tail)
4018         {
4019                 /* Extract the next entry */
4020                 y = temp2_y[flow_tail];
4021                 x = temp2_x[flow_tail];
4022
4023                 /* Forget that entry */
4024                 if (++flow_tail == MAX_SHORT) flow_tail = 0;
4025
4026                 /* Ignore too far entries */
4027                 //if (distance(ty, tx, y, x) > 100) continue;
4028
4029                 /* Add the "children" */
4030                 for (d = 0; d < 8; d++)
4031                 {
4032                         /* Add that child if "legal" */
4033                         travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
4034                 }
4035         }
4036
4037         /* Forget the flow info */
4038         flow_head = flow_tail = 0;
4039 }
4040
4041 /*!
4042  * @brief トラベル処理のメインルーチン
4043  * @return なし
4044  */
4045 void do_cmd_travel(void)
4046 {
4047         POSITION x, y;
4048         int i;
4049         int dx, dy, sx, sy;
4050         feature_type *f_ptr;
4051
4052         if (travel.x != 0 && travel.y != 0 &&
4053             get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
4054         {
4055                 y = travel.y;
4056                 x = travel.x;
4057         }
4058         else if (!tgt_pt(&x, &y)) return;
4059
4060         if ((x == p_ptr->x) && (y == p_ptr->y))
4061         {
4062                 msg_print(_("すでにそこにいます!", "You are already there!!"));
4063                 return;
4064         }
4065
4066         f_ptr = &f_info[cave[y][x].feat];
4067
4068         if ((cave[y][x].info & CAVE_MARK) &&
4069                 (have_flag(f_ptr->flags, FF_WALL) ||
4070                         have_flag(f_ptr->flags, FF_CAN_DIG) ||
4071                         (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic)))
4072         {
4073                 msg_print(_("そこには行くことができません!", "You cannot travel there!"));
4074                 return;
4075         }
4076
4077         forget_travel_flow();
4078         travel_flow(y, x);
4079
4080         travel.x = x;
4081         travel.y = y;
4082
4083         /* Travel till 255 steps */
4084         travel.run = 255;
4085
4086         /* Paranoia */
4087         travel.dir = 0;
4088
4089         /* Decides first direction */
4090         dx = abs(p_ptr->x - x);
4091         dy = abs(p_ptr->y - y);
4092         sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
4093         sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
4094
4095         for (i = 1; i <= 9; i++)
4096         {
4097                 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
4098         }
4099 }
4100 #endif