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