OSDN Git Service

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