OSDN Git Service

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