OSDN Git Service

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