OSDN Git Service

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