OSDN Git Service

[Refactor] #38997 set_stun(), set_oppose_pois() に player_type * 引数を追加.
[hengband/hengband.git] / src / cmd-basic.c
index cf16bd1..07ae5ea 100644 (file)
@@ -13,6 +13,7 @@
 #include "angband.h"
 #include "util.h"
 #include "core.h"
+#include "term.h"
 
 #include "cmd-dump.h"
 #include "chest.h"
 #include "avatar.h"
 #include "player-status.h"
 #include "realm-hex.h"
+#include "realm-song.h"
 #include "geometry.h"
 #include "wild.h"
 #include "grid.h"
 #include "feature.h"
 #include "player-move.h"
 #include "player-effects.h"
+#include "player-class.h"
+#include "player-personality.h"
 #include "objectkind.h"
 #include "object-broken.h"
 #include "object-flavor.h"
 #include "shoot.h"
+#include "snipe.h"
 
 #include "cmd-basic.h"
 #include "cmd-item.h"
  * @param down_stair TRUEならば階段を降りる処理、FALSEなら階段を昇る処理による内容
  * @return フロア移動を実際に行うならTRUE、キャンセルする場合はFALSE
  */
-static bool confirm_leave_level(bool down_stair)
+static bool confirm_leave_level(player_type *creature_ptr, bool down_stair)
 {
-       quest_type *q_ptr = &quest[p_ptr->inside_quest];
+       quest_type *q_ptr = &quest[creature_ptr->inside_quest];
 
        /* Confirm leaving from once only quest */
-       if (confirm_quest && p_ptr->inside_quest &&
+       if (confirm_quest && creature_ptr->inside_quest &&
            (q_ptr->type == QUEST_TYPE_RANDOM ||
             (q_ptr->flags & QUEST_FLAG_ONCE &&
                                                q_ptr->status != QUEST_STATUS_COMPLETED) ||
@@ -156,7 +161,7 @@ bool cmd_limit_blind(player_type *creature_ptr)
        }
        if (no_lite())
        {
-               msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
+               msg_print(_("明かりがないので見えない。", "You have no light."));
                return TRUE;
        }
        return FALSE;
@@ -178,17 +183,17 @@ bool cmd_limit_time_walk(player_type *creature_ptr)
  * @brief 階段を使って階層を昇る処理 / Go up one level
  * @return なし
  */
-void do_cmd_go_up(void)
+void do_cmd_go_up(player_type *creature_ptr)
 {
        bool go_up = FALSE;
 
        /* Player grid */
-       grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
        feature_type *f_ptr = &f_info[g_ptr->feat];
 
        int up_num = 0;
 
-       if (p_ptr->special_defense & KATA_MUSOU)
+       if (creature_ptr->special_defense & KATA_MUSOU)
        {
                set_action(ACTION_NONE);
        }
@@ -203,42 +208,40 @@ void do_cmd_go_up(void)
        /* Quest up stairs */
        if (have_flag(f_ptr->flags, FF_QUEST))
        {
-               /* Cancel the command */
-               if (!confirm_leave_level(FALSE)) return;
+               if (!confirm_leave_level(creature_ptr, FALSE)) return;
        
-               
                /* Success */
-               if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
+               if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
                        msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
                else
                        msg_print(_("上の階に登った。", "You enter the up staircase."));
 
                leave_quest_check();
 
-               p_ptr->inside_quest = g_ptr->special;
+               creature_ptr->inside_quest = g_ptr->special;
 
                /* Activate the quest */
-               if (!quest[p_ptr->inside_quest].status)
+               if (!quest[creature_ptr->inside_quest].status)
                {
-                       if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
+                       if (quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
                        {
                                init_flags = INIT_ASSIGN;
                                process_dungeon_file("q_info.txt", 0, 0, 0, 0);
                        }
-                       quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
+                       quest[creature_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
                }
 
                /* Leaving a quest */
-               if (!p_ptr->inside_quest)
+               if (!creature_ptr->inside_quest)
                {
                        current_floor_ptr->dun_level = 0;
                }
-               p_ptr->leaving = TRUE;
+               creature_ptr->leaving = TRUE;
 
-               p_ptr->oldpx = 0;
-               p_ptr->oldpy = 0;
+               creature_ptr->oldpx = 0;
+               creature_ptr->oldpy = 0;
                
-               take_turn(p_ptr, 100);
+               take_turn(creature_ptr, 100);
 
                /* End the command */
                return;
@@ -250,32 +253,31 @@ void do_cmd_go_up(void)
        }
        else
        {
-               go_up = confirm_leave_level(FALSE);
+               go_up = confirm_leave_level(creature_ptr, FALSE);
        }
 
-       /* Cancel the command */
        if (!go_up) return;
 
-       take_turn(p_ptr, 100);
+       take_turn(creature_ptr, 100);
 
        if (autosave_l) do_cmd_save_game(TRUE);
 
        /* For a random quest */
-       if (p_ptr->inside_quest &&
-           quest[p_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
+       if (creature_ptr->inside_quest &&
+           quest[creature_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
        {
                leave_quest_check();
 
-               p_ptr->inside_quest = 0;
+               creature_ptr->inside_quest = 0;
        }
 
        /* For a fixed quest */
-       if (p_ptr->inside_quest &&
-           quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
+       if (creature_ptr->inside_quest &&
+           quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
        {
                leave_quest_check();
 
-               p_ptr->inside_quest = g_ptr->special;
+               creature_ptr->inside_quest = g_ptr->special;
                current_floor_ptr->dun_level = 0;
                up_num = 0;
        }
@@ -300,19 +302,19 @@ void do_cmd_go_up(void)
                }
 
                /* Get out from current dungeon */
-               if (current_floor_ptr->dun_level - up_num < d_info[p_ptr->dungeon_idx].mindepth)
+               if (current_floor_ptr->dun_level - up_num < d_info[creature_ptr->dungeon_idx].mindepth)
                        up_num = current_floor_ptr->dun_level;
        }
        if (record_stair) do_cmd_write_nikki(NIKKI_STAIR, 0-up_num, _("階段を上った", "climbed up the stairs to"));
 
        /* Success */
-       if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
+       if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
                msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
        else if (up_num == current_floor_ptr->dun_level)
                msg_print(_("地上に戻った。", "You go back to the surface."));
        else
                msg_print(_("階段を上って新たなる迷宮へと足を踏み入れた。", "You enter a maze of up staircases."));
-       p_ptr->leaving = TRUE;
+       creature_ptr->leaving = TRUE;
 }
 
 
@@ -320,16 +322,16 @@ void do_cmd_go_up(void)
  * @brief 階段を使って階層を降りる処理 / Go down one level
  * @return なし
  */
-void do_cmd_go_down(void)
+void do_cmd_go_down(player_type *creature_ptr)
 {
        /* Player grid */
-       grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
        feature_type *f_ptr = &f_info[g_ptr->feat];
 
        bool fall_trap = FALSE;
        int down_num = 0;
 
-       if (p_ptr->special_defense & KATA_MUSOU)
+       if (creature_ptr->special_defense & KATA_MUSOU)
        {
                set_action(ACTION_NONE);
        }
@@ -353,9 +355,9 @@ void do_cmd_go_down(void)
        else if (have_flag(f_ptr->flags, FF_QUEST))
        {
                /* Confirm Leaving */
-               if(!confirm_leave_level(TRUE)) return;
+               if(!confirm_leave_level(creature_ptr, TRUE)) return;
                
-               if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
+               if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
                        msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
                else
                        msg_print(_("下の階に降りた。", "You enter the down staircase."));
@@ -363,29 +365,29 @@ void do_cmd_go_down(void)
                leave_quest_check();
                leave_tower_check();
 
-               p_ptr->inside_quest = g_ptr->special;
+               creature_ptr->inside_quest = g_ptr->special;
 
                /* Activate the quest */
-               if (!quest[p_ptr->inside_quest].status)
+               if (!quest[creature_ptr->inside_quest].status)
                {
-                       if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
+                       if (quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
                        {
                                init_flags = INIT_ASSIGN;
                                process_dungeon_file("q_info.txt", 0, 0, 0, 0);
                        }
-                       quest[p_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
+                       quest[creature_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
                }
 
                /* Leaving a quest */
-               if (!p_ptr->inside_quest)
+               if (!creature_ptr->inside_quest)
                {
                        current_floor_ptr->dun_level = 0;
                }
-               p_ptr->leaving = TRUE;
-               p_ptr->oldpx = 0;
-               p_ptr->oldpy = 0;
+               creature_ptr->leaving = TRUE;
+               creature_ptr->oldpx = 0;
+               creature_ptr->oldpy = 0;
                
-               take_turn(p_ptr, 100);
+               take_turn(creature_ptr, 100);
        }
 
        else
@@ -409,9 +411,9 @@ void do_cmd_go_down(void)
                        }
 
                        /* Save old player position */
-                       p_ptr->oldpx = p_ptr->x;
-                       p_ptr->oldpy = p_ptr->y;
-                       p_ptr->dungeon_idx = target_dungeon;
+                       creature_ptr->oldpx = creature_ptr->x;
+                       creature_ptr->oldpy = creature_ptr->y;
+                       creature_ptr->dungeon_idx = target_dungeon;
 
                        /*
                         * Clear all saved floors
@@ -420,7 +422,7 @@ void do_cmd_go_down(void)
                        prepare_change_floor_mode(CFM_FIRST_FLOOR);
                }
 
-               take_turn(p_ptr, 100);
+               take_turn(creature_ptr, 100);
 
                if (autosave_l) do_cmd_save_game(TRUE);
 
@@ -431,8 +433,8 @@ void do_cmd_go_down(void)
                if (!current_floor_ptr->dun_level)
                {
                        /* Enter the dungeon just now */
-                       p_ptr->enter_dungeon = TRUE;
-                       down_num = d_info[p_ptr->dungeon_idx].mindepth;
+                       creature_ptr->enter_dungeon = TRUE;
+                       down_num = d_info[creature_ptr->dungeon_idx].mindepth;
                }
 
                if (record_stair)
@@ -450,18 +452,18 @@ void do_cmd_go_down(void)
                        /* Success */
                        if (target_dungeon)
                        {
-                               msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[p_ptr->dungeon_idx].text);
+                               msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[creature_ptr->dungeon_idx].text);
                        }
                        else
                        {
-                               if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
+                               if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
                                        msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
                                else
                                        msg_print(_("階段を下りて新たなる迷宮へと足を踏み入れた。", "You enter a maze of down staircases."));
                        }
                }
 
-               p_ptr->leaving = TRUE;
+               creature_ptr->leaving = TRUE;
 
                if (fall_trap)
                {
@@ -488,22 +490,21 @@ void do_cmd_go_down(void)
  * @brief 探索コマンドのメインルーチン / Simple command to "search" for one current_world_ptr->game_turn
  * @return なし
  */
-void do_cmd_search(void)
+void do_cmd_search(player_type * creature_ptr)
 {
        /* Allow repeated command */
        if (command_arg)
        {
                /* Set repeat count */
                command_rep = command_arg - 1;
-               p_ptr->redraw |= (PR_STATE);
+               creature_ptr->redraw |= (PR_STATE);
 
                /* Cancel the arg */
                command_arg = 0;
        }
-       take_turn(p_ptr, 100);
+       take_turn(creature_ptr, 100);
 
-       /* Search */
-       search();
+       search(creature_ptr);
 }
 
 
@@ -542,7 +543,7 @@ static OBJECT_IDX chest_check(POSITION y, POSITION x, bool trapped)
 }
 
 /*!
- * @brief 箱を開けるコマンドのメインルーチン /
+ * @brief 箱を開ける実行処理 /
  * Attempt to open the given chest at the given location
  * @param y 箱の存在するマスのY座標
  * @param x 箱の存在するマスのX座標
@@ -551,14 +552,14 @@ static OBJECT_IDX chest_check(POSITION y, POSITION x, bool trapped)
  * @details
  * Assume there is no monster blocking the destination
  */
-static bool do_cmd_open_chest(POSITION y, POSITION x, OBJECT_IDX o_idx)
+static bool exe_open_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
 {
        int i, j;
        bool flag = TRUE;
        bool more = FALSE;
        object_type *o_ptr = &current_floor_ptr->o_list[o_idx];
 
-       take_turn(p_ptr, 100);
+       take_turn(creature_ptr, 100);
 
        /* Attempt to unlock it */
        if (o_ptr->pval > 0)
@@ -567,11 +568,11 @@ static bool do_cmd_open_chest(POSITION y, POSITION x, OBJECT_IDX o_idx)
                flag = FALSE;
 
                /* Get the "disarm" factor */
-               i = p_ptr->skill_dis;
+               i = creature_ptr->skill_dis;
 
                /* Penalize some conditions */
-               if (p_ptr->blind || no_lite()) i = i / 10;
-               if (p_ptr->confused || p_ptr->image) i = i / 10;
+               if (creature_ptr->blind || no_lite()) i = i / 10;
+               if (creature_ptr->confused || creature_ptr->image) i = i / 10;
 
                /* Extract the difficulty */
                j = i - o_ptr->pval;
@@ -678,7 +679,7 @@ static int count_dt(POSITION *y, POSITION *x, bool (*test)(FEAT_IDX feat), bool
  * @details
  * If requested, count only trapped chests.
  */
-static int count_chests(POSITION *y, POSITION *x, bool trapped)
+static int count_chests(player_type *creature_ptr, POSITION *y, POSITION *x, bool trapped)
 {
        DIRECTION d;
        int count;
@@ -692,8 +693,8 @@ static int count_chests(POSITION *y, POSITION *x, bool trapped)
        for (d = 0; d < 9; d++)
        {
                /* Extract adjacent (legal) location */
-               POSITION yy = p_ptr->y + ddy_ddd[d];
-               POSITION xx = p_ptr->x + ddx_ddd[d];
+               POSITION yy = creature_ptr->y + ddy_ddd[d];
+               POSITION xx = creature_ptr->x + ddx_ddd[d];
 
                /* No (visible) chest is there */
                if ((o_idx = chest_check(yy, xx, FALSE)) == 0) continue;
@@ -817,7 +818,7 @@ static bool do_cmd_open_aux(POSITION y, POSITION x)
  * @details
  * Unlocking a locked door/chest is worth one experience point.
  */
-void do_cmd_open(void)
+void do_cmd_open(player_type *creature_ptr)
 {
        POSITION y, x;
        DIRECTION dir;
@@ -825,9 +826,9 @@ void do_cmd_open(void)
 
        bool more = FALSE;
 
-       if (p_ptr->wild_mode) return;
+       if (creature_ptr->wild_mode) return;
 
-       if (p_ptr->special_defense & KATA_MUSOU)
+       if (creature_ptr->special_defense & KATA_MUSOU)
        {
                set_action(ACTION_NONE);
        }
@@ -837,13 +838,8 @@ void do_cmd_open(void)
        {
                int num_doors, num_chests;
 
-               /* Count closed doors (locked or jammed) */
                num_doors = count_dt(&y, &x, is_closed_door, FALSE);
-
-               /* Count chests (locked) */
-               num_chests = count_chests(&y, &x, FALSE);
-
-               /* See if only one target */
+               num_chests = count_chests(creature_ptr, &y, &x, FALSE);
                if (num_doors || num_chests)
                {
                        bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
@@ -857,7 +853,7 @@ void do_cmd_open(void)
        {
                /* Set repeat count */
                command_rep = command_arg - 1;
-               p_ptr->redraw |= (PR_STATE);
+               creature_ptr->redraw |= (PR_STATE);
 
                /* Cancel the arg */
                command_arg = 0;
@@ -870,8 +866,8 @@ void do_cmd_open(void)
                grid_type *g_ptr;
 
                /* Get requested location */
-               y = p_ptr->y + ddy[dir];
-               x = p_ptr->x + ddx[dir];
+               y = creature_ptr->y + ddy[dir];
+               x = creature_ptr->x + ddx[dir];
 
                /* Get requested grid */
                g_ptr = &current_floor_ptr->grid_array[y][x];
@@ -882,31 +878,22 @@ void do_cmd_open(void)
                /* Check for chest */
                o_idx = chest_check(y, x, FALSE);
 
-               /* Nothing useful */
                if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
                {
                        msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
                }
-
-               /* Monster in the way */
-               else if (g_ptr->m_idx && p_ptr->riding != g_ptr->m_idx)
+               else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
                {
-                       take_turn(p_ptr, 100);
+                       take_turn(creature_ptr, 100);
                        msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
                        py_attack(y, x, 0);
                }
-
-               /* Handle chests */
                else if (o_idx)
                {
-                       /* Open the chest */
-                       more = do_cmd_open_chest(y, x, o_idx);
+                       more = exe_open_chest(creature_ptr, y, x, o_idx);
                }
-
-               /* Handle doors */
                else
                {
-                       /* Open the door */
                        more = do_cmd_open_aux(y, x);
                }
        }
@@ -1187,7 +1174,7 @@ static bool do_cmd_tunnel_aux(POSITION y, POSITION x)
                                /* We may continue chopping */
                                msg_format(_("%sを切っている。", "You chop away at the %s."), name);
                                /* Occasional Search XXX XXX */
-                               if (randint0(100) < 25) search();
+                               if (randint0(100) < 25) search(p_ptr);
                        }
                        else
                        {
@@ -1202,7 +1189,7 @@ static bool do_cmd_tunnel_aux(POSITION y, POSITION x)
        if (is_hidden_door(g_ptr))
        {
                /* Occasional Search XXX XXX */
-               if (randint0(100) < 25) search();
+               if (randint0(100) < 25) search(p_ptr);
        }
        return more;
 }
@@ -1577,7 +1564,7 @@ void do_cmd_disarm(void)
                num_traps = count_dt(&y, &x, is_trap, TRUE);
 
                /* Count chests (trapped) */
-               num_chests = count_chests(&y, &x, TRUE);
+               num_chests = count_chests(p_ptr, &y, &x, TRUE);
 
                /* See if only one target */
                if (num_traps || num_chests)
@@ -1731,7 +1718,7 @@ static bool do_cmd_bash_aux(POSITION y, POSITION x, DIRECTION dir)
                msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
 
                /* Hack -- Lose balance ala paralysis */
-               (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
+               (void)set_paralyzed(p_ptr, p_ptr->paralyzed + 2 + randint0(2));
        }
        return (more);
 }
@@ -2298,14 +2285,10 @@ void do_cmd_fire(SPELL_IDX snipe_type)
                set_action(ACTION_NONE);
        }
 
-       /* Require proper missile */
-       item_tester_tval = p_ptr->tval_ammo;
-
        q = _("どれを撃ちますか? ", "Fire which item? ");
        s = _("発射されるアイテムがありません。", "You have nothing to fire.");
 
-
-       ammo_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
+       ammo_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR), p_ptr->tval_ammo);
        if (!ammo_ptr)
        {
                flush();
@@ -2325,8 +2308,8 @@ void do_cmd_fire(SPELL_IDX snipe_type)
        if (snipe_type == SP_FINAL)
        {
                msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
-               (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
-               (void)set_stun(p_ptr->stun + randint1(25));
+               (void)set_slow(p_ptr, p_ptr->slow + randint0(7) + 7, FALSE);
+               (void)set_stun(p_ptr, p_ptr->stun + randint1(25));
        }
 }
 
@@ -2396,7 +2379,7 @@ bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
                        item_tester_hook = item_tester_hook_boomerang;
                        q = _("どの武器を投げますか? ", "Throw which item? ");
                        s = _("投げる武器がない。", "You have nothing to throw.");
-                       o_ptr = choose_object(&item, q, s, (USE_EQUIP));
+                       o_ptr = choose_object(&item, q, s, (USE_EQUIP), 0);
                        if (!o_ptr)
                        {
                                flush();
@@ -2418,7 +2401,7 @@ bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
        {
                q = _("どのアイテムを投げますか? ", "Throw which item? ");
                s = _("投げるアイテムがない。", "You have nothing to throw.");
-               o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP));
+               o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP), 0);
                if (!o_ptr)
                {
                        flush();
@@ -2445,8 +2428,6 @@ bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
 
        }
        q_ptr = &forge;
-
-       /* Obtain a local object */
        object_copy(q_ptr, o_ptr);
 
        /* Extract the thrown object's flags. */