OSDN Git Service

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