OSDN Git Service

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