OSDN Git Service

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