OSDN Git Service

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