OSDN Git Service

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