OSDN Git Service

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