OSDN Git Service

bafddf74f86cf7cbb0c7751c0183fc1e6fc1d4e2
[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         handle_stuff();
2218
2219         /* Refresh */
2220         Term_fresh();
2221 }
2222
2223
2224 /*!
2225  * @brief 矢弾を射撃した場合の破損確率を返す /
2226  * Determines the odds of an object breaking when thrown at a monster
2227  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2228  * @return 破損確率(%)
2229  * @details
2230  * Note that artifacts never break, see the "drop_near()" function.
2231  */
2232 static PERCENTAGE breakage_chance(object_type *o_ptr)
2233 {
2234         PERCENTAGE archer_bonus = (p_ptr->pclass == CLASS_ARCHER ? (PERCENTAGE)(p_ptr->lev-1)/7 + 4: 0);
2235
2236         /* Examine the snipe type */
2237         if (snipe_type)
2238         {
2239                 if (snipe_type == SP_KILL_WALL) return (100);
2240                 if (snipe_type == SP_EXPLODE) return (100);
2241                 if (snipe_type == SP_PIERCE) return (100);
2242                 if (snipe_type == SP_FINAL) return (100);
2243                 if (snipe_type == SP_NEEDLE) return (100);
2244                 if (snipe_type == SP_EVILNESS) return (40);
2245                 if (snipe_type == SP_HOLYNESS) return (40);
2246         }
2247
2248         /* Examine the item type */
2249         switch (o_ptr->tval)
2250         {
2251                 /* Always break */
2252                 case TV_FLASK:
2253                 case TV_POTION:
2254                 case TV_BOTTLE:
2255                 case TV_FOOD:
2256                 case TV_JUNK:
2257                         return (100);
2258
2259                 /* Often break */
2260                 case TV_LITE:
2261                 case TV_SCROLL:
2262                 case TV_SKELETON:
2263                         return (50);
2264
2265                 /* Sometimes break */
2266                 case TV_WAND:
2267                 case TV_SPIKE:
2268                         return (25);
2269                 case TV_ARROW:
2270                         return (20 - archer_bonus * 2);
2271
2272                 /* Rarely break */
2273                 case TV_SHOT:
2274                 case TV_BOLT:
2275                         return (10 - archer_bonus);
2276                 default:
2277                         return (10);
2278         }
2279 }
2280
2281
2282 /*!
2283  * @brief 矢弾を射撃した際のスレイ倍率をかけた結果を返す /
2284  * Determines the odds of an object breaking when thrown at a monster
2285  * @param o_ptr 矢弾のオブジェクト構造体参照ポインタ
2286  * @param tdam 計算途中のダメージ量
2287  * @param m_ptr 目標モンスターの構造体参照ポインタ
2288  * @return スレイ倍率をかけたダメージ量
2289  */
2290 static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
2291 {
2292         int mult = 10;
2293
2294         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2295
2296         BIT_FLAGS flgs[TR_FLAG_SIZE];
2297
2298         /* Extract the flags */
2299         object_flags(o_ptr, flgs);
2300
2301         /* Some "weapons" and "ammo" do extra damage */
2302         switch (o_ptr->tval)
2303         {
2304                 case TV_SHOT:
2305                 case TV_ARROW:
2306                 case TV_BOLT:
2307                 {
2308                         /* Slay Animal */
2309                         if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
2310                             (r_ptr->flags3 & RF3_ANIMAL))
2311                         {
2312                                 if (is_original_ap_and_seen(m_ptr))
2313                                 {
2314                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2315                                 }
2316
2317                                 if (mult < 17) mult = 17;
2318                         }
2319
2320                         /* Kill Animal */
2321                         if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
2322                             (r_ptr->flags3 & RF3_ANIMAL))
2323                         {
2324                                 if (is_original_ap_and_seen(m_ptr))
2325                                 {
2326                                         r_ptr->r_flags3 |= RF3_ANIMAL;
2327                                 }
2328
2329                                 if (mult < 27) mult = 27;
2330                         }
2331
2332                         /* Slay Evil */
2333                         if ((have_flag(flgs, TR_SLAY_EVIL)) &&
2334                             (r_ptr->flags3 & RF3_EVIL))
2335                         {
2336                                 if (is_original_ap_and_seen(m_ptr))
2337                                 {
2338                                         r_ptr->r_flags3 |= RF3_EVIL;
2339                                 }
2340
2341                                 if (mult < 15) mult = 15;
2342                         }
2343
2344                         /* Kill Evil */
2345                         if ((have_flag(flgs, TR_KILL_EVIL)) &&
2346                             (r_ptr->flags3 & RF3_EVIL))
2347                         {
2348                                 if (is_original_ap_and_seen(m_ptr))
2349                                 {
2350                                         r_ptr->r_flags3 |= RF3_EVIL;
2351                                 }
2352
2353                                 if (mult < 25) mult = 25;
2354                         }
2355
2356                         /* Slay Human */
2357                         if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
2358                             (r_ptr->flags2 & RF2_HUMAN))
2359                         {
2360                                 if (is_original_ap_and_seen(m_ptr))
2361                                 {
2362                                         r_ptr->r_flags2 |= RF2_HUMAN;
2363                                 }
2364
2365                                 if (mult < 17) mult = 17;
2366                         }
2367
2368                         /* Kill Human */
2369                         if ((have_flag(flgs, TR_KILL_HUMAN)) &&
2370                             (r_ptr->flags2 & RF2_HUMAN))
2371                         {
2372                                 if (is_original_ap_and_seen(m_ptr))
2373                                 {
2374                                         r_ptr->r_flags2 |= RF2_HUMAN;
2375                                 }
2376
2377                                 if (mult < 27) mult = 27;
2378                         }
2379
2380                         /* Slay Undead */
2381                         if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
2382                             (r_ptr->flags3 & RF3_UNDEAD))
2383                         {
2384                                 if (is_original_ap_and_seen(m_ptr))
2385                                 {
2386                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2387                                 }
2388
2389                                 if (mult < 20) mult = 20;
2390                         }
2391
2392                         /* Kill Undead */
2393                         if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
2394                             (r_ptr->flags3 & RF3_UNDEAD))
2395                         {
2396                                 if (is_original_ap_and_seen(m_ptr))
2397                                 {
2398                                         r_ptr->r_flags3 |= RF3_UNDEAD;
2399                                 }
2400
2401                                 if (mult < 30) mult = 30;
2402                         }
2403
2404                         /* Slay Demon */
2405                         if ((have_flag(flgs, TR_SLAY_DEMON)) &&
2406                             (r_ptr->flags3 & RF3_DEMON))
2407                         {
2408                                 if (is_original_ap_and_seen(m_ptr))
2409                                 {
2410                                         r_ptr->r_flags3 |= RF3_DEMON;
2411                                 }
2412
2413                                 if (mult < 20) mult = 20;
2414                         }
2415
2416                         /* Kill Demon */
2417                         if ((have_flag(flgs, TR_KILL_DEMON)) &&
2418                             (r_ptr->flags3 & RF3_DEMON))
2419                         {
2420                                 if (is_original_ap_and_seen(m_ptr))
2421                                 {
2422                                         r_ptr->r_flags3 |= RF3_DEMON;
2423                                 }
2424
2425                                 if (mult < 30) mult = 30;
2426                         }
2427
2428                         /* Slay Orc */
2429                         if ((have_flag(flgs, TR_SLAY_ORC)) &&
2430                             (r_ptr->flags3 & RF3_ORC))
2431                         {
2432                                 if (is_original_ap_and_seen(m_ptr))
2433                                 {
2434                                         r_ptr->r_flags3 |= RF3_ORC;
2435                                 }
2436
2437                                 if (mult < 20) mult = 20;
2438                         }
2439
2440                         /* Kill Orc */
2441                         if ((have_flag(flgs, TR_KILL_ORC)) &&
2442                             (r_ptr->flags3 & RF3_ORC))
2443                         {
2444                                 if (is_original_ap_and_seen(m_ptr))
2445                                 {
2446                                         r_ptr->r_flags3 |= RF3_ORC;
2447                                 }
2448
2449                                 if (mult < 30) mult = 30;
2450                         }
2451
2452                         /* Slay Troll */
2453                         if ((have_flag(flgs, TR_SLAY_TROLL)) &&
2454                             (r_ptr->flags3 & RF3_TROLL))
2455                         {
2456                                 if (is_original_ap_and_seen(m_ptr))
2457                                 {
2458                                         r_ptr->r_flags3 |= RF3_TROLL;
2459                                 }
2460
2461                                 if (mult < 20) mult = 20;
2462                         }
2463
2464                         /* Kill Troll */
2465                         if ((have_flag(flgs, TR_KILL_TROLL)) &&
2466                             (r_ptr->flags3 & RF3_TROLL))
2467                         {
2468                                 if (is_original_ap_and_seen(m_ptr))
2469                                 {
2470                                         r_ptr->r_flags3 |= RF3_TROLL;
2471                                 }
2472
2473                                 if (mult < 30) mult = 30;
2474                         }
2475
2476                         /* Slay Giant */
2477                         if ((have_flag(flgs, TR_SLAY_GIANT)) &&
2478                             (r_ptr->flags3 & RF3_GIANT))
2479                         {
2480                                 if (is_original_ap_and_seen(m_ptr))
2481                                 {
2482                                         r_ptr->r_flags3 |= RF3_GIANT;
2483                                 }
2484
2485                                 if (mult < 20) mult = 20;
2486                         }
2487
2488                         /* Kill Giant */
2489                         if ((have_flag(flgs, TR_KILL_GIANT)) &&
2490                             (r_ptr->flags3 & RF3_GIANT))
2491                         {
2492                                 if (is_original_ap_and_seen(m_ptr))
2493                                 {
2494                                         r_ptr->r_flags3 |= RF3_GIANT;
2495                                 }
2496
2497                                 if (mult < 30) mult = 30;
2498                         }
2499
2500                         /* Slay Dragon  */
2501                         if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
2502                             (r_ptr->flags3 & RF3_DRAGON))
2503                         {
2504                                 if (is_original_ap_and_seen(m_ptr))
2505                                 {
2506                                         r_ptr->r_flags3 |= RF3_DRAGON;
2507                                 }
2508
2509                                 if (mult < 20) mult = 20;
2510                         }
2511
2512                         /* Execute Dragon */
2513                         if ((have_flag(flgs, TR_KILL_DRAGON)) &&
2514                             (r_ptr->flags3 & RF3_DRAGON))
2515                         {
2516                                 if (is_original_ap_and_seen(m_ptr))
2517                                 {
2518                                         r_ptr->r_flags3 |= RF3_DRAGON;
2519                                 }
2520
2521                                 if (mult < 30) mult = 30;
2522
2523                                 if ((o_ptr->name1 == ART_BARD_ARROW) &&
2524                                     (m_ptr->r_idx == MON_SMAUG) &&
2525                                     (inventory[INVEN_BOW].name1 == ART_BARD))
2526                                         mult *= 5;
2527                         }
2528
2529                         /* Brand (Acid) */
2530                         if (have_flag(flgs, TR_BRAND_ACID))
2531                         {
2532                                 /* Notice immunity */
2533                                 if (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)
2534                                 {
2535                                         if (is_original_ap_and_seen(m_ptr))
2536                                         {
2537                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ACID_MASK);
2538                                         }
2539                                 }
2540
2541                                 /* Otherwise, take the damage */
2542                                 else
2543                                 {
2544                                         if (mult < 17) mult = 17;
2545                                 }
2546                         }
2547
2548                         /* Brand (Elec) */
2549                         if (have_flag(flgs, TR_BRAND_ELEC))
2550                         {
2551                                 /* Notice immunity */
2552                                 if (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)
2553                                 {
2554                                         if (is_original_ap_and_seen(m_ptr))
2555                                         {
2556                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
2557                                         }
2558                                 }
2559
2560                                 /* Otherwise, take the damage */
2561                                 else
2562                                 {
2563                                         if (mult < 17) mult = 17;
2564                                 }
2565                         }
2566
2567                         /* Brand (Fire) */
2568                         if (have_flag(flgs, TR_BRAND_FIRE))
2569                         {
2570                                 /* Notice immunity */
2571                                 if (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)
2572                                 {
2573                                         if (is_original_ap_and_seen(m_ptr))
2574                                         {
2575                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
2576                                         }
2577                                 }
2578
2579                                 /* Otherwise, take the damage */
2580                                 else
2581                                 {
2582                                         if (r_ptr->flags3 & RF3_HURT_FIRE)
2583                                         {
2584                                                 if (mult < 25) mult = 25;
2585                                                 if (is_original_ap_and_seen(m_ptr))
2586                                                 {
2587                                                         r_ptr->r_flags3 |= RF3_HURT_FIRE;
2588                                                 }
2589                                         }
2590                                         else if (mult < 17) mult = 17;
2591                                 }
2592                         }
2593
2594                         /* Brand (Cold) */
2595                         if (have_flag(flgs, TR_BRAND_COLD))
2596                         {
2597                                 /* Notice immunity */
2598                                 if (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)
2599                                 {
2600                                         if (is_original_ap_and_seen(m_ptr))
2601                                         {
2602                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
2603                                         }
2604                                 }
2605                                 /* Otherwise, take the damage */
2606                                 else
2607                                 {
2608                                         if (r_ptr->flags3 & RF3_HURT_COLD)
2609                                         {
2610                                                 if (mult < 25) mult = 25;
2611                                                 if (is_original_ap_and_seen(m_ptr))
2612                                                 {
2613                                                         r_ptr->r_flags3 |= RF3_HURT_COLD;
2614                                                 }
2615                                         }
2616                                         else if (mult < 17) mult = 17;
2617                                 }
2618                         }
2619
2620                         /* Brand (Poison) */
2621                         if (have_flag(flgs, TR_BRAND_POIS))
2622                         {
2623                                 /* Notice immunity */
2624                                 if (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)
2625                                 {
2626                                         if (is_original_ap_and_seen(m_ptr))
2627                                         {
2628                                                 r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_POIS_MASK);
2629                                         }
2630                                 }
2631
2632                                 /* Otherwise, take the damage */
2633                                 else
2634                                 {
2635                                         if (mult < 17) mult = 17;
2636                                 }
2637                         }
2638
2639                         if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
2640                         {
2641                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
2642                                 p_ptr->redraw |= (PR_MANA);
2643                                 mult = mult * 5 / 2;
2644                         }
2645                         break;
2646                 }
2647         }
2648
2649         /* Sniper */
2650         if (snipe_type) mult = tot_dam_aux_snipe(mult, m_ptr);
2651
2652         /* Return the total damage */
2653         return (tdam * mult / 10);
2654 }
2655
2656
2657 /*!
2658  * @brief 射撃処理のサブルーチン /
2659  * Fire an object from the pack or floor.
2660  * @param item 射撃するオブジェクトの所持ID
2661  * @param j_ptr 射撃武器のオブジェクト参照ポインタ
2662  * @return なし
2663  * @details
2664  * <pre>
2665  * You may only fire items that "match" your missile launcher.
2666  *
2667  * You must use slings + pebbles/shots, bows + arrows, xbows + bolts.
2668  *
2669  * See "calc_bonuses()" for more calculations and such.
2670  *
2671  * Note that "firing" a missile is MUCH better than "throwing" it.
2672  *
2673  * Note: "unseen" monsters are very hard to hit.
2674  *
2675  * Objects are more likely to break if they "attempt" to hit a monster.
2676  *
2677  * Rangers (with Bows) and Anyone (with "Extra Shots") get extra shots.
2678  *
2679  * The "extra shot" code works by decreasing the amount of energy
2680  * required to make each shot, spreading the shots out over time.
2681  *
2682  * Note that when firing missiles, the launcher multiplier is applied
2683  * after all the bonuses are added in, making multipliers very useful.
2684  *
2685  * Note that Bows of "Extra Might" get extra range and an extra bonus
2686  * for the damage multiplier.
2687  *
2688  * Note that Bows of "Extra Shots" give an extra shot.
2689  * </pre>
2690  */
2691 void do_cmd_fire_aux(INVENTORY_IDX item, object_type *j_ptr)
2692 {
2693         DIRECTION dir;
2694         int i;
2695         POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
2696         int tdam_base, tdis, thits, tmul;
2697         int bonus, chance;
2698         int cur_dis, visible;
2699         PERCENTAGE j;
2700
2701         object_type forge;
2702         object_type *q_ptr;
2703
2704         object_type *o_ptr;
2705
2706         bool hit_body = FALSE;
2707
2708         char o_name[MAX_NLEN];
2709
2710         u16b path_g[512];       /* For calcuration of path length */
2711
2712         int msec = delay_factor * delay_factor * delay_factor;
2713
2714         /* STICK TO */
2715         bool stick_to = FALSE;
2716
2717         /* Access the item (if in the pack) */
2718         if (item >= 0)
2719         {
2720                 o_ptr = &inventory[item];
2721         }
2722         else
2723         {
2724                 o_ptr = &o_list[0 - item];
2725         }
2726
2727         /* Sniper - Cannot shot a single arrow twice */
2728         if ((snipe_type == SP_DOUBLE) && (o_ptr->number < 2)) snipe_type = SP_NONE;
2729
2730         object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
2731
2732         /* Use the proper number of shots */
2733         thits = p_ptr->num_fire;
2734
2735         /* Use a base distance */
2736         tdis = 10;
2737
2738         /* Base damage from thrown object plus launcher bonus */
2739         tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
2740
2741         /* Actually "fire" the object */
2742         bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
2743         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
2744                 chance = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
2745         else
2746                 chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
2747
2748         p_ptr->energy_use = bow_energy(j_ptr->sval);
2749         tmul = bow_tmul(j_ptr->sval);
2750
2751         /* Get extra "power" from "extra might" */
2752         if (p_ptr->xtra_might) tmul++;
2753
2754         tmul = tmul * (100 + (int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
2755
2756         /* Boost the damage */
2757         tdam_base *= tmul;
2758         tdam_base /= 100;
2759
2760         /* Base range */
2761         tdis = 13 + tmul/80;
2762         if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
2763         {
2764                 if (p_ptr->concent)
2765                         tdis -= (5 - (p_ptr->concent + 1) / 2);
2766                 else
2767                         tdis -= 5;
2768         }
2769
2770         project_length = tdis + 1;
2771
2772         /* Get a direction (or cancel) */
2773         if (!get_aim_dir(&dir))
2774         {
2775                 p_ptr->energy_use = 0;
2776
2777                 if (snipe_type == SP_AWAY) snipe_type = SP_NONE;
2778
2779                 /* need not to reset project_length (already did)*/
2780
2781                 return;
2782         }
2783
2784         /* Predict the "target" location */
2785         tx = p_ptr->x + 99 * ddx[dir];
2786         ty = p_ptr->y + 99 * ddy[dir];
2787
2788         /* Check for "target request" */
2789         if ((dir == 5) && target_okay())
2790         {
2791                 tx = target_col;
2792                 ty = target_row;
2793         }
2794
2795         /* Get projection path length */
2796         tdis = project_path(path_g, project_length, p_ptr->y, p_ptr->x, ty, tx, PROJECT_PATH|PROJECT_THRU) - 1;
2797
2798         project_length = 0; /* reset to default */
2799
2800         /* Don't shoot at my feet */
2801         if (tx == p_ptr->x && ty == p_ptr->y)
2802         {
2803                 p_ptr->energy_use = 0;
2804
2805                 /* project_length is already reset to 0 */
2806
2807                 return;
2808         }
2809
2810
2811         /* Take a (partial) turn */
2812         p_ptr->energy_use = (p_ptr->energy_use / thits);
2813         is_fired = TRUE;
2814
2815         /* Sniper - Difficult to shot twice at 1 turn */
2816         if (snipe_type == SP_DOUBLE)  p_ptr->concent = (p_ptr->concent + 1) / 2;
2817
2818         /* Sniper - Repeat shooting when double shots */
2819         for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++)
2820         {
2821
2822         /* Start at the player */
2823         y = p_ptr->y;
2824         x = p_ptr->x;
2825         q_ptr = &forge;
2826
2827         /* Obtain a local object */
2828         object_copy(q_ptr, o_ptr);
2829
2830         /* Single object */
2831         q_ptr->number = 1;
2832
2833         /* Reduce and describe inventory */
2834         if (item >= 0)
2835         {
2836                 inven_item_increase(item, -1);
2837                 inven_item_describe(item);
2838                 inven_item_optimize(item);
2839         }
2840
2841         /* Reduce and describe floor item */
2842         else
2843         {
2844                 floor_item_increase(0 - item, -1);
2845                 floor_item_optimize(0 - item);
2846         }
2847
2848         sound(SOUND_SHOOT);
2849         handle_stuff();
2850
2851         /* Save the old location */
2852         prev_y = y;
2853         prev_x = x;
2854
2855         /* The shot does not hit yet */
2856         hit_body = FALSE;
2857
2858         /* Travel until stopped */
2859         for (cur_dis = 0; cur_dis <= tdis; )
2860         {
2861                 cave_type *c_ptr;
2862
2863                 /* Hack -- Stop at the target */
2864                 if ((y == ty) && (x == tx)) break;
2865
2866                 /* Calculate the new location (see "project()") */
2867                 ny = y;
2868                 nx = x;
2869                 mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
2870
2871                 /* Shatter Arrow */
2872                 if (snipe_type == SP_KILL_WALL)
2873                 {
2874                         c_ptr = &cave[ny][nx];
2875
2876                         if (cave_have_flag_grid(c_ptr, FF_HURT_ROCK) && !c_ptr->m_idx)
2877                         {
2878                                 if (c_ptr->info & (CAVE_MARK)) msg_print(_("岩が砕け散った。", "Wall rocks were shattered."));
2879                                 /* Forget the wall */
2880                                 c_ptr->info &= ~(CAVE_MARK);
2881
2882                                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
2883
2884                                 /* Destroy the wall */
2885                                 cave_alter_feat(ny, nx, FF_HURT_ROCK);
2886
2887                                 hit_body = TRUE;
2888                                 break;
2889                         }
2890                 }
2891
2892                 /* Stopped by walls/doors */
2893                 if (!cave_have_flag_bold(ny, nx, FF_PROJECT) && !cave[ny][nx].m_idx) break;
2894
2895                 /* Advance the distance */
2896                 cur_dis++;
2897
2898                 /* Sniper */
2899                 if (snipe_type == SP_LITE)
2900                 {
2901                         cave[ny][nx].info |= (CAVE_GLOW);
2902
2903                         note_spot(ny, nx);
2904
2905                         lite_spot(ny, nx);
2906                 }
2907
2908                 /* The player can see the (on screen) missile */
2909                 if (panel_contains(ny, nx) && player_can_see_bold(ny, nx))
2910                 {
2911                         char c = object_char(q_ptr);
2912                         byte a = object_attr(q_ptr);
2913
2914                         /* Draw, Hilite, Fresh, Pause, Erase */
2915                         print_rel(c, a, ny, nx);
2916                         move_cursor_relative(ny, nx);
2917                         Term_fresh();
2918                         Term_xtra(TERM_XTRA_DELAY, msec);
2919                         lite_spot(ny, nx);
2920                         Term_fresh();
2921                 }
2922
2923                 /* The player cannot see the missile */
2924                 else
2925                 {
2926                         /* Pause anyway, for consistancy */
2927                         Term_xtra(TERM_XTRA_DELAY, msec);
2928                 }
2929
2930                 /* Sniper */
2931                 if (snipe_type == SP_KILL_TRAP)
2932                 {
2933                         project(0, 0, ny, nx, 0, GF_KILL_TRAP,
2934                                 (PROJECT_JUMP | PROJECT_HIDE | PROJECT_GRID | PROJECT_ITEM), -1);
2935                 }
2936
2937                 /* Sniper */
2938                 if (snipe_type == SP_EVILNESS)
2939                 {
2940                         cave[ny][nx].info &= ~(CAVE_GLOW | CAVE_MARK);
2941
2942                         note_spot(ny, nx);
2943
2944                         lite_spot(ny, nx);
2945                 }
2946
2947                 /* Save the old location */
2948                 prev_y = y;
2949                 prev_x = x;
2950
2951                 /* Save the new location */
2952                 x = nx;
2953                 y = ny;
2954
2955
2956                 /* Monster here, Try to hit it */
2957                 if (cave[y][x].m_idx)
2958                 {
2959                         cave_type *c_mon_ptr = &cave[y][x];
2960
2961                         monster_type *m_ptr = &m_list[c_mon_ptr->m_idx];
2962                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
2963
2964                         /* Check the visibility */
2965                         visible = m_ptr->ml;
2966
2967                         /* Note the collision */
2968                         hit_body = TRUE;
2969
2970                         if (MON_CSLEEP(m_ptr))
2971                         {
2972                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
2973                                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
2974                         }
2975
2976                         if ((r_ptr->level + 10) > p_ptr->lev)
2977                         {
2978                                 int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
2979                                 if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
2980                                 {
2981                                         SUB_EXP amount = 0;
2982                                         if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
2983                                         else if (now_exp < WEAPON_EXP_SKILLED) amount = 25;
2984                                         else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 10;
2985                                         else if (p_ptr->lev > 34) amount = 2;
2986                                         p_ptr->weapon_exp[0][j_ptr->sval] += amount;
2987                                         p_ptr->update |= (PU_BONUS);
2988                                 }
2989                         }
2990
2991                         if (p_ptr->riding)
2992                         {
2993                                 if ((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING])
2994                                         && ((p_ptr->skill_exp[GINOU_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[m_list[p_ptr->riding].r_idx].level)
2995                                         && one_in_(2))
2996                                 {
2997                                         p_ptr->skill_exp[GINOU_RIDING] += 1;
2998                                         p_ptr->update |= (PU_BONUS);
2999                                 }
3000                         }
3001
3002                         /* Did we hit it (penalize range) */
3003                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3004                         {
3005                                 bool fear = FALSE;
3006                                 int tdam = tdam_base;
3007
3008                                 /* Get extra damage from concentration */
3009                                 if (p_ptr->concent) tdam = boost_concentration_damage(tdam);
3010
3011                                 /* Handle unseen monster */
3012                                 if (!visible)
3013                                 {
3014                                         /* Invisible monster */
3015                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
3016                                 }
3017
3018                                 /* Handle visible monster */
3019                                 else
3020                                 {
3021                                         char m_name[80];
3022
3023                                         /* Get "the monster" or "it" */
3024                                         monster_desc(m_name, m_ptr, 0);
3025
3026                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3027
3028                                         if (m_ptr->ml)
3029                                         {
3030                                                 /* Hack -- Track this monster race */
3031                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3032
3033                                                 /* Hack -- Track this monster */
3034                                                 health_track(c_mon_ptr->m_idx);
3035                                         }
3036                                 }
3037
3038                                 if (snipe_type == SP_NEEDLE)
3039                                 {
3040                                         if ((randint1(randint1(r_ptr->level / (3 + p_ptr->concent)) + (8 - p_ptr->concent)) == 1)
3041                                                 && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
3042                                         {
3043                                                 char m_name[80];
3044
3045                                                 /* Get "the monster" or "it" */
3046                                                 monster_desc(m_name, m_ptr, 0);
3047
3048                                                 tdam = m_ptr->hp + 1;
3049                                                 msg_format(_("%sの急所に突き刺さった!", "Your shot sticked on a fatal spot of %s!"), m_name);
3050                                         }
3051                                         else tdam = 1;
3052                                 }
3053                                 else
3054                                 {
3055                                         /* Apply special damage */
3056                                         tdam = tot_dam_aux_shot(q_ptr, tdam, m_ptr);
3057                                         tdam = critical_shot(q_ptr->weight, q_ptr->to_h, j_ptr->to_h, tdam);
3058
3059                                         /* No negative damage */
3060                                         if (tdam < 0) tdam = 0;
3061
3062                                         /* Modify the damage */
3063                                         tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3064                                 }
3065
3066                                 msg_format_wizard(CHEAT_MONSTER,
3067                                         _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3068                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3069
3070                                 /* Sniper */
3071                                 if (snipe_type == SP_EXPLODE)
3072                                 {
3073                                         u16b flg = (PROJECT_STOP | PROJECT_JUMP | PROJECT_KILL | PROJECT_GRID);
3074
3075                                         sound(SOUND_EXPLODE); /* No explode sound - use breath fire instead */
3076                                         project(0, ((p_ptr->concent + 1) / 2 + 1), ny, nx, tdam, GF_MISSILE, flg, -1);
3077                                         break;
3078                                 }
3079
3080                                 /* Sniper */
3081                                 if (snipe_type == SP_HOLYNESS)
3082                                 {
3083                                         cave[ny][nx].info |= (CAVE_GLOW);
3084
3085                                         note_spot(ny, nx);
3086
3087                                         lite_spot(ny, nx);
3088                                 }
3089
3090                                 /* Hit the monster, check for death */
3091                                 if (mon_take_hit(c_mon_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3092                                 {
3093                                         /* Dead monster */
3094                                 }
3095
3096                                 /* No death */
3097                                 else
3098                                 {
3099                                         /* STICK TO */
3100                                         if (object_is_fixed_artifact(q_ptr) &&
3101                                                 (p_ptr->pclass != CLASS_SNIPER || p_ptr->concent == 0))
3102                                         {
3103                                                 char m_name[80];
3104
3105                                                 monster_desc(m_name, m_ptr, 0);
3106
3107                                                 stick_to = TRUE;
3108                                                 msg_format(_("%sは%sに突き刺さった!", "%^s have stuck into %s!"),o_name, m_name);
3109                                         }
3110
3111                                         message_pain(c_mon_ptr->m_idx, tdam);
3112
3113                                         /* Anger the monster */
3114                                         if (tdam > 0) anger_monster(m_ptr);
3115
3116                                         /* Take note */
3117                                         if (fear && m_ptr->ml)
3118                                         {
3119                                                 char m_name[80];
3120
3121                                                 sound(SOUND_FLEE);
3122
3123                                                 /* Get the monster name (or "it") */
3124                                                 monster_desc(m_name, m_ptr, 0);
3125
3126                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3127                                         }
3128
3129                                         set_target(m_ptr, p_ptr->y, p_ptr->x);
3130
3131                                         /* Sniper */
3132                                         if (snipe_type == SP_RUSH)
3133                                         {
3134                                                 int n = randint1(5) + 3;
3135                                                 MONSTER_IDX m_idx = c_mon_ptr->m_idx;
3136
3137                                                 for ( ; cur_dis <= tdis; )
3138                                                 {
3139                                                         POSITION ox = nx;
3140                                                         POSITION oy = ny;
3141
3142                                                         if (!n) break;
3143
3144                                                         /* Calculate the new location (see "project()") */
3145                                                         mmove2(&ny, &nx, p_ptr->y, p_ptr->x, ty, tx);
3146
3147                                                         /* Stopped by wilderness boundary */
3148                                                         if (!in_bounds2(ny, nx)) break;
3149
3150                                                         /* Stopped by walls/doors */
3151                                                         if (!player_can_enter(cave[ny][nx].feat, 0)) break;
3152
3153                                                         /* Stopped by monsters */
3154                                                         if (!cave_empty_bold(ny, nx)) break;
3155
3156                                                         cave[ny][nx].m_idx = m_idx;
3157                                                         cave[oy][ox].m_idx = 0;
3158
3159                                                         m_ptr->fx = nx;
3160                                                         m_ptr->fy = ny;
3161
3162                                                         /* Update the monster (new location) */
3163                                                         update_monster(c_mon_ptr->m_idx, TRUE);
3164
3165                                                         lite_spot(ny, nx);
3166                                                         lite_spot(oy, ox);
3167
3168                                                         Term_fresh();
3169                                                         Term_xtra(TERM_XTRA_DELAY, msec);
3170
3171                                                         x = nx;
3172                                                         y = ny;
3173                                                         cur_dis++;
3174                                                         n--;
3175                                                 }
3176                                         }
3177                                 }
3178                         }
3179
3180                         /* Sniper */
3181                         if (snipe_type == SP_PIERCE)
3182                         {
3183                                 if(p_ptr->concent < 1) break;
3184                                 p_ptr->concent--;
3185                                 continue;
3186                         }
3187
3188                         /* Stop looking */
3189                         break;
3190                 }
3191         }
3192
3193         /* Chance of breakage (during attacks) */
3194         j = (hit_body ? breakage_chance(q_ptr) : 0);
3195
3196         if (stick_to)
3197         {
3198                 MONSTER_IDX m_idx = cave[y][x].m_idx;
3199                 monster_type *m_ptr = &m_list[m_idx];
3200                 OBJECT_IDX o_idx = o_pop();
3201
3202                 if (!o_idx)
3203                 {
3204                         msg_format(_("%sはどこかへ行った。", "The %s have gone to somewhere."), o_name);
3205                         if (object_is_fixed_artifact(q_ptr))
3206                         {
3207                                 a_info[j_ptr->name1].cur_num = 0;
3208                         }
3209                         return;
3210                 }
3211
3212                 o_ptr = &o_list[o_idx];
3213                 object_copy(o_ptr, q_ptr);
3214
3215                 /* Forget mark */
3216                 o_ptr->marked &= OM_TOUCHED;
3217
3218                 /* Forget location */
3219                 o_ptr->iy = o_ptr->ix = 0;
3220
3221                 /* Memorize monster */
3222                 o_ptr->held_m_idx = m_idx;
3223
3224                 /* Build a stack */
3225                 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3226
3227                 /* Carry object */
3228                 m_ptr->hold_o_idx = o_idx;
3229         }
3230         else if (cave_have_flag_bold(y, x, FF_PROJECT))
3231         {
3232                 /* Drop (or break) near that location */
3233                 (void)drop_near(q_ptr, j, y, x);
3234         }
3235         else
3236         {
3237                 /* Drop (or break) near that location */
3238                 (void)drop_near(q_ptr, j, prev_y, prev_x);
3239         }
3240
3241         /* Sniper - Repeat shooting when double shots */
3242         }
3243
3244         /* Sniper - Loose his/her concentration after any shot */
3245         if (p_ptr->concent) reset_concentration(FALSE);
3246 }
3247
3248 /*!
3249  * @brief 射撃処理のメインルーチン
3250  * @return なし
3251  */
3252 void do_cmd_fire(void)
3253 {
3254         OBJECT_IDX item;
3255         object_type *j_ptr;
3256         cptr q, s;
3257
3258         is_fired = FALSE;       /* not fired yet */
3259
3260         /* Get the "bow" (if any) */
3261         j_ptr = &inventory[INVEN_BOW];
3262
3263         /* Require a launcher */
3264         if (!j_ptr->tval)
3265         {
3266                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
3267                 flush();
3268                 return;
3269         }
3270
3271         if (j_ptr->sval == SV_CRIMSON)
3272         {
3273                 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
3274                 flush();
3275                 return;
3276         }
3277
3278         if (j_ptr->sval == SV_HARP)
3279         {
3280                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
3281                 flush();
3282                 return;
3283         }
3284
3285
3286         if (p_ptr->special_defense & KATA_MUSOU)
3287         {
3288                 set_action(ACTION_NONE);
3289         }
3290
3291         /* Require proper missile */
3292         item_tester_tval = p_ptr->tval_ammo;
3293
3294         q = _("どれを撃ちますか? ", "Fire which item? ");
3295         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
3296         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
3297         {
3298                 flush();
3299                 return;
3300         }
3301
3302         /* Fire the item */
3303         do_cmd_fire_aux(item, j_ptr);
3304
3305         if (!is_fired || p_ptr->pclass != CLASS_SNIPER) return;
3306
3307         /* Sniper actions after some shootings */
3308         if (snipe_type == SP_AWAY)
3309         {
3310                 teleport_player(10 + (p_ptr->concent * 2), 0L);
3311         }
3312         if (snipe_type == SP_FINAL)
3313         {
3314                 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
3315                 (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
3316                 (void)set_stun(p_ptr->stun + randint1(25));
3317         }
3318 }
3319
3320
3321 /*!
3322  * @brief 投射処理メインルーチン /
3323  * Throw an object from the pack or floor.
3324  * @param mult 威力の倍率
3325  * @param boomerang ブーメラン処理ならばTRUE
3326  * @param shuriken 忍者の手裏剣処理ならばTRUE
3327  * @return ターンを消費した場合TRUEを返す
3328  * @details
3329  * <pre>
3330  * Note: "unseen" monsters are very hard to hit.
3331  *
3332  * Should throwing a weapon do full damage?  Should it allow the magic
3333  * to hit bonus of the weapon to have an effect?  Should it ever cause
3334  * the item to be destroyed?  Should it do any damage at all?
3335  * </pre>
3336  */
3337 bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
3338 {
3339         DIRECTION dir;
3340         OBJECT_IDX item;
3341         int i;
3342         POSITION y, x, ty, tx, prev_y, prev_x;
3343         POSITION ny[19], nx[19];
3344         int chance, tdam, tdis;
3345         int mul, div, dd, ds;
3346         int cur_dis, visible;
3347         PERCENTAGE j;
3348
3349         object_type forge;
3350         object_type *q_ptr;
3351
3352         object_type *o_ptr;
3353
3354         bool hit_body = FALSE;
3355         bool hit_wall = FALSE;
3356         bool equiped_item = FALSE;
3357         bool return_when_thrown = FALSE;
3358
3359         char o_name[MAX_NLEN];
3360
3361         int msec = delay_factor * delay_factor * delay_factor;
3362
3363         BIT_FLAGS flgs[TR_FLAG_SIZE];
3364         cptr q, s;
3365         bool come_back = FALSE;
3366         bool do_drop = TRUE;
3367
3368
3369         if (p_ptr->special_defense & KATA_MUSOU)
3370         {
3371                 set_action(ACTION_NONE);
3372         }
3373
3374         if (shuriken >= 0)
3375         {
3376                 item = shuriken;
3377         }
3378         else if (boomerang)
3379         {
3380                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
3381                 {
3382                         item_tester_hook = item_tester_hook_boomerang;
3383                         q = _("どの武器を投げますか? ", "Throw which item? ");
3384                         s = _("投げる武器がない。", "You have nothing to throw.");
3385                         if (!get_item(&item, q, s, (USE_EQUIP)))
3386                         {
3387                                 flush();
3388                                 return FALSE;
3389                         }
3390                 }
3391                 else if (buki_motteruka(INVEN_LARM)) item = INVEN_LARM;
3392                 else item = INVEN_RARM;
3393         }
3394         else
3395         {
3396                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
3397                 s = _("投げるアイテムがない。", "You have nothing to throw.");
3398                 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP)))
3399                 {
3400                         flush();
3401                         return FALSE;
3402                 }
3403         }
3404
3405         /* Access the item (if in the pack) */
3406         if (item >= 0)
3407         {
3408                 o_ptr = &inventory[item];
3409         }
3410         else
3411         {
3412                 o_ptr = &o_list[0 - item];
3413         }
3414
3415         /* Item is cursed */
3416         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
3417         {
3418                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
3419
3420                 return FALSE;
3421         }
3422
3423         if (p_ptr->inside_arena && !boomerang)
3424         {
3425                 if (o_ptr->tval != TV_SPIKE)
3426                 {
3427                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
3428                         msg_print(NULL);
3429
3430                         return FALSE;
3431                 }
3432
3433         }
3434         q_ptr = &forge;
3435
3436         /* Obtain a local object */
3437         object_copy(q_ptr, o_ptr);
3438
3439         /* Extract the thrown object's flags. */
3440         object_flags(q_ptr, flgs);
3441         torch_flags(q_ptr, flgs);
3442
3443         /* Distribute the charges of rods/wands between the stacks */
3444         distribute_charges(o_ptr, q_ptr, 1);
3445
3446         /* Single object */
3447         q_ptr->number = 1;
3448
3449         /* Description */
3450         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
3451
3452         if (p_ptr->mighty_throw) mult += 3;
3453
3454         /* Extract a "distance multiplier" */
3455         /* Changed for 'launcher' mutation */
3456         mul = 10 + 2 * (mult - 1);
3457
3458         /* Enforce a minimum "weight" of one pound */
3459         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
3460         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
3461
3462         /* Hack -- Distance -- Reward strength, penalize weight */
3463         tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
3464
3465         /* Max distance of 10-18 */
3466         if (tdis > mul) tdis = mul;
3467
3468         if (shuriken >= 0)
3469         {
3470                 ty = randint0(101) - 50 + p_ptr->y;
3471                 tx = randint0(101) - 50 + p_ptr->x;
3472         }
3473         else
3474         {
3475                 project_length = tdis + 1;
3476
3477                 /* Get a direction (or cancel) */
3478                 if (!get_aim_dir(&dir)) return FALSE;
3479
3480                 /* Predict the "target" location */
3481                 tx = p_ptr->x + 99 * ddx[dir];
3482                 ty = p_ptr->y + 99 * ddy[dir];
3483
3484                 /* Check for "target request" */
3485                 if ((dir == 5) && target_okay())
3486                 {
3487                         tx = target_col;
3488                         ty = target_row;
3489                 }
3490
3491                 project_length = 0;  /* reset to default */
3492         }
3493
3494         if ((q_ptr->name1 == ART_MJOLLNIR) ||
3495             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
3496                 return_when_thrown = TRUE;
3497
3498         /* Reduce and describe inventory */
3499         if (item >= 0)
3500         {
3501                 inven_item_increase(item, -1);
3502                 if (!return_when_thrown)
3503                         inven_item_describe(item);
3504                 inven_item_optimize(item);
3505         }
3506
3507         /* Reduce and describe floor item */
3508         else
3509         {
3510                 floor_item_increase(0 - item, -1);
3511                 floor_item_optimize(0 - item);
3512         }
3513         if (item >= INVEN_RARM)
3514         {
3515                 equiped_item = TRUE;
3516                 p_ptr->redraw |= (PR_EQUIPPY);
3517         }
3518
3519         p_ptr->energy_use = 100;
3520
3521         /* Rogue and Ninja gets bonus */
3522         if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
3523                 p_ptr->energy_use -= p_ptr->lev;
3524
3525         /* Start at the player */
3526         y = p_ptr->y;
3527         x = p_ptr->x;
3528
3529         handle_stuff();
3530
3531         if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
3532         else shuriken = FALSE;
3533
3534         /* Chance of hitting */
3535         if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
3536                 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
3537         else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
3538
3539         if (shuriken) chance *= 2;
3540
3541         /* Save the old location */
3542         prev_y = y;
3543         prev_x = x;
3544
3545         /* Travel until stopped */
3546         for (cur_dis = 0; cur_dis <= tdis; )
3547         {
3548                 /* Hack -- Stop at the target */
3549                 if ((y == ty) && (x == tx)) break;
3550
3551                 /* Calculate the new location (see "project()") */
3552                 ny[cur_dis] = y;
3553                 nx[cur_dis] = x;
3554                 mmove2(&ny[cur_dis], &nx[cur_dis], p_ptr->y, p_ptr->x, ty, tx);
3555
3556                 /* Stopped by walls/doors */
3557                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
3558                 {
3559                         hit_wall = TRUE;
3560                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !cave[ny[cur_dis]][nx[cur_dis]].m_idx) break;
3561                 }
3562
3563                 /* The player can see the (on screen) missile */
3564                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
3565                 {
3566                         char c = object_char(q_ptr);
3567                         byte a = object_attr(q_ptr);
3568
3569                         /* Draw, Hilite, Fresh, Pause, Erase */
3570                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
3571                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
3572                         Term_fresh();
3573                         Term_xtra(TERM_XTRA_DELAY, msec);
3574                         lite_spot(ny[cur_dis], nx[cur_dis]);
3575                         Term_fresh();
3576                 }
3577
3578                 /* The player cannot see the missile */
3579                 else
3580                 {
3581                         /* Pause anyway, for consistancy */
3582                         Term_xtra(TERM_XTRA_DELAY, msec);
3583                 }
3584
3585                 /* Save the old location */
3586                 prev_y = y;
3587                 prev_x = x;
3588
3589                 /* Save the new location */
3590                 x = nx[cur_dis];
3591                 y = ny[cur_dis];
3592
3593                 /* Advance the distance */
3594                 cur_dis++;
3595
3596                 /* Monster here, Try to hit it */
3597                 if (cave[y][x].m_idx)
3598                 {
3599                         cave_type *c_ptr = &cave[y][x];
3600                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3601
3602                         /* Check the visibility */
3603                         visible = m_ptr->ml;
3604
3605                         /* Note the collision */
3606                         hit_body = TRUE;
3607
3608                         /* Did we hit it (penalize range) */
3609                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
3610                         {
3611                                 bool fear = FALSE;
3612
3613                                 /* Handle unseen monster */
3614                                 if (!visible)
3615                                 {
3616                                         /* Invisible monster */
3617                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
3618                                 }
3619
3620                                 /* Handle visible monster */
3621                                 else
3622                                 {
3623                                         char m_name[80];
3624
3625                                         /* Get "the monster" or "it" */
3626                                         monster_desc(m_name, m_ptr, 0);
3627
3628                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
3629
3630                                         if (m_ptr->ml)
3631                                         {
3632                                                 /* Hack -- Track this monster race */
3633                                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3634
3635                                                 /* Hack -- Track this monster */
3636                                                 health_track(c_ptr->m_idx);
3637                                         }
3638                                 }
3639
3640                                 /* Hack -- Base damage from thrown object */
3641                                 dd = q_ptr->dd;
3642                                 ds = q_ptr->ds;
3643                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
3644                                 tdam = damroll(dd, ds);
3645                                 /* Apply special damage */
3646                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
3647                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
3648                                 if (q_ptr->to_d > 0)
3649                                         tdam += q_ptr->to_d;
3650                                 else
3651                                         tdam += -q_ptr->to_d;
3652
3653                                 if (boomerang)
3654                                 {
3655                                         tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
3656                                         tdam += p_ptr->to_d_m;
3657                                 }
3658                                 else if (have_flag(flgs, TR_THROW))
3659                                 {
3660                                         tdam *= (3+mult);
3661                                         tdam += p_ptr->to_d_m;
3662                                 }
3663                                 else
3664                                 {
3665                                         tdam *= mult;
3666                                 }
3667                                 if (shuriken)
3668                                 {
3669                                         tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
3670                                 }
3671
3672                                 /* No negative damage */
3673                                 if (tdam < 0) tdam = 0;
3674
3675                                 /* Modify the damage */
3676                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
3677
3678                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
3679                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
3680
3681                                 /* Hit the monster, check for death */
3682                                 if (mon_take_hit(c_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_ptr(m_ptr))))
3683                                 {
3684                                         /* Dead monster */
3685                                 }
3686
3687                                 /* No death */
3688                                 else
3689                                 {
3690                                         message_pain(c_ptr->m_idx, tdam);
3691
3692                                         /* Anger the monster */
3693                                         if ((tdam > 0) && !object_is_potion(q_ptr))
3694                                                 anger_monster(m_ptr);
3695
3696                                         /* Take note */
3697                                         if (fear && m_ptr->ml)
3698                                         {
3699                                                 char m_name[80];
3700
3701                                                 sound(SOUND_FLEE);
3702
3703                                                 /* Get the monster name (or "it") */
3704                                                 monster_desc(m_name, m_ptr, 0);
3705
3706                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
3707                                         }
3708                                 }
3709                         }
3710
3711                         /* Stop looking */
3712                         break;
3713                 }
3714         }
3715
3716         /* decrease toach's fuel */
3717         if (hit_body) torch_lost_fuel(q_ptr);
3718
3719         /* Chance of breakage (during attacks) */
3720         j = (hit_body ? breakage_chance(q_ptr) : 0);
3721
3722         /* Figurines transform */
3723         if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
3724         {
3725                 j = 100;
3726
3727                 if (!(summon_named_creature(0, y, x, q_ptr->pval,
3728                                             !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
3729                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
3730                 else if (object_is_cursed(q_ptr))
3731                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
3732
3733         }
3734
3735
3736         /* Potions smash open */
3737         if (object_is_potion(q_ptr))
3738         {
3739                 if (hit_body || hit_wall || (randint1(100) < j))
3740                 {
3741                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
3742
3743                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
3744                         {
3745                                 monster_type *m_ptr = &m_list[cave[y][x].m_idx];
3746
3747                                 /* ToDo (Robert): fix the invulnerability */
3748                                 if (cave[y][x].m_idx &&
3749                                     is_friendly(&m_list[cave[y][x].m_idx]) &&
3750                                     !MON_INVULNER(m_ptr))
3751                                 {
3752                                         char m_name[80];
3753                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
3754                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
3755                                         set_hostile(&m_list[cave[y][x].m_idx]);
3756                                 }
3757                         }
3758                         do_drop = FALSE;
3759                 }
3760                 else
3761                 {
3762                         j = 0;
3763                 }
3764         }
3765
3766         if (return_when_thrown)
3767         {
3768                 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
3769                 char o2_name[MAX_NLEN];
3770                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
3771
3772                 j = -1;
3773                 if (boomerang) back_chance += 4+randint1(5);
3774                 if (super_boomerang) back_chance += 100;
3775                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3776
3777                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
3778                 {
3779                         for (i = cur_dis - 1; i > 0; i--)
3780                         {
3781                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
3782                                 {
3783                                         char c = object_char(q_ptr);
3784                                         byte a = object_attr(q_ptr);
3785
3786                                         /* Draw, Hilite, Fresh, Pause, Erase */
3787                                         print_rel(c, a, ny[i], nx[i]);
3788                                         move_cursor_relative(ny[i], nx[i]);
3789                                         Term_fresh();
3790                                         Term_xtra(TERM_XTRA_DELAY, msec);
3791                                         lite_spot(ny[i], nx[i]);
3792                                         Term_fresh();
3793                                 }
3794                                 else
3795                                 {
3796                                         /* Pause anyway, for consistancy */
3797                                         Term_xtra(TERM_XTRA_DELAY, msec);
3798                                 }
3799                         }
3800                         if((back_chance > 37) && !p_ptr->blind && (item >= 0))
3801                         {
3802                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
3803                                 come_back = TRUE;
3804                         }
3805                         else
3806                         {
3807                                 if (item >= 0)
3808                                 {
3809                                         msg_format(_("%sを受け損ねた!", "%s backs, but you can't catch!"), o2_name);
3810                                 }
3811                                 else
3812                                 {
3813                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
3814                                 }
3815                                 y = p_ptr->y;
3816                                 x = p_ptr->x;
3817                         }
3818                 }
3819                 else
3820                 {
3821                         msg_format(_("%sが返ってこなかった!", "%s doesn't back!"), o2_name);
3822                 }
3823         }
3824
3825         if (come_back)
3826         {
3827                 if (item == INVEN_RARM || item == INVEN_LARM)
3828                 {
3829                         /* Access the wield slot */
3830                         o_ptr = &inventory[item];
3831
3832                         /* Wear the new stuff */
3833                         object_copy(o_ptr, q_ptr);
3834
3835                         /* Increase the weight */
3836                         p_ptr->total_weight += q_ptr->weight;
3837
3838                         /* Increment the equip counter by hand */
3839                         equip_cnt++;
3840
3841                         /* Recalculate bonuses */
3842                         p_ptr->update |= (PU_BONUS);
3843
3844                         /* Recalculate torch */
3845                         p_ptr->update |= (PU_TORCH);
3846
3847                         /* Recalculate mana XXX */
3848                         p_ptr->update |= (PU_MANA);
3849
3850                         p_ptr->window |= (PW_EQUIP);
3851                 }
3852                 else
3853                 {
3854                         inven_carry(q_ptr);
3855                 }
3856                 do_drop = FALSE;
3857         }
3858         else if (equiped_item)
3859         {
3860                 kamaenaoshi(item);
3861                 calc_android_exp();
3862         }
3863
3864         /* Drop (or break) near that location */
3865         if (do_drop)
3866         {
3867                 if (cave_have_flag_bold(y, x, FF_PROJECT))
3868                 {
3869                         /* Drop (or break) near that location */
3870                         (void)drop_near(q_ptr, j, y, x);
3871                 }
3872                 else
3873                 {
3874                         /* Drop (or break) near that location */
3875                         (void)drop_near(q_ptr, j, prev_y, prev_x);
3876                 }
3877         }
3878
3879         return TRUE;
3880 }
3881
3882
3883 #ifdef TRAVEL
3884 /*
3885  * Hack: travel command
3886  */
3887 #define TRAVEL_UNABLE 9999
3888
3889 static int flow_head = 0;
3890 static int flow_tail = 0;
3891 static POSITION temp2_x[MAX_SHORT];
3892 static POSITION temp2_y[MAX_SHORT];
3893
3894 /*!
3895  * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information 
3896  * @return なし
3897  */
3898 void forget_travel_flow(void)
3899 {
3900         POSITION x, y;
3901
3902         /* Check the entire dungeon */
3903         for (y = 0; y < cur_hgt; y++)
3904         {
3905                 for (x = 0; x < cur_wid; x++)
3906                 {
3907                         /* Forget the old data */
3908                         travel.cost[y][x] = MAX_SHORT;
3909                 }
3910         }
3911
3912         travel.y = travel.x = 0;
3913 }
3914
3915 /*!
3916  * @brief トラベル処理中に地形に応じた移動コスト基準を返す
3917  * @param y 該当地点のY座標
3918  * @param x 該当地点のX座標
3919  * @return コスト値
3920  */
3921 static int travel_flow_cost(POSITION y, POSITION x)
3922 {
3923         feature_type *f_ptr = &f_info[cave[y][x].feat];
3924         int cost = 1;
3925
3926         /* Avoid obstacles (ex. trees) */
3927         if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
3928
3929         /* Water */
3930         if (have_flag(f_ptr->flags, FF_WATER))
3931         {
3932                 if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
3933         }
3934
3935         /* Lava */
3936         if (have_flag(f_ptr->flags, FF_LAVA))
3937         {
3938                 int lava = 2;
3939                 if (!p_ptr->resist_fire) lava *= 2;
3940                 if (!p_ptr->levitation) lava *= 2;
3941                 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
3942
3943                 cost += lava;
3944         }
3945
3946         /* Detected traps and doors */
3947         if (cave[y][x].info & (CAVE_MARK))
3948         {
3949                 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
3950                 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
3951         }
3952
3953         return (cost);
3954 }
3955
3956 /*!
3957  * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
3958  * @param y 目標地点のY座標
3959  * @param x 目標地点のX座標
3960  * @param n 現在のコスト
3961  * @param wall プレイヤーが壁の中にいるならばTRUE
3962  * @return なし
3963  */
3964 static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
3965 {
3966         cave_type *c_ptr = &cave[y][x];
3967         feature_type *f_ptr = &f_info[c_ptr->feat];
3968         int old_head = flow_head;
3969         int add_cost = 1;
3970         int base_cost = (n % TRAVEL_UNABLE);
3971         int from_wall = (n / TRAVEL_UNABLE);
3972         int cost;
3973
3974         /* Ignore out of bounds */
3975         if (!in_bounds(y, x)) return;
3976
3977         /* Ignore unknown grid except in wilderness */
3978         if (dun_level > 0 && !(c_ptr->info & CAVE_KNOWN)) return;
3979
3980         /* Ignore "walls" and "rubble" (include "secret doors") */
3981         if (have_flag(f_ptr->flags, FF_WALL) ||
3982                 have_flag(f_ptr->flags, FF_CAN_DIG) ||
3983                 (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic) ||
3984                 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
3985         {
3986                 if (!wall || !from_wall) return;
3987                 add_cost += TRAVEL_UNABLE;
3988         }
3989         else
3990         {
3991                 add_cost = travel_flow_cost(y, x);
3992         }
3993
3994         cost = base_cost + add_cost;
3995
3996         /* Ignore lower cost entries */
3997         if (travel.cost[y][x] <= cost) return;
3998
3999         /* Save the flow cost */
4000         travel.cost[y][x] = cost;
4001
4002         /* Enqueue that entry */
4003         temp2_y[flow_head] = y;
4004         temp2_x[flow_head] = x;
4005
4006         /* Advance the queue */
4007         if (++flow_head == MAX_SHORT) flow_head = 0;
4008
4009         /* Hack -- notice overflow by forgetting new entry */
4010         if (flow_head == flow_tail) flow_head = old_head;
4011
4012         return;
4013 }
4014
4015 /*!
4016  * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
4017  * @param ty 目標地点のY座標
4018  * @param tx 目標地点のX座標
4019  * @return なし
4020  */
4021 static void travel_flow(POSITION ty, POSITION tx)
4022 {
4023         POSITION x, y, d;
4024         bool wall = FALSE;
4025         feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
4026
4027         /* Reset the "queue" */
4028         flow_head = flow_tail = 0;
4029
4030         /* is player in the wall? */
4031         if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
4032
4033         /* Start at the target grid */
4034         travel_flow_aux(ty, tx, 0, wall);
4035
4036         /* Now process the queue */
4037         while (flow_head != flow_tail)
4038         {
4039                 /* Extract the next entry */
4040                 y = temp2_y[flow_tail];
4041                 x = temp2_x[flow_tail];
4042
4043                 /* Forget that entry */
4044                 if (++flow_tail == MAX_SHORT) flow_tail = 0;
4045
4046                 /* Ignore too far entries */
4047                 //if (distance(ty, tx, y, x) > 100) continue;
4048
4049                 /* Add the "children" */
4050                 for (d = 0; d < 8; d++)
4051                 {
4052                         /* Add that child if "legal" */
4053                         travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
4054                 }
4055         }
4056
4057         /* Forget the flow info */
4058         flow_head = flow_tail = 0;
4059 }
4060
4061 /*!
4062  * @brief トラベル処理のメインルーチン
4063  * @return なし
4064  */
4065 void do_cmd_travel(void)
4066 {
4067         POSITION x, y;
4068         int i;
4069         int dx, dy, sx, sy;
4070         feature_type *f_ptr;
4071
4072         if (travel.x != 0 && travel.y != 0 &&
4073             get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
4074         {
4075                 y = travel.y;
4076                 x = travel.x;
4077         }
4078         else if (!tgt_pt(&x, &y)) return;
4079
4080         if ((x == p_ptr->x) && (y == p_ptr->y))
4081         {
4082                 msg_print(_("すでにそこにいます!", "You are already there!!"));
4083                 return;
4084         }
4085
4086         f_ptr = &f_info[cave[y][x].feat];
4087
4088         if ((cave[y][x].info & CAVE_MARK) &&
4089                 (have_flag(f_ptr->flags, FF_WALL) ||
4090                         have_flag(f_ptr->flags, FF_CAN_DIG) ||
4091                         (have_flag(f_ptr->flags, FF_DOOR) && cave[y][x].mimic)))
4092         {
4093                 msg_print(_("そこには行くことができません!", "You cannot travel there!"));
4094                 return;
4095         }
4096
4097         forget_travel_flow();
4098         travel_flow(y, x);
4099
4100         travel.x = x;
4101         travel.y = y;
4102
4103         /* Travel till 255 steps */
4104         travel.run = 255;
4105
4106         /* Paranoia */
4107         travel.dir = 0;
4108
4109         /* Decides first direction */
4110         dx = abs(p_ptr->x - x);
4111         dy = abs(p_ptr->y - y);
4112         sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
4113         sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
4114
4115         for (i = 1; i <= 9; i++)
4116         {
4117                 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
4118         }
4119 }
4120 #endif