OSDN Git Service

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