OSDN Git Service

[Refactor] #39076 冗長なコメントを削除. (/* hex */)
[hengband/hengband.git] / src / cmd-basic.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 "util.h"
15 #include "core.h"
16 #include "term.h"
17
18 #include "cmd-dump.h"
19 #include "chest.h"
20 #include "trap.h"
21 #include "dungeon.h"
22 #include "feature.h"
23 #include "floor.h"
24 #include "melee.h"
25 #include "object-hook.h"
26 #include "spells.h"
27 #include "spells-summon.h"
28 #include "spells-status.h"
29 #include "monster.h"
30 #include "monster-status.h"
31 #include "quest.h"
32 #include "artifact.h"
33 #include "avatar.h"
34 #include "player-status.h"
35 #include "realm-hex.h"
36 #include "realm-song.h"
37 #include "geometry.h"
38 #include "wild.h"
39 #include "grid.h"
40 #include "feature.h"
41 #include "player-move.h"
42 #include "player-effects.h"
43 #include "player-class.h"
44 #include "player-personality.h"
45 #include "objectkind.h"
46 #include "object-broken.h"
47 #include "object-flavor.h"
48 #include "shoot.h"
49 #include "snipe.h"
50
51 #include "cmd-basic.h"
52 #include "cmd-item.h"
53 #include "floor-save.h"
54 #include "dungeon-file.h"
55 #include "files.h"
56
57 #include "view-mainwindow.h"
58 #include "targeting.h"
59
60 /*!
61  * @brief フロア脱出時に出戻りが不可能だった場合に警告を加える処理
62  * @param down_stair TRUEならば階段を降りる処理、FALSEなら階段を昇る処理による内容
63  * @return フロア移動を実際に行うならTRUE、キャンセルする場合はFALSE
64  */
65 static bool confirm_leave_level(player_type *creature_ptr, bool down_stair)
66 {
67         quest_type *q_ptr = &quest[creature_ptr->inside_quest];
68
69         /* Confirm leaving from once only quest */
70         if (confirm_quest && creature_ptr->inside_quest &&
71             (q_ptr->type == QUEST_TYPE_RANDOM ||
72              (q_ptr->flags & QUEST_FLAG_ONCE &&
73                                                 q_ptr->status != QUEST_STATUS_COMPLETED) ||
74                  (q_ptr->flags & QUEST_FLAG_TOWER &&
75                                                 ((q_ptr->status != QUEST_STATUS_STAGE_COMPLETED) ||
76                                                  (down_stair && (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))))))
77         {
78                 msg_print(_("この階を一度去ると二度と戻って来られません。", "You can't come back here once you leave this floor."));
79                 if (get_check(_("本当にこの階を去りますか?", "Really leave this floor? "))) return TRUE;
80         }
81         else
82         {
83                 return TRUE;
84         }
85         return FALSE;
86 }
87
88 /*!
89  * @brief 魔法系コマンドが制限されているかを返す。
90  * @return 魔法系コマンドを使用可能ならFALSE、不可能ならば理由をメッセージ表示してTRUEを返す。
91  */
92 bool cmd_limit_cast(player_type *creature_ptr)
93 {
94         if (current_floor_ptr->dun_level && (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
95         {
96                 msg_print(_("ダンジョンが魔法を吸収した!", "The dungeon absorbs all attempted magic!"));
97                 msg_print(NULL);
98                 return TRUE;
99         }
100         else if (creature_ptr->anti_magic)
101         {
102                 msg_print(_("反魔法バリアが魔法を邪魔した!", "An anti-magic shell disrupts your magic!"));
103                 return TRUE;
104         }
105         else if (creature_ptr->shero)
106         {
107                 msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
108                 return TRUE;
109         }
110         else
111                 return FALSE;
112 }
113
114 bool cmd_limit_confused(player_type *creature_ptr)
115 {
116         if (creature_ptr->confused)
117         {
118                 msg_print(_("混乱していてできない!", "You are too confused!"));
119                 return TRUE;
120         }
121         return FALSE;
122 }
123
124 bool cmd_limit_image(player_type *creature_ptr)
125 {
126         if (creature_ptr->image)
127         {
128                 msg_print(_("幻覚が見えて集中できない!", "You are too hallucinated!"));
129                 return TRUE;
130         }
131         return FALSE;
132 }
133
134 bool cmd_limit_stun(player_type *creature_ptr)
135 {
136         if (creature_ptr->stun)
137         {
138                 msg_print(_("頭が朦朧としていて集中できない!", "You are too stuned!"));
139                 return TRUE;
140         }
141         return FALSE;
142 }
143
144 bool cmd_limit_arena(player_type *creature_ptr)
145 {
146         if (creature_ptr->inside_arena)
147         {
148                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
149                 msg_print(NULL);
150                 return TRUE;
151         }
152         return FALSE;
153 }
154
155 bool cmd_limit_blind(player_type *creature_ptr)
156 {
157         if (creature_ptr->blind)
158         {
159                 msg_print(_("目が見えない。", "You can't see anything."));
160                 return TRUE;
161         }
162         if (no_lite())
163         {
164                 msg_print(_("明かりがないので見えない。", "You have no light."));
165                 return TRUE;
166         }
167         return FALSE;
168 }
169
170 bool cmd_limit_time_walk(player_type *creature_ptr)
171 {
172         if (creature_ptr->timewalk)
173         {
174                 if (flush_failure) flush();
175                 msg_print(_("止まった時の中ではうまく働かないようだ。", "It shows no reaction."));
176                 sound(SOUND_FAIL);
177                 return TRUE;
178         }
179         return FALSE;
180 }
181
182 /*!
183  * @brief 階段を使って階層を昇る処理 / Go up one level
184  * @return なし
185  */
186 void do_cmd_go_up(player_type *creature_ptr)
187 {
188         bool go_up = FALSE;
189
190         /* Player grid */
191         grid_type *g_ptr = &current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
192         feature_type *f_ptr = &f_info[g_ptr->feat];
193
194         int up_num = 0;
195
196         if (creature_ptr->special_defense & KATA_MUSOU)
197         {
198                 set_action(creature_ptr, ACTION_NONE);
199         }
200
201         /* Verify stairs */
202         if (!have_flag(f_ptr->flags, FF_LESS))
203         {
204                 msg_print(_("ここには上り階段が見当たらない。", "I see no up staircase here."));
205                 return;
206         }
207
208         /* Quest up stairs */
209         if (have_flag(f_ptr->flags, FF_QUEST))
210         {
211                 if (!confirm_leave_level(creature_ptr, FALSE)) return;
212         
213                 /* Success */
214                 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
215                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
216                 else
217                         msg_print(_("上の階に登った。", "You enter the up staircase."));
218
219                 leave_quest_check();
220
221                 creature_ptr->inside_quest = g_ptr->special;
222
223                 /* Activate the quest */
224                 if (!quest[creature_ptr->inside_quest].status)
225                 {
226                         if (quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
227                         {
228                                 init_flags = INIT_ASSIGN;
229                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
230                         }
231                         quest[creature_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
232                 }
233
234                 /* Leaving a quest */
235                 if (!creature_ptr->inside_quest)
236                 {
237                         current_floor_ptr->dun_level = 0;
238                 }
239                 creature_ptr->leaving = TRUE;
240
241                 creature_ptr->oldpx = 0;
242                 creature_ptr->oldpy = 0;
243                 
244                 take_turn(creature_ptr, 100);
245
246                 /* End the command */
247                 return;
248         }
249
250         if (!current_floor_ptr->dun_level)
251         {
252                 go_up = TRUE;
253         }
254         else
255         {
256                 go_up = confirm_leave_level(creature_ptr, FALSE);
257         }
258
259         if (!go_up) return;
260
261         take_turn(creature_ptr, 100);
262
263         if (autosave_l) do_cmd_save_game(TRUE);
264
265         /* For a random quest */
266         if (creature_ptr->inside_quest &&
267             quest[creature_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
268         {
269                 leave_quest_check();
270
271                 creature_ptr->inside_quest = 0;
272         }
273
274         /* For a fixed quest */
275         if (creature_ptr->inside_quest &&
276             quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
277         {
278                 leave_quest_check();
279
280                 creature_ptr->inside_quest = g_ptr->special;
281                 current_floor_ptr->dun_level = 0;
282                 up_num = 0;
283         }
284
285         /* For normal dungeon and random quest */
286         else
287         {
288                 /* New depth */
289                 if (have_flag(f_ptr->flags, FF_SHAFT))
290                 {
291                         /* Create a way back */
292                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_SHAFT);
293
294                         up_num = 2;
295                 }
296                 else
297                 {
298                         /* Create a way back */
299                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP);
300
301                         up_num = 1;
302                 }
303
304                 /* Get out from current dungeon */
305                 if (current_floor_ptr->dun_level - up_num < d_info[creature_ptr->dungeon_idx].mindepth)
306                         up_num = current_floor_ptr->dun_level;
307         }
308         if (record_stair) exe_write_diary(creature_ptr, NIKKI_STAIR, 0-up_num, _("階段を上った", "climbed up the stairs to"));
309
310         /* Success */
311         if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
312                 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
313         else if (up_num == current_floor_ptr->dun_level)
314                 msg_print(_("地上に戻った。", "You go back to the surface."));
315         else
316                 msg_print(_("階段を上って新たなる迷宮へと足を踏み入れた。", "You enter a maze of up staircases."));
317         creature_ptr->leaving = TRUE;
318 }
319
320
321 /*!
322  * @brief 階段を使って階層を降りる処理 / Go down one level
323  * @return なし
324  */
325 void do_cmd_go_down(player_type *creature_ptr)
326 {
327         /* Player grid */
328         grid_type *g_ptr = &current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
329         feature_type *f_ptr = &f_info[g_ptr->feat];
330
331         bool fall_trap = FALSE;
332         int down_num = 0;
333
334         if (creature_ptr->special_defense & KATA_MUSOU)
335         {
336                 set_action(creature_ptr, ACTION_NONE);
337         }
338
339         /* Verify stairs */
340         if (!have_flag(f_ptr->flags, FF_MORE))
341         {
342                 msg_print(_("ここには下り階段が見当たらない。", "I see no down staircase here."));
343                 return;
344         }
345
346         if (have_flag(f_ptr->flags, FF_TRAP)) fall_trap = TRUE;
347
348         /* Quest entrance */
349         if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
350         {
351                 do_cmd_quest();
352         }
353
354         /* Quest down stairs */
355         else if (have_flag(f_ptr->flags, FF_QUEST))
356         {
357                 /* Confirm Leaving */
358                 if(!confirm_leave_level(creature_ptr, TRUE)) return;
359                 
360                 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
361                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
362                 else
363                         msg_print(_("下の階に降りた。", "You enter the down staircase."));
364
365                 leave_quest_check();
366                 leave_tower_check();
367
368                 creature_ptr->inside_quest = g_ptr->special;
369
370                 /* Activate the quest */
371                 if (!quest[creature_ptr->inside_quest].status)
372                 {
373                         if (quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
374                         {
375                                 init_flags = INIT_ASSIGN;
376                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
377                         }
378                         quest[creature_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
379                 }
380
381                 /* Leaving a quest */
382                 if (!creature_ptr->inside_quest)
383                 {
384                         current_floor_ptr->dun_level = 0;
385                 }
386                 creature_ptr->leaving = TRUE;
387                 creature_ptr->oldpx = 0;
388                 creature_ptr->oldpy = 0;
389                 
390                 take_turn(creature_ptr, 100);
391         }
392
393         else
394         {
395                 DUNGEON_IDX target_dungeon = 0;
396
397                 if (!current_floor_ptr->dun_level)
398                 {
399                         target_dungeon = have_flag(f_ptr->flags, FF_ENTRANCE) ? g_ptr->special : DUNGEON_ANGBAND;
400
401                         if (ironman_downward && (target_dungeon != DUNGEON_ANGBAND))
402                         {
403                                 msg_print(_("ダンジョンの入口は塞がれている!", "The entrance of this dungeon is closed!"));
404                                 return;
405                         }
406                         if (!max_dlv[target_dungeon])
407                         {
408                                 msg_format(_("ここには%sの入り口(%d階相当)があります", "There is the entrance of %s (Danger level: %d)"),
409                                                         d_name+d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
410                                 if (!get_check(_("本当にこのダンジョンに入りますか?", "Do you really get in this dungeon? "))) return;
411                         }
412
413                         /* Save old player position */
414                         creature_ptr->oldpx = creature_ptr->x;
415                         creature_ptr->oldpy = creature_ptr->y;
416                         creature_ptr->dungeon_idx = target_dungeon;
417
418                         /*
419                          * Clear all saved floors
420                          * and create a first saved floor
421                          */
422                         prepare_change_floor_mode(CFM_FIRST_FLOOR);
423                 }
424
425                 take_turn(creature_ptr, 100);
426
427                 if (autosave_l) do_cmd_save_game(TRUE);
428
429                 /* Go down */
430                 if (have_flag(f_ptr->flags, FF_SHAFT)) down_num += 2;
431                 else down_num += 1;
432
433                 if (!current_floor_ptr->dun_level)
434                 {
435                         /* Enter the dungeon just now */
436                         creature_ptr->enter_dungeon = TRUE;
437                         down_num = d_info[creature_ptr->dungeon_idx].mindepth;
438                 }
439
440                 if (record_stair)
441                 {
442                         if (fall_trap) exe_write_diary(creature_ptr, NIKKI_STAIR, down_num, _("落とし戸に落ちた", "fell through a trap door"));
443                         else exe_write_diary(creature_ptr, NIKKI_STAIR, down_num, _("階段を下りた", "climbed down the stairs to"));
444                 }
445
446                 if (fall_trap)
447                 {
448                         msg_print(_("わざと落とし戸に落ちた。", "You deliberately jump through the trap door."));
449                 }
450                 else
451                 {
452                         /* Success */
453                         if (target_dungeon)
454                         {
455                                 msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[creature_ptr->dungeon_idx].text);
456                         }
457                         else
458                         {
459                                 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
460                                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
461                                 else
462                                         msg_print(_("階段を下りて新たなる迷宮へと足を踏み入れた。", "You enter a maze of down staircases."));
463                         }
464                 }
465
466                 creature_ptr->leaving = TRUE;
467
468                 if (fall_trap)
469                 {
470                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
471                 }
472                 else
473                 {
474                         if (have_flag(f_ptr->flags, FF_SHAFT))
475                         {
476                                 /* Create a way back */
477                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_SHAFT);
478                         }
479                         else
480                         {
481                                 /* Create a way back */
482                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN);
483                         }
484                 }
485         }
486 }
487
488
489 /*!
490  * @brief 探索コマンドのメインルーチン / Simple command to "search" for one current_world_ptr->game_turn
491  * @return なし
492  */
493 void do_cmd_search(player_type * creature_ptr)
494 {
495         /* Allow repeated command */
496         if (command_arg)
497         {
498                 /* Set repeat count */
499                 command_rep = command_arg - 1;
500                 creature_ptr->redraw |= (PR_STATE);
501
502                 /* Cancel the arg */
503                 command_arg = 0;
504         }
505         take_turn(creature_ptr, 100);
506
507         search(creature_ptr);
508 }
509
510
511 /*!
512  * @brief 該当のマスに存在している箱のオブジェクトIDを返す。
513  * @param y 走査対象にしたいマスのY座標
514  * @param x 走査対象にしたいマスのX座標
515  * @param trapped TRUEならばトラップが存在する箱のみ、FALSEならば空でない箱全てを対象にする
516  * @return 箱が存在する場合そのオブジェクトID、存在しない場合0を返す。
517  */
518 static OBJECT_IDX chest_check(POSITION y, POSITION x, bool trapped)
519 {
520         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
521         OBJECT_IDX this_o_idx, next_o_idx = 0;
522
523         /* Scan all objects in the grid */
524         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
525         {
526                 object_type *o_ptr;
527
528                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
529                 next_o_idx = o_ptr->next_o_idx;
530
531                 /* Skip unknown chests XXX XXX */
532                 /* if (!(o_ptr->marked & OM_FOUND)) continue; */
533
534                 /* Check for non empty chest */
535                 if ((o_ptr->tval == TV_CHEST) &&
536                         (((!trapped) && (o_ptr->pval)) || /* non empty */
537                         ((trapped) && (o_ptr->pval > 0)))) /* trapped only */
538                 {
539                         return (this_o_idx);
540                 }
541         }
542         return (0);
543 }
544
545 /*!
546  * @brief 箱を開ける実行処理 /
547  * Attempt to open the given chest at the given location
548  * @param y 箱の存在するマスのY座標
549  * @param x 箱の存在するマスのX座標
550  * @param o_idx 箱のオブジェクトID
551  * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
552  * @details
553  * Assume there is no monster blocking the destination
554  */
555 static bool exe_open_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
556 {
557         int i, j;
558         bool flag = TRUE;
559         bool more = FALSE;
560         object_type *o_ptr = &current_floor_ptr->o_list[o_idx];
561
562         take_turn(creature_ptr, 100);
563
564         /* Attempt to unlock it */
565         if (o_ptr->pval > 0)
566         {
567                 /* Assume locked, and thus not open */
568                 flag = FALSE;
569
570                 /* Get the "disarm" factor */
571                 i = creature_ptr->skill_dis;
572
573                 /* Penalize some conditions */
574                 if (creature_ptr->blind || no_lite()) i = i / 10;
575                 if (creature_ptr->confused || creature_ptr->image) i = i / 10;
576
577                 /* Extract the difficulty */
578                 j = i - o_ptr->pval;
579
580                 /* Always have a small chance of success */
581                 if (j < 2) j = 2;
582
583                 /* Success -- May still have traps */
584                 if (randint0(100) < j)
585                 {
586                         msg_print(_("鍵をはずした。", "You have picked the lock."));
587                         gain_exp(creature_ptr, 1);
588                         flag = TRUE;
589                 }
590
591                 /* Failure -- Keep trying */
592                 else
593                 {
594                         /* We may continue repeating */
595                         more = TRUE;
596                         if (flush_failure) flush();
597                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
598
599                 }
600         }
601
602         /* Allowed to open */
603         if (flag)
604         {
605                 /* Apply chest traps, if any */
606                 chest_trap(y, x, o_idx);
607
608                 /* Let the Chest drop items */
609                 chest_death(FALSE, y, x, o_idx);
610         }
611         return (more);
612 }
613
614 /*!
615  * @brief プレイヤーの周辺9マスに該当する地形がいくつあるかを返す /
616  * Attempt to open the given chest at the given location
617  * @param y 該当する地形の中から1つのY座標を返す参照ポインタ
618  * @param x 該当する地形の中から1つのX座標を返す参照ポインタ
619  * @param test 地形条件を判定するための関数ポインタ
620  * @param under TRUEならばプレイヤーの直下の座標も走査対象にする
621  * @return 該当する地形の数
622  * @details Return the number of features around (or under) the character.
623  * Usually look for doors and floor traps.
624  */
625 static int count_dt(player_type *creature_ptr, POSITION *y, POSITION *x, bool (*test)(FEAT_IDX feat), bool under)
626 {
627         DIRECTION d;
628         int count;
629         POSITION xx, yy;
630
631         /* Count how many matches */
632         count = 0;
633
634         /* Check around (and under) the character */
635         for (d = 0; d < 9; d++)
636         {
637                 grid_type *g_ptr;
638                 FEAT_IDX feat;
639
640                 /* if not searching under player continue */
641                 if ((d == 8) && !under) continue;
642
643                 /* Extract adjacent (legal) location */
644                 yy = creature_ptr->y + ddy_ddd[d];
645                 xx = creature_ptr->x + ddx_ddd[d];
646
647                 /* Get the current_floor_ptr->grid_array */
648                 g_ptr = &current_floor_ptr->grid_array[yy][xx];
649
650                 /* Must have knowledge */
651                 if (!(g_ptr->info & (CAVE_MARK))) continue;
652
653                 /* Feature code (applying "mimic" field) */
654                 feat = get_feat_mimic(g_ptr);
655
656                 /* Not looking for this feature */
657                 if (!((*test)(feat))) continue;
658
659                 /* OK */
660                 ++count;
661
662                 /* Remember the location. Only useful if only one match */
663                 *y = yy;
664                 *x = xx;
665         }
666
667         /* All done */
668         return count;
669 }
670
671
672 /*!
673  * @brief プレイヤーの周辺9マスに箱のあるマスがいくつあるかを返す /
674  * Return the number of chests around (or under) the character.
675  * @param y 該当するマスの中から1つのY座標を返す参照ポインタ
676  * @param x 該当するマスの中から1つのX座標を返す参照ポインタ
677  * @param trapped TRUEならばトラップの存在が判明している箱のみ対象にする
678  * @return 該当する地形の数
679  * @details
680  * If requested, count only trapped chests.
681  */
682 static int count_chests(player_type *creature_ptr, POSITION *y, POSITION *x, bool trapped)
683 {
684         DIRECTION d;
685         int count;
686         OBJECT_IDX o_idx;
687         object_type *o_ptr;
688
689         /* Count how many matches */
690         count = 0;
691
692         /* Check around (and under) the character */
693         for (d = 0; d < 9; d++)
694         {
695                 /* Extract adjacent (legal) location */
696                 POSITION yy = creature_ptr->y + ddy_ddd[d];
697                 POSITION xx = creature_ptr->x + ddx_ddd[d];
698
699                 /* No (visible) chest is there */
700                 if ((o_idx = chest_check(yy, xx, FALSE)) == 0) continue;
701
702                 /* Grab the object */
703                 o_ptr = &current_floor_ptr->o_list[o_idx];
704
705                 /* Already open */
706                 if (o_ptr->pval == 0) continue;
707
708                 /* No (known) traps here */
709                 if (trapped && (!object_is_known(o_ptr) ||
710                         !chest_traps[o_ptr->pval])) continue;
711
712                 /* OK */
713                 ++count;
714
715                 /* Remember the location. Only useful if only one match */
716                 *y = yy;
717                 *x = xx;
718         }
719
720         /* All done */
721         return count;
722 }
723
724
725
726 /*!
727  * @brief 「開ける」動作コマンドのサブルーチン /
728  * Perform the basic "open" command on doors
729  * @param y 対象を行うマスのY座標
730  * @param x 対象を行うマスのX座標
731  * @return 実際に処理が行われた場合TRUEを返す。
732  * @details
733  * Assume destination is a closed/locked/jammed door
734  * Assume there is no monster blocking the destination
735  * Returns TRUE if repeated commands may continue
736  */
737 static bool exe_open(player_type *creature_ptr, POSITION y, POSITION x)
738 {
739         int i, j;
740
741         /* Get requested grid */
742         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
743         feature_type *f_ptr = &f_info[g_ptr->feat];
744         bool more = FALSE;
745
746         take_turn(creature_ptr, 100);
747
748         /* Seeing true feature code (ignore mimic) */
749
750         /* Jammed door */
751         if (!have_flag(f_ptr->flags, FF_OPEN))
752         {
753                 /* Stuck */
754                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
755         }
756
757         /* Locked door */
758         else if (f_ptr->power)
759         {
760                 /* Disarm factor */
761                 i = creature_ptr->skill_dis;
762
763                 /* Penalize some conditions */
764                 if (creature_ptr->blind || no_lite()) i = i / 10;
765                 if (creature_ptr->confused || creature_ptr->image) i = i / 10;
766
767                 /* Extract the lock power */
768                 j = f_ptr->power;
769
770                 /* Extract the difficulty */
771                 j = i - (j * 4);
772
773                 /* Always have a small chance of success */
774                 if (j < 2) j = 2;
775
776                 /* Success */
777                 if (randint0(100) < j)
778                 {
779                         msg_print(_("鍵をはずした。", "You have picked the lock."));
780
781                         /* Open the door */
782                         cave_alter_feat(y, x, FF_OPEN);
783
784                         sound(SOUND_OPENDOOR);
785
786                         /* Experience */
787                         gain_exp(creature_ptr, 1);
788                 }
789
790                 /* Failure */
791                 else
792                 {
793                         /* Failure */
794                         if (flush_failure) flush();
795
796                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
797
798                         /* We may keep trying */
799                         more = TRUE;
800                 }
801         }
802
803         /* Closed door */
804         else
805         {
806                 /* Open the door */
807                 cave_alter_feat(y, x, FF_OPEN);
808
809                 sound(SOUND_OPENDOOR);
810         }
811         return (more);
812 }
813
814 /*!
815  * @brief 「開ける」コマンドのメインルーチン /
816  * Open a closed/locked/jammed door or a closed/locked chest.
817  * @return なし
818  * @details
819  * Unlocking a locked door/chest is worth one experience point.
820  */
821 void do_cmd_open(player_type *creature_ptr)
822 {
823         POSITION y, x;
824         DIRECTION dir;
825         OBJECT_IDX o_idx;
826
827         bool more = FALSE;
828
829         if (creature_ptr->wild_mode) return;
830
831         if (creature_ptr->special_defense & KATA_MUSOU)
832         {
833                 set_action(creature_ptr, ACTION_NONE);
834         }
835
836         /* Option: Pick a direction */
837         if (easy_open)
838         {
839                 int num_doors, num_chests;
840
841                 num_doors = count_dt(creature_ptr, &y, &x, is_closed_door, FALSE);
842                 num_chests = count_chests(creature_ptr, &y, &x, FALSE);
843                 if (num_doors || num_chests)
844                 {
845                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
846                             (num_chests > 1);
847                         if (!too_many) command_dir = coords_to_dir(y, x);
848                 }
849         }
850
851         /* Allow repeated command */
852         if (command_arg)
853         {
854                 /* Set repeat count */
855                 command_rep = command_arg - 1;
856                 creature_ptr->redraw |= (PR_STATE);
857
858                 /* Cancel the arg */
859                 command_arg = 0;
860         }
861
862         /* Get a "repeated" direction */
863         if (get_rep_dir(&dir, TRUE))
864         {
865                 FEAT_IDX feat;
866                 grid_type *g_ptr;
867
868                 /* Get requested location */
869                 y = creature_ptr->y + ddy[dir];
870                 x = creature_ptr->x + ddx[dir];
871
872                 /* Get requested grid */
873                 g_ptr = &current_floor_ptr->grid_array[y][x];
874
875                 /* Feature code (applying "mimic" field) */
876                 feat = get_feat_mimic(g_ptr);
877
878                 /* Check for chest */
879                 o_idx = chest_check(y, x, FALSE);
880
881                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
882                 {
883                         msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
884                 }
885                 else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
886                 {
887                         take_turn(creature_ptr, 100);
888                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
889                         py_attack(y, x, 0);
890                 }
891                 else if (o_idx)
892                 {
893                         more = exe_open_chest(creature_ptr, y, x, o_idx);
894                 }
895                 else
896                 {
897                         more = exe_open(creature_ptr, y, x);
898                 }
899         }
900
901         /* Cancel repeat unless we may continue */
902         if (!more) disturb(FALSE, FALSE);
903 }
904
905
906
907 /*!
908  * @brief 「閉じる」動作コマンドのサブルーチン /
909  * Perform the basic "close" command
910  * @param y 対象を行うマスのY座標
911  * @param x 対象を行うマスのX座標
912  * @return 実際に処理が行われた場合TRUEを返す。
913  * @details
914  * Assume destination is an open/broken door
915  * Assume there is no monster blocking the destination
916  * Returns TRUE if repeated commands may continue
917  */
918 static bool exe_close(player_type *creature_ptr, POSITION y, POSITION x)
919 {
920         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
921         FEAT_IDX old_feat = g_ptr->feat;
922         bool more = FALSE;
923
924         take_turn(creature_ptr, 100);
925
926         /* Seeing true feature code (ignore mimic) */
927
928         /* Open door */
929         if (have_flag(f_info[old_feat].flags, FF_CLOSE))
930         {
931                 s16b closed_feat = feat_state(old_feat, FF_CLOSE);
932
933                 /* Hack -- object in the way */
934                 if ((g_ptr->o_idx || (g_ptr->info & CAVE_OBJECT)) &&
935                     (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
936                 {
937                         msg_print(_("何かがつっかえて閉まらない。", "There seems stuck."));
938                 }
939                 else
940                 {
941                         /* Close the door */
942                         cave_alter_feat(y, x, FF_CLOSE);
943
944                         /* Broken door */
945                         if (old_feat == g_ptr->feat)
946                         {
947                                 msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
948                         }
949                         else
950                         {
951                                 sound(SOUND_SHUTDOOR);
952                         }
953                 }
954         }
955         return (more);
956 }
957
958
959 /*!
960  * @brief 「閉じる」コマンドのメインルーチン /
961  * Close an open door.
962  * @return なし
963  * @details
964  * Unlocking a locked door/chest is worth one experience point.
965  */
966 void do_cmd_close(player_type *creature_ptr)
967 {
968         POSITION y, x;
969         DIRECTION dir;
970
971         bool more = FALSE;
972
973         if (creature_ptr->wild_mode) return;
974
975         if (creature_ptr->special_defense & KATA_MUSOU)
976         {
977                 set_action(creature_ptr, ACTION_NONE);
978         }
979
980         /* Option: Pick a direction */
981         if (easy_open)
982         {
983                 /* Count open doors */
984                 if (count_dt(creature_ptr, &y, &x, is_open, FALSE) == 1)
985                 {
986                         command_dir = coords_to_dir(y, x);
987                 }
988         }
989
990         /* Allow repeated command */
991         if (command_arg)
992         {
993                 /* Set repeat count */
994                 command_rep = command_arg - 1;
995                 creature_ptr->redraw |= (PR_STATE);
996
997                 /* Cancel the arg */
998                 command_arg = 0;
999         }
1000
1001         /* Get a "repeated" direction */
1002         if (get_rep_dir(&dir, FALSE))
1003         {
1004                 grid_type *g_ptr;
1005                 FEAT_IDX feat;
1006
1007                 y = creature_ptr->y + ddy[dir];
1008                 x = creature_ptr->x + ddx[dir];
1009                 g_ptr = &current_floor_ptr->grid_array[y][x];
1010
1011                 /* Feature code (applying "mimic" field) */
1012                 feat = get_feat_mimic(g_ptr);
1013
1014                 /* Require open/broken door */
1015                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
1016                 {
1017                         msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
1018                 }
1019
1020                 /* Monster in the way */
1021                 else if (g_ptr->m_idx)
1022                 {
1023                         take_turn(creature_ptr, 100);
1024
1025                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1026
1027                         /* Attack */
1028                         py_attack(y, x, 0);
1029                 }
1030
1031                 /* Close the door */
1032                 else
1033                 {
1034                         /* Close the door */
1035                         more = exe_close(creature_ptr, y, x);
1036                 }
1037         }
1038
1039         /* Cancel repeat unless we may continue */
1040         if (!more) disturb(FALSE, FALSE);
1041 }
1042
1043
1044 /*!
1045  * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
1046  * Determine if a given grid may be "tunneled"
1047  * @param y 対象を行うマスのY座標
1048  * @param x 対象を行うマスのX座標
1049  * @return 
1050  */
1051 static bool do_cmd_tunnel_test(POSITION y, POSITION x)
1052 {
1053         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
1054
1055         /* Must have knowledge */
1056         if (!(g_ptr->info & CAVE_MARK))
1057         {
1058                 msg_print(_("そこには何も見当たらない。", "You see nothing there."));
1059
1060                 return (FALSE);
1061         }
1062
1063         /* Must be a wall/door/etc */
1064         if (!cave_have_flag_grid(g_ptr, FF_TUNNEL))
1065         {
1066                 msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
1067
1068                 return (FALSE);
1069         }
1070
1071         return (TRUE);
1072 }
1073
1074
1075 /*!
1076  * @brief 「掘る」動作コマンドのサブルーチン /
1077  * Perform the basic "tunnel" command
1078  * @param y 対象を行うマスのY座標
1079  * @param x 対象を行うマスのX座標
1080  * @return 実際に処理が行われた場合TRUEを返す。
1081  * @details
1082  * Assumes that no monster is blocking the destination
1083  * Do not use twall anymore
1084  * Returns TRUE if repeated commands may continue
1085  */
1086 static bool exe_tunnel(player_type *creature_ptr, POSITION y, POSITION x)
1087 {
1088         grid_type *g_ptr;
1089         feature_type *f_ptr, *mimic_f_ptr;
1090         int power;
1091         concptr name;
1092         bool more = FALSE;
1093
1094         /* Verify legality */
1095         if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1096
1097         take_turn(creature_ptr, 100);
1098
1099         g_ptr = &current_floor_ptr->grid_array[y][x];
1100         f_ptr = &f_info[g_ptr->feat];
1101         power = f_ptr->power;
1102
1103         /* Feature code (applying "mimic" field) */
1104         mimic_f_ptr = &f_info[get_feat_mimic(g_ptr)];
1105
1106         name = f_name + mimic_f_ptr->name;
1107
1108         sound(SOUND_DIG);
1109
1110         if (have_flag(f_ptr->flags, FF_PERMANENT))
1111         {
1112                 /* Titanium */
1113                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1114                 {
1115                         msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
1116                 }
1117
1118                 /* Map border (mimiccing Permanent wall) */
1119                 else
1120                 {
1121                         msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
1122                 }
1123         }
1124
1125         /* Dig or tunnel */
1126         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1127         {
1128                 /* Dig */
1129                 if (creature_ptr->skill_dig > randint0(20 * power))
1130                 {
1131                         msg_format(_("%sをくずした。", "You have removed the %s."), name);
1132
1133                         /* Remove the feature */
1134                         cave_alter_feat(y, x, FF_TUNNEL);
1135                         creature_ptr->update |= (PU_FLOW);
1136                 }
1137                 else
1138                 {
1139                         /* Message, keep digging */
1140                         msg_format(_("%sをくずしている。", "You dig into the %s."), name);
1141                         
1142                         more = TRUE;
1143                 }
1144         }
1145
1146         else
1147         {
1148                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1149
1150                 /* Tunnel */
1151                 if (creature_ptr->skill_dig > power + randint0(40 * power))
1152                 {
1153                         if (tree) msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
1154                         else
1155                         {
1156                                 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
1157                                 creature_ptr->update |= (PU_FLOW);
1158                         }
1159                         
1160                         if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1161
1162                         /* Remove the feature */
1163                         cave_alter_feat(y, x, FF_TUNNEL);
1164
1165                         chg_virtue(creature_ptr, V_DILIGENCE, 1);
1166                         chg_virtue(creature_ptr, V_NATURE, -1);
1167                 }
1168
1169                 /* Keep trying */
1170                 else
1171                 {
1172                         if (tree)
1173                         {
1174                                 /* We may continue chopping */
1175                                 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
1176                                 /* Occasional Search XXX XXX */
1177                                 if (randint0(100) < 25) search(creature_ptr);
1178                         }
1179                         else
1180                         {
1181                                 /* We may continue tunelling */
1182                                 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
1183                         }
1184
1185                         more = TRUE;
1186                 }
1187         }
1188
1189         if (is_hidden_door(g_ptr))
1190         {
1191                 /* Occasional Search XXX XXX */
1192                 if (randint0(100) < 25) search(creature_ptr);
1193         }
1194         return more;
1195 }
1196
1197
1198 /*!
1199  * @brief 「掘る」動作コマンドのメインルーチン /
1200  * Tunnels through "walls" (including rubble and closed doors)
1201  * @return なし
1202  * @details
1203  * <pre>
1204  * Note that you must tunnel in order to hit invisible monsters
1205  * in walls, though moving into walls still takes a current_world_ptr->game_turn anyway.
1206  *
1207  * Digging is very difficult without a "digger" weapon, but can be
1208  * accomplished by strong players using heavy weapons.
1209  * </pre>
1210  */
1211 void do_cmd_tunnel(player_type *creature_ptr)
1212 {
1213         POSITION y, x;
1214         DIRECTION dir;
1215         grid_type *g_ptr;
1216         FEAT_IDX feat;
1217
1218         bool more = FALSE;
1219
1220         if (creature_ptr->special_defense & KATA_MUSOU)
1221         {
1222                 set_action(creature_ptr, ACTION_NONE);
1223         }
1224
1225         /* Allow repeated command */
1226         if (command_arg)
1227         {
1228                 /* Set repeat count */
1229                 command_rep = command_arg - 1;
1230                 creature_ptr->redraw |= (PR_STATE);
1231
1232                 /* Cancel the arg */
1233                 command_arg = 0;
1234         }
1235
1236         /* Get a direction to tunnel, or Abort */
1237         if (get_rep_dir(&dir,FALSE))
1238         {
1239                 /* Get location */
1240                 y = creature_ptr->y + ddy[dir];
1241                 x = creature_ptr->x + ddx[dir];
1242
1243                 g_ptr = &current_floor_ptr->grid_array[y][x];
1244
1245                 /* Feature code (applying "mimic" field) */
1246                 feat = get_feat_mimic(g_ptr);
1247
1248                 /* No tunnelling through doors */
1249                 if (have_flag(f_info[feat].flags, FF_DOOR))
1250                 {
1251                         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
1252                 }
1253
1254                 /* No tunnelling through most features */
1255                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1256                 {
1257                         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
1258                 }
1259
1260                 /* A monster is in the way */
1261                 else if (g_ptr->m_idx)
1262                 {
1263                         take_turn(creature_ptr, 100);
1264                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1265
1266                         /* Attack */
1267                         py_attack(y, x, 0);
1268                 }
1269
1270                 /* Try digging */
1271                 else
1272                 {
1273                         /* Tunnel through walls */
1274                         more = exe_tunnel(creature_ptr, y, x);
1275                 }
1276         }
1277
1278         /* Cancel repetition unless we can continue */
1279         if (!more) disturb(FALSE, FALSE);
1280 }
1281
1282 /*!
1283  * @brief 移動処理による簡易な「開く」処理 /
1284  * easy_open_door --
1285  * @return 開く処理が実際に試みられた場合TRUEを返す
1286  * @details
1287  * <pre>
1288  *      If there is a jammed/closed/locked door at the given location,
1289  *      then attempt to unlock/open it. Return TRUE if an attempt was
1290  *      made (successful or not), otherwise return FALSE.
1291  *
1292  *      The code here should be nearly identical to that in
1293  *      do_cmd_open_test() and exe_open().
1294  * </pre>
1295  */
1296 bool easy_open_door(player_type *creature_ptr, POSITION y, POSITION x)
1297 {
1298         int i, j;
1299
1300         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
1301         feature_type *f_ptr = &f_info[g_ptr->feat];
1302
1303         /* Must be a closed door */
1304         if (!is_closed_door(g_ptr->feat))
1305         {
1306                 return (FALSE);
1307         }
1308
1309         /* Jammed door */
1310         if (!have_flag(f_ptr->flags, FF_OPEN))
1311         {
1312                 /* Stuck */
1313                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1314
1315         }
1316
1317         /* Locked door */
1318         else if (f_ptr->power)
1319         {
1320                 /* Disarm factor */
1321                 i = creature_ptr->skill_dis;
1322
1323                 /* Penalize some conditions */
1324                 if (creature_ptr->blind || no_lite()) i = i / 10;
1325                 if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1326
1327                 /* Extract the lock power */
1328                 j = f_ptr->power;
1329
1330                 /* Extract the difficulty */
1331                 j = i - (j * 4);
1332
1333                 /* Always have a small chance of success */
1334                 if (j < 2) j = 2;
1335
1336                 /* Success */
1337                 if (randint0(100) < j)
1338                 {
1339                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1340
1341                         /* Open the door */
1342                         cave_alter_feat(y, x, FF_OPEN);
1343
1344                         sound(SOUND_OPENDOOR);
1345
1346                         /* Experience */
1347                         gain_exp(creature_ptr, 1);
1348                 }
1349
1350                 /* Failure */
1351                 else
1352                 {
1353                         /* Failure */
1354                         if (flush_failure) flush();
1355
1356                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1357
1358                 }
1359         }
1360
1361         /* Closed door */
1362         else
1363         {
1364                 /* Open the door */
1365                 cave_alter_feat(y, x, FF_OPEN);
1366
1367                 sound(SOUND_OPENDOOR);
1368         }
1369         return (TRUE);
1370 }
1371
1372 /*!
1373  * @brief 箱のトラップを解除する実行処理 /
1374  * Perform the basic "disarm" command
1375  * @param y 解除を行うマスのY座標
1376  * @param x 解除を行うマスのX座標
1377  * @param o_idx 箱のオブジェクトID
1378  * @return ターンを消費する処理が行われた場合TRUEを返す
1379  * @details
1380  * <pre>
1381  * Assume destination is a visible trap
1382  * Assume there is no monster blocking the destination
1383  * Returns TRUE if repeated commands may continue
1384  * </pre>
1385  */
1386 static bool exe_disarm_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
1387 {
1388         int i, j;
1389         bool more = FALSE;
1390         object_type *o_ptr = &current_floor_ptr->o_list[o_idx];
1391
1392         take_turn(creature_ptr, 100);
1393
1394         /* Get the "disarm" factor */
1395         i = creature_ptr->skill_dis;
1396
1397         /* Penalize some conditions */
1398         if (creature_ptr->blind || no_lite()) i = i / 10;
1399         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1400
1401         /* Extract the difficulty */
1402         j = i - o_ptr->pval;
1403
1404         /* Always have a small chance of success */
1405         if (j < 2) j = 2;
1406
1407         /* Must find the trap first. */
1408         if (!object_is_known(o_ptr))
1409         {
1410                 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
1411
1412         }
1413
1414         /* Already disarmed/unlocked */
1415         else if (o_ptr->pval <= 0)
1416         {
1417                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1418         }
1419
1420         /* No traps to find. */
1421         else if (!chest_traps[o_ptr->pval])
1422         {
1423                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1424         }
1425
1426         /* Success (get a lot of experience) */
1427         else if (randint0(100) < j)
1428         {
1429                 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
1430                 gain_exp(creature_ptr, o_ptr->pval);
1431                 o_ptr->pval = (0 - o_ptr->pval);
1432         }
1433
1434         /* Failure -- Keep trying */
1435         else if ((i > 5) && (randint1(i) > 5))
1436         {
1437                 /* We may keep trying */
1438                 more = TRUE;
1439                 if (flush_failure) flush();
1440                 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
1441         }
1442
1443         /* Failure -- Set off the trap */
1444         else
1445         {
1446                 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
1447                 sound(SOUND_FAIL);
1448                 chest_trap(y, x, o_idx);
1449         }
1450         return (more);
1451 }
1452
1453
1454 /*!
1455  * @brief 箱のトラップを解除するコマンドのサブルーチン /
1456  * Perform the basic "disarm" command
1457  * @param y 解除を行うマスのY座標
1458  * @param x 解除を行うマスのX座標
1459  * @param dir プレイヤーからみた方向ID
1460  * @return ターンを消費する処理が行われた場合TRUEを返す
1461  * @details
1462  * <pre>
1463  * Assume destination is a visible trap
1464  * Assume there is no monster blocking the destination
1465  * Returns TRUE if repeated commands may continue
1466  * </pre>
1467  */
1468
1469 bool exe_disarm(player_type *creature_ptr, POSITION y, POSITION x, DIRECTION dir)
1470 {
1471         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
1472
1473         /* Get feature */
1474         feature_type *f_ptr = &f_info[g_ptr->feat];
1475
1476         /* Access trap name */
1477         concptr name = (f_name + f_ptr->name);
1478
1479         /* Extract trap "power" */
1480         int power = f_ptr->power;
1481         bool more = FALSE;
1482
1483         /* Get the "disarm" factor */
1484         int i = creature_ptr->skill_dis;
1485         int j;
1486
1487         take_turn(creature_ptr, 100);
1488
1489         /* Penalize some conditions */
1490         if (creature_ptr->blind || no_lite()) i = i / 10;
1491         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1492
1493         /* Extract the difficulty */
1494         j = i - power;
1495
1496         /* Always have a small chance of success */
1497         if (j < 2) j = 2;
1498
1499         /* Success */
1500         if (randint0(100) < j)
1501         {
1502                 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
1503                 
1504                 /* Reward */
1505                 gain_exp(creature_ptr, power);
1506
1507                 /* Remove the trap */
1508                 cave_alter_feat(y, x, FF_DISARM);
1509
1510                 /* Move the player onto the trap */
1511                 move_player(creature_ptr, dir, easy_disarm, FALSE);
1512         }
1513
1514         /* Failure -- Keep trying */
1515         else if ((i > 5) && (randint1(i) > 5))
1516         {
1517                 /* Failure */
1518                 if (flush_failure) flush();
1519
1520                 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
1521
1522                 /* We may keep trying */
1523                 more = TRUE;
1524         }
1525
1526         /* Failure -- Set off the trap */
1527         else
1528         {
1529                 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
1530                 /* Move the player onto the trap */
1531                 move_player(creature_ptr, dir, easy_disarm, FALSE);
1532         }
1533         return (more);
1534 }
1535
1536
1537 /*!
1538  * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
1539  * Disarms a trap, or chest
1540  * @return なし
1541  */
1542 void do_cmd_disarm(player_type *creature_ptr)
1543 {
1544         POSITION y, x;
1545         DIRECTION dir;
1546         OBJECT_IDX o_idx;
1547
1548         bool more = FALSE;
1549
1550         if (creature_ptr->wild_mode) return;
1551
1552         if (creature_ptr->special_defense & KATA_MUSOU)
1553         {
1554                 set_action(creature_ptr, ACTION_NONE);
1555         }
1556
1557         /* Option: Pick a direction */
1558         if (easy_disarm)
1559         {
1560                 int num_traps, num_chests;
1561
1562                 /* Count visible traps */
1563                 num_traps = count_dt(creature_ptr, &y, &x, is_trap, TRUE);
1564
1565                 /* Count chests (trapped) */
1566                 num_chests = count_chests(creature_ptr, &y, &x, TRUE);
1567
1568                 /* See if only one target */
1569                 if (num_traps || num_chests)
1570                 {
1571                         bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
1572                         if (!too_many) command_dir = coords_to_dir(y, x);
1573                 }
1574         }
1575
1576
1577         /* Allow repeated command */
1578         if (command_arg)
1579         {
1580                 /* Set repeat count */
1581                 command_rep = command_arg - 1;
1582                 creature_ptr->redraw |= (PR_STATE);
1583
1584                 /* Cancel the arg */
1585                 command_arg = 0;
1586         }
1587
1588         /* Get a direction (or abort) */
1589         if (get_rep_dir(&dir,TRUE))
1590         {
1591                 grid_type *g_ptr;
1592                 FEAT_IDX feat;
1593
1594                 y = creature_ptr->y + ddy[dir];
1595                 x = creature_ptr->x + ddx[dir];
1596                 g_ptr = &current_floor_ptr->grid_array[y][x];
1597
1598                 /* Feature code (applying "mimic" field) */
1599                 feat = get_feat_mimic(g_ptr);
1600
1601                 /* Check for chests */
1602                 o_idx = chest_check(y, x, TRUE);
1603
1604                 /* Disarm a trap */
1605                 if (!is_trap(feat) && !o_idx)
1606                 {
1607                         msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
1608                 }
1609
1610                 /* Monster in the way */
1611                 else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
1612                 {
1613                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1614
1615                         /* Attack */
1616                         py_attack(y, x, 0);
1617                 }
1618
1619                 /* Disarm chest */
1620                 else if (o_idx)
1621                 {
1622                         more = exe_disarm_chest(creature_ptr, y, x, o_idx);
1623                 }
1624
1625                 /* Disarm trap */
1626                 else
1627                 {
1628                         more = exe_disarm(creature_ptr, y, x, dir);
1629                 }
1630         }
1631
1632         /* Cancel repeat unless told not to */
1633         if (!more) disturb(FALSE, FALSE);
1634 }
1635
1636
1637 /*!
1638  * @brief 「打ち破る」動作コマンドのサブルーチン /
1639  * Perform the basic "bash" command
1640  * @param y 対象を行うマスのY座標
1641  * @param x 対象を行うマスのX座標
1642  * @param dir プレイヤーから見たターゲットの方角ID
1643  * @return 実際に処理が行われた場合TRUEを返す。
1644  * @details
1645  * <pre>
1646  * Assume destination is a closed/locked/jammed door
1647  * Assume there is no monster blocking the destination
1648  * Returns TRUE if repeated commands may continue
1649  * </pre>
1650  */
1651 static bool do_cmd_bash_aux(player_type *creature_ptr, POSITION y, POSITION x, DIRECTION dir)
1652 {
1653         grid_type       *g_ptr = &current_floor_ptr->grid_array[y][x];
1654
1655         /* Get feature */
1656         feature_type *f_ptr = &f_info[g_ptr->feat];
1657
1658         /* Hack -- Bash power based on strength */
1659         /* (Ranges from 3 to 20 to 100 to 200) */
1660         int bash = adj_str_blow[creature_ptr->stat_ind[A_STR]];
1661
1662         /* Extract door power */
1663         int temp = f_ptr->power;
1664
1665         bool            more = FALSE;
1666
1667         concptr name = f_name + f_info[get_feat_mimic(g_ptr)].name;
1668
1669         take_turn(creature_ptr, 100);
1670
1671         msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
1672
1673         /* Compare bash power to door power */
1674         temp = (bash - (temp * 10));
1675
1676         if (creature_ptr->pclass == CLASS_BERSERKER) temp *= 2;
1677
1678         /* Hack -- always have a chance */
1679         if (temp < 1) temp = 1;
1680
1681         /* Hack -- attempt to bash down the door */
1682         if (randint0(100) < temp)
1683         {
1684                 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
1685
1686                 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
1687
1688                 /* Break down the door */
1689                 if ((randint0(100) < 50) || (feat_state(g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
1690                 {
1691                         cave_alter_feat(y, x, FF_BASH);
1692                 }
1693
1694                 /* Open the door */
1695                 else
1696                 {
1697                         cave_alter_feat(y, x, FF_OPEN);
1698                 }
1699
1700                 /* Hack -- Fall through the door */
1701                 move_player(creature_ptr, dir, FALSE, FALSE);
1702         }
1703
1704         /* Saving throw against stun */
1705         else if (randint0(100) < adj_dex_safe[creature_ptr->stat_ind[A_DEX]] +
1706                  creature_ptr->lev)
1707         {
1708                 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
1709
1710                 /* Allow repeated bashing */
1711                 more = TRUE;
1712         }
1713
1714         /* High dexterity yields coolness */
1715         else
1716         {
1717                 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
1718
1719                 /* Hack -- Lose balance ala paralysis */
1720                 (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + 2 + randint0(2));
1721         }
1722         return (more);
1723 }
1724
1725
1726 /*!
1727  * @brief 「打ち破る」動作コマンドのメインルーチン /
1728  * Bash open a door, success based on character strength
1729  * @return なし
1730  * @details
1731  * <pre>
1732  * For a closed door, pval is positive if locked; negative if stuck.
1733  *
1734  * For an open door, pval is positive for a broken door.
1735  *
1736  * A closed door can be opened - harder if locked. Any door might be
1737  * bashed open (and thereby broken). Bashing a door is (potentially)
1738  * faster! You move into the door way. To open a stuck door, it must
1739  * be bashed. A closed door can be jammed (see do_cmd_spike()).
1740  *
1741  * Creatures can also open or bash doors, see elsewhere.
1742  * </pre>
1743  */
1744 void do_cmd_bash(player_type *creature_ptr)
1745 {
1746         POSITION y, x;
1747         DIRECTION dir;
1748         grid_type *g_ptr;
1749         bool more = FALSE;
1750
1751         if (creature_ptr->wild_mode) return;
1752
1753         if (creature_ptr->special_defense & KATA_MUSOU)
1754         {
1755                 set_action(creature_ptr, ACTION_NONE);
1756         }
1757
1758         /* Allow repeated command */
1759         if (command_arg)
1760         {
1761                 /* Set repeat count */
1762                 command_rep = command_arg - 1;
1763                 creature_ptr->redraw |= (PR_STATE);
1764
1765                 /* Cancel the arg */
1766                 command_arg = 0;
1767         }
1768
1769         /* Get a "repeated" direction */
1770         if (get_rep_dir(&dir,FALSE))
1771         {
1772                 FEAT_IDX feat;
1773
1774                 /* Bash location */
1775                 y = creature_ptr->y + ddy[dir];
1776                 x = creature_ptr->x + ddx[dir];
1777
1778                 g_ptr = &current_floor_ptr->grid_array[y][x];
1779
1780                 /* Feature code (applying "mimic" field) */
1781                 feat = get_feat_mimic(g_ptr);
1782
1783                 /* Nothing useful */
1784                 if (!have_flag(f_info[feat].flags, FF_BASH))
1785                 {
1786                         msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
1787                 }
1788
1789                 /* Monster in the way */
1790                 else if (g_ptr->m_idx)
1791                 {
1792                         take_turn(creature_ptr, 100);
1793
1794                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1795
1796                         /* Attack */
1797                         py_attack(y, x, 0);
1798                 }
1799
1800                 /* Bash a closed door */
1801                 else
1802                 {
1803                         /* Bash the door */
1804                         more = do_cmd_bash_aux(creature_ptr, y, x, dir);
1805                 }
1806         }
1807
1808         /* Unless valid action taken, cancel bash */
1809         if (!more) disturb(FALSE, FALSE);
1810 }
1811
1812
1813 /*!
1814  * @brief 特定のマスに影響を及ぼすための汎用的コマンド
1815  * @return なし
1816  * @details
1817  * <pre>
1818  * Manipulate an adjacent grid in some way
1819  *
1820  * Attack monsters, tunnel through walls, disarm traps, open doors.
1821  *
1822  * Consider confusion 
1823  *
1824  * This command must always take a current_world_ptr->game_turn, to prevent free detection
1825  * of invisible monsters.
1826  * </pre>
1827  */
1828 void do_cmd_alter(player_type *creature_ptr)
1829 {
1830         POSITION y, x;
1831         DIRECTION dir;
1832         grid_type *g_ptr;
1833         bool more = FALSE;
1834
1835         if (creature_ptr->special_defense & KATA_MUSOU)
1836         {
1837                 set_action(creature_ptr, ACTION_NONE);
1838         }
1839
1840         /* Allow repeated command */
1841         if (command_arg)
1842         {
1843                 /* Set repeat count */
1844                 command_rep = command_arg - 1;
1845                 creature_ptr->redraw |= (PR_STATE);
1846
1847                 /* Cancel the arg */
1848                 command_arg = 0;
1849         }
1850
1851         /* Get a direction */
1852         if (get_rep_dir(&dir,TRUE))
1853         {
1854                 FEAT_IDX feat;
1855                 feature_type *f_ptr;
1856
1857                 y = creature_ptr->y + ddy[dir];
1858                 x = creature_ptr->x + ddx[dir];
1859
1860                 g_ptr = &current_floor_ptr->grid_array[y][x];
1861
1862                 /* Feature code (applying "mimic" field) */
1863                 feat = get_feat_mimic(g_ptr);
1864                 f_ptr = &f_info[feat];
1865
1866                 take_turn(creature_ptr, 100);
1867
1868                 if (g_ptr->m_idx)
1869                 {
1870                         py_attack(y, x, 0);
1871                 }
1872
1873                 /* Locked doors */
1874                 else if (have_flag(f_ptr->flags, FF_OPEN))
1875                 {
1876                         more = exe_open(creature_ptr, y, x);
1877                 }
1878
1879                 /* Bash jammed doors */
1880                 else if (have_flag(f_ptr->flags, FF_BASH))
1881                 {
1882                         more = do_cmd_bash_aux(creature_ptr, y, x, dir);
1883                 }
1884
1885                 /* Tunnel through walls */
1886                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
1887                 {
1888                         more = exe_tunnel(creature_ptr, y, x);
1889                 }
1890
1891                 /* Close open doors */
1892                 else if (have_flag(f_ptr->flags, FF_CLOSE))
1893                 {
1894                         more = exe_close(creature_ptr, y, x);
1895                 }
1896
1897                 /* Disarm traps */
1898                 else if (have_flag(f_ptr->flags, FF_DISARM))
1899                 {
1900                         more = exe_disarm(creature_ptr, y, x, dir);
1901                 }
1902
1903                 else
1904                 {
1905                         msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
1906                 }
1907         }
1908
1909         /* Cancel repetition unless we can continue */
1910         if (!more) disturb(FALSE, FALSE);
1911 }
1912
1913
1914
1915 /*!
1916  * @brief 「くさびを打つ」ために必要なオブジェクトを所持しているかどうかの判定を返す /
1917  * Find the index of some "spikes", if possible.
1918  * @param ip くさびとして打てるオブジェクトのID
1919  * @return オブジェクトがある場合TRUEを返す
1920  * @details
1921  * <pre>
1922  * Let user choose a pile of spikes, perhaps?
1923  * </pre>
1924  */
1925 static bool get_spike(player_type *creature_ptr, INVENTORY_IDX *ip)
1926 {
1927         INVENTORY_IDX i;
1928
1929         /* Check every item in the pack */
1930         for (i = 0; i < INVEN_PACK; i++)
1931         {
1932                 object_type *o_ptr = &creature_ptr->inventory_list[i];
1933                 if (!o_ptr->k_idx) continue;
1934
1935                 /* Check the "tval" code */
1936                 if (o_ptr->tval == TV_SPIKE)
1937                 {
1938                         /* Save the spike index */
1939                         (*ip) = i;
1940
1941                         /* Success */
1942                         return (TRUE);
1943                 }
1944         }
1945
1946         return (FALSE);
1947 }
1948
1949
1950 /*!
1951  * @brief 「くさびを打つ」動作コマンドのメインルーチン /
1952  * Jam a closed door with a spike
1953  * @return なし
1954  * @details
1955  * <pre>
1956  * This command may NOT be repeated
1957  * </pre>
1958  */
1959 void do_cmd_spike(player_type *creature_ptr)
1960 {
1961         DIRECTION dir;
1962
1963         if (creature_ptr->wild_mode) return;
1964         if (creature_ptr->special_defense & KATA_MUSOU)
1965         {
1966                 set_action(creature_ptr, ACTION_NONE);
1967         }
1968
1969         /* Get a "repeated" direction */
1970         if (get_rep_dir(&dir, FALSE))
1971         {
1972                 POSITION y, x;
1973                 INVENTORY_IDX item;
1974                 grid_type *g_ptr;
1975                 FEAT_IDX feat;
1976
1977                 y = creature_ptr->y + ddy[dir];
1978                 x = creature_ptr->x + ddx[dir];
1979                 g_ptr = &current_floor_ptr->grid_array[y][x];
1980
1981                 /* Feature code (applying "mimic" field) */
1982                 feat = get_feat_mimic(g_ptr);
1983
1984                 /* Require closed door */
1985                 if (!have_flag(f_info[feat].flags, FF_SPIKE))
1986                 {
1987                         msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
1988                 }
1989
1990                 /* Get a spike */
1991                 else if (!get_spike(creature_ptr, &item))
1992                 {
1993                         msg_print(_("くさびを持っていない!", "You have no spikes!"));
1994                 }
1995
1996                 /* Is a monster in the way? */
1997                 else if (g_ptr->m_idx)
1998                 {
1999                         take_turn(creature_ptr, 100);
2000
2001                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2002
2003                         /* Attack */
2004                         py_attack(y, x, 0);
2005                 }
2006
2007                 /* Go for it */
2008                 else
2009                 {
2010                         take_turn(creature_ptr, 100);
2011
2012                         /* Successful jamming */
2013                         msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_name + f_info[feat].name);
2014                         cave_alter_feat(y, x, FF_SPIKE);
2015
2016                         /* Use up, and describe, a single spike, from the bottom */
2017                         inven_item_increase(item, -1);
2018                         inven_item_describe(item);
2019                         inven_item_optimize(item);
2020                 }
2021         }
2022 }
2023
2024
2025
2026 /*!
2027  * @brief 「歩く」動作コマンドのメインルーチン /
2028  * Support code for the "Walk" and "Jump" commands
2029  * @param pickup アイテムの自動拾いを行うならTRUE
2030  * @return なし
2031  */
2032 void do_cmd_walk(player_type *creature_ptr, bool pickup)
2033 {
2034         DIRECTION dir;
2035
2036         bool more = FALSE;
2037
2038
2039         /* Allow repeated command */
2040         if (command_arg)
2041         {
2042                 /* Set repeat count */
2043                 command_rep = command_arg - 1;
2044                 creature_ptr->redraw |= (PR_STATE);
2045
2046                 /* Cancel the arg */
2047                 command_arg = 0;
2048         }
2049
2050         /* Get a "repeated" direction */
2051         if (get_rep_dir(&dir, FALSE))
2052         {
2053                 take_turn(creature_ptr, 100);
2054
2055                 if ((dir != 5) && (creature_ptr->special_defense & KATA_MUSOU))
2056                 {
2057                         set_action(creature_ptr, ACTION_NONE);
2058                 }
2059
2060                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2061                 if (creature_ptr->wild_mode) creature_ptr->energy_use *= ((MAX_HGT + MAX_WID) / 2);
2062                 if (creature_ptr->action == ACTION_HAYAGAKE) creature_ptr->energy_use = creature_ptr->energy_use * (45-(creature_ptr->lev/2)) / 100;
2063
2064                 /* Actually move the character */
2065                 move_player(creature_ptr, dir, pickup, FALSE);
2066
2067                 /* Allow more walking */
2068                 more = TRUE;
2069         }
2070
2071         /* Hack again -- Is there a special encounter ??? */
2072         if (creature_ptr->wild_mode && !cave_have_flag_bold(creature_ptr->y, creature_ptr->x, FF_TOWN))
2073         {
2074                 int tmp = 120 + creature_ptr->lev*10 - wilderness[creature_ptr->y][creature_ptr->x].level + 5;
2075                 if (tmp < 1) 
2076                         tmp = 1;
2077                 if (((wilderness[creature_ptr->y][creature_ptr->x].level + 5) > (creature_ptr->lev / 2)) && randint0(tmp) < (21-creature_ptr->skill_stl))
2078                 {
2079                         /* Inform the player of his horrible fate :=) */
2080                         msg_print(_("襲撃だ!", "You are ambushed !"));
2081
2082                         /* Go into large wilderness view */
2083                         creature_ptr->oldpy = randint1(MAX_HGT-2);
2084                         creature_ptr->oldpx = randint1(MAX_WID-2);
2085                         change_wild_mode(TRUE);
2086
2087                         /* Give first move to monsters */
2088                         take_turn(creature_ptr, 100);
2089
2090                 }
2091         }
2092
2093         /* Cancel repeat unless we may continue */
2094         if (!more) disturb(FALSE, FALSE);
2095 }
2096
2097
2098 /*!
2099  * @brief 「走る」動作コマンドのメインルーチン /
2100  * Start running.
2101  * @return なし
2102  */
2103 void do_cmd_run(player_type *creature_ptr)
2104 {
2105         DIRECTION dir;
2106         if (cmd_limit_confused(creature_ptr)) return;
2107
2108         if (creature_ptr->special_defense & KATA_MUSOU)
2109         {
2110                 set_action(creature_ptr, ACTION_NONE);
2111         }
2112
2113         /* Get a "repeated" direction */
2114         if (get_rep_dir(&dir,FALSE))
2115         {
2116                 /* Hack -- Set the run counter */
2117                 creature_ptr->running = (command_arg ? command_arg : 1000);
2118
2119                 /* First step */
2120                 run_step(dir);
2121         }
2122 }
2123
2124
2125 /*!
2126  * @brief 「留まる」動作コマンドのメインルーチン /
2127  * Stay still.  Search.  Enter stores.
2128  * Pick up treasure if "pickup" is true.
2129  * @param pickup アイテムの自動拾いを行うならTRUE
2130  * @return なし
2131  */
2132 void do_cmd_stay(player_type *creature_ptr, bool pickup)
2133 {
2134         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2135
2136         /* Allow repeated command */
2137         if (command_arg)
2138         {
2139                 /* Set repeat count */
2140                 command_rep = command_arg - 1;
2141                 creature_ptr->redraw |= (PR_STATE);
2142
2143                 /* Cancel the arg */
2144                 command_arg = 0;
2145         }
2146
2147         take_turn(creature_ptr, 100);
2148
2149         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2150         (void)move_player_effect(creature_ptr, creature_ptr->y, creature_ptr->x, mpe_mode);
2151 }
2152
2153
2154 /*!
2155  * @brief 「休む」動作コマンドのメインルーチン /
2156  * Resting allows a player to safely restore his hp     -RAK-
2157  * @return なし
2158  */
2159 void do_cmd_rest(player_type *creature_ptr)
2160 {
2161
2162         set_action(creature_ptr, ACTION_NONE);
2163
2164         if ((creature_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(creature_ptr) || INTERUPTING_SONG_EFFECT(creature_ptr)))
2165         {
2166                 stop_singing(creature_ptr);
2167         }
2168
2169         if (hex_spelling_any(creature_ptr)) stop_hex_spell_all();
2170
2171         /* Prompt for time if needed */
2172         if (command_arg <= 0)
2173         {
2174                 concptr p = _("休憩 (0-9999, '*' で HP/MP全快, '&' で必要なだけ): ", 
2175                                    "Rest (0-9999, '*' for HP/SP, '&' as needed): ");
2176
2177
2178                 char out_val[80];
2179
2180                 /* Default */
2181                 strcpy(out_val, "&");
2182
2183                 /* Ask for duration */
2184                 if (!get_string(p, out_val, 4)) return;
2185
2186                 /* Rest until done */
2187                 if (out_val[0] == '&')
2188                 {
2189                         command_arg = COMMAND_ARG_REST_UNTIL_DONE;
2190                 }
2191
2192                 /* Rest a lot */
2193                 else if (out_val[0] == '*')
2194                 {
2195                         command_arg = COMMAND_ARG_REST_FULL_HEALING;
2196                 }
2197
2198                 /* Rest some */
2199                 else
2200                 {
2201                         command_arg = (COMMAND_ARG)atoi(out_val);
2202                         if (command_arg <= 0) return;
2203                 }
2204         }
2205
2206         if (command_arg > 9999) command_arg = 9999;
2207
2208         if (creature_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(creature_ptr, FALSE);
2209
2210         /* Take a current_world_ptr->game_turn (?) */
2211         take_turn(creature_ptr, 100);
2212
2213         /* The sin of sloth */
2214         if (command_arg > 100) chg_virtue(creature_ptr, V_DILIGENCE, -1);
2215         
2216         /* Why are you sleeping when there's no need?  WAKE UP!*/
2217         if ((creature_ptr->chp == creature_ptr->mhp) &&
2218             (creature_ptr->csp == creature_ptr->msp) &&
2219             !creature_ptr->blind && !creature_ptr->confused &&
2220             !creature_ptr->poisoned && !creature_ptr->afraid &&
2221             !creature_ptr->stun && !creature_ptr->cut &&
2222             !creature_ptr->slow && !creature_ptr->paralyzed &&
2223             !creature_ptr->image && !creature_ptr->word_recall &&
2224             !creature_ptr->alter_reality)
2225                         chg_virtue(creature_ptr, V_DILIGENCE, -1);
2226
2227         /* Save the rest code */
2228         creature_ptr->resting = command_arg;
2229         creature_ptr->action = ACTION_REST;
2230         creature_ptr->update |= (PU_BONUS);
2231         update_creature(creature_ptr);
2232
2233         creature_ptr->redraw |= (PR_STATE);
2234         update_output();
2235
2236         Term_fresh();
2237 }
2238
2239
2240
2241 /*!
2242  * @brief 射撃処理のメインルーチン
2243  * @return なし
2244  */
2245 void do_cmd_fire(player_type *creature_ptr, SPELL_IDX snipe_type)
2246 {
2247         OBJECT_IDX item;
2248         object_type *j_ptr, *ammo_ptr;
2249         concptr q, s;
2250
2251         if(creature_ptr->wild_mode) return;
2252
2253         creature_ptr->is_fired = FALSE; /* not fired yet */
2254
2255         /* Get the "bow" (if any) */
2256         j_ptr = &creature_ptr->inventory_list[INVEN_BOW];
2257
2258         /* Require a launcher */
2259         if (!j_ptr->tval)
2260         {
2261                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
2262                 flush();
2263                 return;
2264         }
2265
2266         if (j_ptr->sval == SV_CRIMSON)
2267         {
2268                 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
2269                 flush();
2270                 return;
2271         }
2272
2273         if (j_ptr->sval == SV_HARP)
2274         {
2275                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
2276                 flush();
2277                 return;
2278         }
2279
2280
2281         if (creature_ptr->special_defense & KATA_MUSOU)
2282         {
2283                 set_action(creature_ptr, ACTION_NONE);
2284         }
2285
2286         q = _("どれを撃ちますか? ", "Fire which item? ");
2287         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
2288
2289         ammo_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR), creature_ptr->tval_ammo);
2290         if (!ammo_ptr)
2291         {
2292                 flush();
2293                 return;
2294         }
2295
2296         /* Fire the item */
2297         exe_fire(item, j_ptr, snipe_type);
2298
2299         if (!creature_ptr->is_fired || creature_ptr->pclass != CLASS_SNIPER) return;
2300
2301         /* Sniper actions after some shootings */
2302         if (snipe_type == SP_AWAY)
2303         {
2304                 teleport_player(10 + (creature_ptr->concent * 2), 0L);
2305         }
2306         if (snipe_type == SP_FINAL)
2307         {
2308                 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
2309                 (void)set_slow(creature_ptr, creature_ptr->slow + randint0(7) + 7, FALSE);
2310                 (void)set_stun(creature_ptr, creature_ptr->stun + randint1(25));
2311         }
2312 }
2313
2314
2315 /*!
2316  * @brief 投射処理メインルーチン /
2317  * Throw an object from the pack or floor.
2318  * @param mult 威力の倍率
2319  * @param boomerang ブーメラン処理ならばTRUE
2320  * @param shuriken 忍者の手裏剣処理ならばTRUE
2321  * @return ターンを消費した場合TRUEを返す
2322  * @details
2323  * <pre>
2324  * Note: "unseen" monsters are very hard to hit.
2325  *
2326  * Should throwing a weapon do full damage?  Should it allow the magic
2327  * to hit bonus of the weapon to have an effect?  Should it ever cause
2328  * the item to be destroyed?  Should it do any damage at all?
2329  * </pre>
2330  */
2331 bool do_cmd_throw(player_type *creature_ptr, int mult, bool boomerang, OBJECT_IDX shuriken)
2332 {
2333         DIRECTION dir;
2334         OBJECT_IDX item;
2335         int i;
2336         POSITION y, x, ty, tx, prev_y, prev_x;
2337         POSITION ny[19], nx[19];
2338         int chance, tdam, tdis;
2339         int mul, div, dd, ds;
2340         int cur_dis, visible;
2341         PERCENTAGE j;
2342
2343         object_type forge;
2344         object_type *q_ptr;
2345         object_type *o_ptr;
2346
2347         bool hit_body = FALSE;
2348         bool hit_wall = FALSE;
2349         bool equiped_item = FALSE;
2350         bool return_when_thrown = FALSE;
2351
2352         GAME_TEXT o_name[MAX_NLEN];
2353
2354         int msec = delay_factor * delay_factor * delay_factor;
2355
2356         BIT_FLAGS flgs[TR_FLAG_SIZE];
2357         concptr q, s;
2358         bool come_back = FALSE;
2359         bool do_drop = TRUE;
2360
2361         if (creature_ptr->wild_mode) return FALSE;
2362
2363         if (creature_ptr->special_defense & KATA_MUSOU)
2364         {
2365                 set_action(creature_ptr, ACTION_NONE);
2366         }
2367
2368         if (shuriken >= 0)
2369         {
2370                 item = shuriken;
2371                 o_ptr = &creature_ptr->inventory_list[item];
2372         }
2373         else if (boomerang)
2374         {
2375                 if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM))
2376                 {
2377                         item_tester_hook = item_tester_hook_boomerang;
2378                         q = _("どの武器を投げますか? ", "Throw which item? ");
2379                         s = _("投げる武器がない。", "You have nothing to throw.");
2380                         o_ptr = choose_object(&item, q, s, (USE_EQUIP), 0);
2381                         if (!o_ptr)
2382                         {
2383                                 flush();
2384                                 return FALSE;
2385                         }
2386                 }
2387                 else if (has_melee_weapon(creature_ptr, INVEN_LARM))
2388                 {
2389                         item = INVEN_LARM;
2390                         o_ptr = &creature_ptr->inventory_list[item];
2391                 }
2392                 else
2393                 {
2394                         item = INVEN_RARM;
2395                         o_ptr = &creature_ptr->inventory_list[item];
2396                 }
2397         }
2398         else
2399         {
2400                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
2401                 s = _("投げるアイテムがない。", "You have nothing to throw.");
2402                 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP), 0);
2403                 if (!o_ptr)
2404                 {
2405                         flush();
2406                         return FALSE;
2407                 }
2408         }
2409
2410         /* Item is cursed */
2411         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
2412         {
2413                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
2414                 return FALSE;
2415         }
2416
2417         if (creature_ptr->inside_arena && !boomerang)
2418         {
2419                 if (o_ptr->tval != TV_SPIKE)
2420                 {
2421                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
2422                         msg_print(NULL);
2423
2424                         return FALSE;
2425                 }
2426
2427         }
2428         q_ptr = &forge;
2429         object_copy(q_ptr, o_ptr);
2430
2431         /* Extract the thrown object's flags. */
2432         object_flags(q_ptr, flgs);
2433         torch_flags(q_ptr, flgs);
2434
2435         /* Distribute the charges of rods/wands between the stacks */
2436         distribute_charges(o_ptr, q_ptr, 1);
2437
2438         /* Single object */
2439         q_ptr->number = 1;
2440
2441         object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
2442
2443         if (creature_ptr->mighty_throw) mult += 3;
2444
2445         /* Extract a "distance multiplier" */
2446         /* Changed for 'launcher' mutation */
2447         mul = 10 + 2 * (mult - 1);
2448
2449         /* Enforce a minimum "weight" of one pound */
2450         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
2451         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
2452
2453         /* Hack -- Distance -- Reward strength, penalize weight */
2454         tdis = (adj_str_blow[creature_ptr->stat_ind[A_STR]] + 20) * mul / div;
2455
2456         /* Max distance of 10-18 */
2457         if (tdis > mul) tdis = mul;
2458
2459         if (shuriken >= 0)
2460         {
2461                 ty = randint0(101) - 50 + creature_ptr->y;
2462                 tx = randint0(101) - 50 + creature_ptr->x;
2463         }
2464         else
2465         {
2466                 project_length = tdis + 1;
2467
2468                 /* Get a direction (or cancel) */
2469                 if (!get_aim_dir(&dir)) return FALSE;
2470
2471                 /* Predict the "target" location */
2472                 tx = creature_ptr->x + 99 * ddx[dir];
2473                 ty = creature_ptr->y + 99 * ddy[dir];
2474
2475                 /* Check for "target request" */
2476                 if ((dir == 5) && target_okay())
2477                 {
2478                         tx = target_col;
2479                         ty = target_row;
2480                 }
2481
2482                 project_length = 0;  /* reset to default */
2483         }
2484
2485         if ((q_ptr->name1 == ART_MJOLLNIR) ||
2486             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
2487                 return_when_thrown = TRUE;
2488
2489         /* Reduce and describe creature_ptr->inventory_list */
2490         if (item >= 0)
2491         {
2492                 inven_item_increase(item, -1);
2493                 if (!return_when_thrown)
2494                         inven_item_describe(item);
2495                 inven_item_optimize(item);
2496         }
2497
2498         /* Reduce and describe floor item */
2499         else
2500         {
2501                 floor_item_increase(0 - item, -1);
2502                 floor_item_optimize(0 - item);
2503         }
2504         if (item >= INVEN_RARM)
2505         {
2506                 equiped_item = TRUE;
2507                 creature_ptr->redraw |= (PR_EQUIPPY);
2508         }
2509
2510         take_turn(creature_ptr, 100);
2511
2512         /* Rogue and Ninja gets bonus */
2513         if ((creature_ptr->pclass == CLASS_ROGUE) || (creature_ptr->pclass == CLASS_NINJA))
2514                 creature_ptr->energy_use -= creature_ptr->lev;
2515
2516         /* Start at the player */
2517         y = creature_ptr->y;
2518         x = creature_ptr->x;
2519
2520         handle_stuff();
2521
2522         if ((creature_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
2523         else shuriken = FALSE;
2524
2525         /* Chance of hitting */
2526         if (have_flag(flgs, TR_THROW)) chance = ((creature_ptr->skill_tht) +
2527                 ((creature_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
2528         else chance = (creature_ptr->skill_tht + (creature_ptr->to_h_b * BTH_PLUS_ADJ));
2529
2530         if (shuriken) chance *= 2;
2531
2532         prev_y = y;
2533         prev_x = x;
2534
2535         /* Travel until stopped */
2536         for (cur_dis = 0; cur_dis <= tdis; )
2537         {
2538                 /* Hack -- Stop at the target */
2539                 if ((y == ty) && (x == tx)) break;
2540
2541                 /* Calculate the new location (see "project()") */
2542                 ny[cur_dis] = y;
2543                 nx[cur_dis] = x;
2544                 mmove2(&ny[cur_dis], &nx[cur_dis], creature_ptr->y, creature_ptr->x, ty, tx);
2545
2546                 /* Stopped by walls/doors */
2547                 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
2548                 {
2549                         hit_wall = TRUE;
2550                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !current_floor_ptr->grid_array[ny[cur_dis]][nx[cur_dis]].m_idx) break;
2551                 }
2552
2553                 /* The player can see the (on screen) missile */
2554                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
2555                 {
2556                         SYMBOL_CODE c = object_char(q_ptr);
2557                         TERM_COLOR a = object_attr(q_ptr);
2558
2559                         /* Draw, Hilite, Fresh, Pause, Erase */
2560                         print_rel(c, a, ny[cur_dis], nx[cur_dis]);
2561                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
2562                         Term_fresh();
2563                         Term_xtra(TERM_XTRA_DELAY, msec);
2564                         lite_spot(ny[cur_dis], nx[cur_dis]);
2565                         Term_fresh();
2566                 }
2567
2568                 /* The player cannot see the missile */
2569                 else
2570                 {
2571                         /* Pause anyway, for consistancy */
2572                         Term_xtra(TERM_XTRA_DELAY, msec);
2573                 }
2574
2575                 prev_y = y;
2576                 prev_x = x;
2577
2578                 /* Save the new location */
2579                 x = nx[cur_dis];
2580                 y = ny[cur_dis];
2581
2582                 /* Advance the distance */
2583                 cur_dis++;
2584
2585                 /* Monster here, Try to hit it */
2586                 if (current_floor_ptr->grid_array[y][x].m_idx)
2587                 {
2588                         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
2589                         monster_type *m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
2590                         GAME_TEXT m_name[MAX_NLEN];
2591                         monster_name(g_ptr->m_idx, m_name);
2592
2593                         /* Check the visibility */
2594                         visible = m_ptr->ml;
2595
2596                         /* Note the collision */
2597                         hit_body = TRUE;
2598
2599                         /* Did we hit it (penalize range) */
2600                         if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
2601                         {
2602                                 bool fear = FALSE;
2603
2604                                 /* Handle unseen monster */
2605                                 if (!visible)
2606                                 {
2607                                         /* Invisible monster */
2608                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
2609                                 }
2610
2611                                 /* Handle visible monster */
2612                                 else
2613                                 {
2614                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
2615
2616                                         if (m_ptr->ml)
2617                                         {
2618                                                 if (!creature_ptr->image) monster_race_track(m_ptr->ap_r_idx);
2619                                                 health_track(g_ptr->m_idx);
2620                                         }
2621                                 }
2622
2623                                 /* Hack -- Base damage from thrown object */
2624                                 dd = q_ptr->dd;
2625                                 ds = q_ptr->ds;
2626                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
2627                                 tdam = damroll(dd, ds);
2628                                 /* Apply special damage */
2629                                 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
2630                                 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
2631                                 if (q_ptr->to_d > 0)
2632                                         tdam += q_ptr->to_d;
2633                                 else
2634                                         tdam += -q_ptr->to_d;
2635
2636                                 if (boomerang)
2637                                 {
2638                                         tdam *= (mult+creature_ptr->num_blow[item - INVEN_RARM]);
2639                                         tdam += creature_ptr->to_d_m;
2640                                 }
2641                                 else if (have_flag(flgs, TR_THROW))
2642                                 {
2643                                         tdam *= (3+mult);
2644                                         tdam += creature_ptr->to_d_m;
2645                                 }
2646                                 else
2647                                 {
2648                                         tdam *= mult;
2649                                 }
2650                                 if (shuriken)
2651                                 {
2652                                         tdam += ((creature_ptr->lev+30)*(creature_ptr->lev+30)-900)/55;
2653                                 }
2654
2655                                 /* No negative damage */
2656                                 if (tdam < 0) tdam = 0;
2657
2658                                 /* Modify the damage */
2659                                 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
2660
2661                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
2662                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
2663
2664                                 /* Hit the monster, check for death */
2665                                 if (mon_take_hit(g_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr))))
2666                                 {
2667                                         /* Dead monster */
2668                                 }
2669
2670                                 /* No death */
2671                                 else
2672                                 {
2673                                         message_pain(g_ptr->m_idx, tdam);
2674
2675                                         /* Anger the monster */
2676                                         if ((tdam > 0) && !object_is_potion(q_ptr))
2677                                                 anger_monster(m_ptr);
2678
2679                                         if (fear && m_ptr->ml)
2680                                         {
2681                                                 sound(SOUND_FLEE);
2682                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
2683                                         }
2684                                 }
2685                         }
2686
2687                         /* Stop looking */
2688                         break;
2689                 }
2690         }
2691
2692         /* decrease toach's fuel */
2693         if (hit_body) torch_lost_fuel(q_ptr);
2694
2695         /* Chance of breakage (during attacks) */
2696         j = (hit_body ? breakage_chance(q_ptr, creature_ptr->pclass == CLASS_ARCHER, 0) : 0);
2697
2698         /* Figurines transform */
2699         if ((q_ptr->tval == TV_FIGURINE) && !(creature_ptr->inside_arena))
2700         {
2701                 j = 100;
2702
2703                 if (!(summon_named_creature(0, y, x, q_ptr->pval, !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
2704                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
2705                 else if (object_is_cursed(q_ptr))
2706                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
2707
2708         }
2709
2710         /* Potions smash open */
2711         if (object_is_potion(q_ptr))
2712         {
2713                 if (hit_body || hit_wall || (randint1(100) < j))
2714                 {
2715                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
2716
2717                         if (potion_smash_effect(0, y, x, q_ptr->k_idx))
2718                         {
2719                                 monster_type *m_ptr = &current_floor_ptr->m_list[current_floor_ptr->grid_array[y][x].m_idx];
2720                                 if (current_floor_ptr->grid_array[y][x].m_idx && is_friendly(m_ptr) && !MON_INVULNER(m_ptr))
2721                                 {
2722                                         GAME_TEXT m_name[MAX_NLEN];
2723                                         monster_desc(m_name, m_ptr, 0);
2724                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
2725                                         set_hostile(&current_floor_ptr->m_list[current_floor_ptr->grid_array[y][x].m_idx]);
2726                                 }
2727                         }
2728                         do_drop = FALSE;
2729                 }
2730                 else
2731                 {
2732                         j = 0;
2733                 }
2734         }
2735
2736         if (return_when_thrown)
2737         {
2738                 int back_chance = randint1(30)+20+((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
2739                 char o2_name[MAX_NLEN];
2740                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
2741
2742                 j = -1;
2743                 if (boomerang) back_chance += 4+randint1(5);
2744                 if (super_boomerang) back_chance += 100;
2745                 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2746
2747                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
2748                 {
2749                         for (i = cur_dis - 1; i > 0; i--)
2750                         {
2751                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
2752                                 {
2753                                         char c = object_char(q_ptr);
2754                                         byte a = object_attr(q_ptr);
2755
2756                                         /* Draw, Hilite, Fresh, Pause, Erase */
2757                                         print_rel(c, a, ny[i], nx[i]);
2758                                         move_cursor_relative(ny[i], nx[i]);
2759                                         Term_fresh();
2760                                         Term_xtra(TERM_XTRA_DELAY, msec);
2761                                         lite_spot(ny[i], nx[i]);
2762                                         Term_fresh();
2763                                 }
2764                                 else
2765                                 {
2766                                         /* Pause anyway, for consistancy */
2767                                         Term_xtra(TERM_XTRA_DELAY, msec);
2768                                 }
2769                         }
2770                         if((back_chance > 37) && !creature_ptr->blind && (item >= 0))
2771                         {
2772                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
2773                                 come_back = TRUE;
2774                         }
2775                         else
2776                         {
2777                                 if (item >= 0)
2778                                 {
2779                                         msg_format(_("%sを受け損ねた!", "%s backs, but you can't catch!"), o2_name);
2780                                 }
2781                                 else
2782                                 {
2783                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
2784                                 }
2785                                 y = creature_ptr->y;
2786                                 x = creature_ptr->x;
2787                         }
2788                 }
2789                 else
2790                 {
2791                         msg_format(_("%sが返ってこなかった!", "%s doesn't back!"), o2_name);
2792                 }
2793         }
2794
2795         if (come_back)
2796         {
2797                 if (item == INVEN_RARM || item == INVEN_LARM)
2798                 {
2799                         /* Access the wield slot */
2800                         o_ptr = &creature_ptr->inventory_list[item];
2801
2802                         /* Wear the new stuff */
2803                         object_copy(o_ptr, q_ptr);
2804
2805                         creature_ptr->total_weight += q_ptr->weight;
2806
2807                         /* Increment the equip counter by hand */
2808                         creature_ptr->equip_cnt++;
2809
2810                         creature_ptr->update |= (PU_BONUS | PU_TORCH | PU_MANA);
2811                         creature_ptr->window |= (PW_EQUIP);
2812                 }
2813                 else
2814                 {
2815                         inven_carry(q_ptr);
2816                 }
2817                 do_drop = FALSE;
2818         }
2819         else if (equiped_item)
2820         {
2821                 kamaenaoshi(item);
2822                 calc_android_exp(creature_ptr);
2823         }
2824
2825         if (do_drop)
2826         {
2827                 if (cave_have_flag_bold(y, x, FF_PROJECT))
2828                 {
2829                         (void)drop_near(q_ptr, j, y, x);
2830                 }
2831                 else
2832                 {
2833                         (void)drop_near(q_ptr, j, prev_y, prev_x);
2834                 }
2835         }
2836
2837         return TRUE;
2838 }
2839
2840 /*!
2841  * @brief 自殺するコマンドのメインルーチン
2842  * Hack -- commit suicide
2843  * @return なし
2844  * @details
2845  */
2846 void do_cmd_suicide(player_type *creature_ptr)
2847 {
2848         int i;
2849
2850         /* Flush input */
2851         flush();
2852
2853         /* Verify Retirement */
2854         if (creature_ptr->total_winner)
2855         {
2856                 /* Verify */
2857                 if (!get_check_strict(_("引退しますか? ", "Do you want to retire? "), CHECK_NO_HISTORY)) return;
2858         }
2859
2860         /* Verify Suicide */
2861         else
2862         {
2863                 /* Verify */
2864                 if (!get_check(_("本当に自殺しますか?", "Do you really want to commit suicide? "))) return;
2865         }
2866
2867
2868         if (!creature_ptr->noscore)
2869         {
2870                 /* Special Verification for suicide */
2871                 prt(_("確認のため '@' を押して下さい。", "Please verify SUICIDE by typing the '@' sign: "), 0, 0);
2872
2873                 flush();
2874                 i = inkey();
2875                 prt("", 0, 0);
2876                 if (i != '@') return;
2877
2878                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
2879         }
2880
2881         /* Initialize "last message" buffer */
2882         if (creature_ptr->last_message) string_free(creature_ptr->last_message);
2883         creature_ptr->last_message = NULL;
2884
2885         /* Hack -- Note *winning* message */
2886         if (creature_ptr->total_winner && last_words)
2887         {
2888                 char buf[1024] = "";
2889                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WINNER);
2890                 do
2891                 {
2892                         while (!get_string(_("*勝利*メッセージ: ", "*Winning* message: "), buf, sizeof buf));
2893                 } while (!get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
2894
2895                 if (buf[0])
2896                 {
2897                         creature_ptr->last_message = string_make(buf);
2898                         msg_print(creature_ptr->last_message);
2899                 }
2900         }
2901
2902         /* Stop playing */
2903         creature_ptr->playing = FALSE;
2904
2905         /* Kill the player */
2906         creature_ptr->is_dead = TRUE;
2907         creature_ptr->leaving = TRUE;
2908
2909         if (!creature_ptr->total_winner)
2910         {
2911                 exe_write_diary(creature_ptr, NIKKI_BUNSHOU, 0, _("ダンジョンの探索に絶望して自殺した。", "give up all hope to commit suicide."));
2912                 exe_write_diary(creature_ptr, NIKKI_GAMESTART, 1, _("-------- ゲームオーバー --------", "--------   Game  Over   --------"));
2913                 exe_write_diary(creature_ptr, NIKKI_BUNSHOU, 1, "\n\n\n\n");
2914         }
2915
2916         /* Cause of death */
2917         (void)strcpy(creature_ptr->died_from, _("途中終了", "Quitting"));
2918 }