OSDN Git Service

[Refactor] #2683 Rebamed k_idx to bi_id (Kind index to Baseitem ID)
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-open-close.cpp
index a0f98d8..71300a7 100644 (file)
@@ -12,6 +12,9 @@
 #include "inventory/inventory-object.h"
 #include "inventory/inventory-slot-types.h"
 #include "io/input-key-requester.h"
+#include "object/tval-types.h"
+#include "player-base/player-class.h"
+#include "player-info/samurai-data-type.h"
 #include "player-status/player-energy.h"
 #include "player/attack-defense-types.h"
 #include "player/special-defense-types.h"
 #include "status/action-setter.h"
 #include "status/experience.h"
 #include "system/floor-type-definition.h"
-#include "system/object-type-definition.h"
+#include "system/grid-type-definition.h"
+#include "system/item-entity.h"
 #include "system/player-type-definition.h"
+#include "system/terrain-type-definition.h"
 #include "target/target-getter.h"
 #include "term/screen-processor.h"
+#include "timed-effect/player-blindness.h"
+#include "timed-effect/player-confusion.h"
+#include "timed-effect/player-hallucination.h"
+#include "timed-effect/timed-effects.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 
  * @details
  * Assume there is no monster blocking the destination
  */
-static bool exe_open_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
+static bool exe_open_chest(PlayerType *player_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
 {
-    bool flag = TRUE;
-    bool more = FALSE;
-    object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
-    PlayerEnergy(creature_ptr).set_player_turn_energy(100);
+    bool flag = true;
+    bool more = false;
+    auto *o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
+    PlayerEnergy(player_ptr).set_player_turn_energy(100);
     if (o_ptr->pval > 0) {
-        flag = FALSE;
-        int i = creature_ptr->skill_dis;
-        if (creature_ptr->blind || no_lite(creature_ptr))
+        flag = false;
+        int i = player_ptr->skill_dis;
+        const auto effects = player_ptr->effects();
+        if (effects->blindness()->is_blind() || no_lite(player_ptr)) {
             i = i / 10;
+        }
 
-        if (creature_ptr->confused || creature_ptr->image)
+        if (effects->confusion()->is_confused() || effects->hallucination()->is_hallucinated()) {
             i = i / 10;
+        }
 
         int j = i - o_ptr->pval;
-        if (j < 2)
+        if (j < 2) {
             j = 2;
+        }
 
         if (randint0(100) < j) {
             msg_print(_("鍵をはずした。", "You have picked the lock."));
-            gain_exp(creature_ptr, 1);
-            flag = TRUE;
+            gain_exp(player_ptr, 1);
+            flag = true;
         } else {
-            more = TRUE;
-            if (flush_failure)
+            more = true;
+            if (flush_failure) {
                 flush();
+            }
 
             msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
         }
     }
 
     if (flag) {
-        chest_trap(creature_ptr, y, x, o_idx);
-        chest_death(creature_ptr, FALSE, y, x, o_idx);
+        Chest chest(player_ptr);
+        chest.chest_trap(y, x, o_idx);
+        chest.chest_death(false, y, x, o_idx);
     }
 
     return more;
@@ -82,57 +97,59 @@ static bool exe_open_chest(player_type *creature_ptr, POSITION y, POSITION x, OB
  * @details
  * Unlocking a locked door/chest is worth one experience point.
  */
-void do_cmd_open(player_type *creature_ptr)
+void do_cmd_open(PlayerType *player_ptr)
 {
     POSITION y, x;
     DIRECTION dir;
     OBJECT_IDX o_idx;
-    bool more = FALSE;
-    if (creature_ptr->wild_mode)
+    bool more = false;
+    if (player_ptr->wild_mode) {
         return;
+    }
 
-    if (creature_ptr->special_defense & KATA_MUSOU)
-        set_action(creature_ptr, ACTION_NONE);
+    PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
     if (easy_open) {
-        int num_doors = count_dt(creature_ptr, &y, &x, is_closed_door, FALSE);
-        int num_chests = count_chests(creature_ptr, &y, &x, FALSE);
+        int num_doors = count_dt(player_ptr, &y, &x, is_closed_door, false);
+        int num_chests = count_chests(player_ptr, &y, &x, false);
         if (num_doors || num_chests) {
             bool too_many = (num_doors && num_chests) || (num_doors > 1) || (num_chests > 1);
-            if (!too_many)
-                command_dir = coords_to_dir(creature_ptr, y, x);
+            if (!too_many) {
+                command_dir = coords_to_dir(player_ptr, y, x);
+            }
         }
     }
 
     if (command_arg) {
         command_rep = command_arg - 1;
-        creature_ptr->redraw |= PR_STATE;
+        player_ptr->redraw |= PR_STATE;
         command_arg = 0;
     }
 
-    if (get_rep_dir(creature_ptr, &dir, TRUE)) {
+    if (get_rep_dir(player_ptr, &dir, true)) {
         FEAT_IDX feat;
         grid_type *g_ptr;
-        y = creature_ptr->y + ddy[dir];
-        x = creature_ptr->x + ddx[dir];
-        g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
-        feat = get_feat_mimic(g_ptr);
-        o_idx = chest_check(creature_ptr->current_floor_ptr, y, x, FALSE);
-        if (!has_flag(f_info[feat].flags, FF_OPEN) && !o_idx) {
+        y = player_ptr->y + ddy[dir];
+        x = player_ptr->x + ddx[dir];
+        g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
+        feat = g_ptr->get_feat_mimic();
+        o_idx = chest_check(player_ptr->current_floor_ptr, y, x, false);
+        if (terrains_info[feat].flags.has_not(TerrainCharacteristics::OPEN) && !o_idx) {
             msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
-        } else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx) {
-            PlayerEnergy(creature_ptr).set_player_turn_energy(100);
+        } else if (g_ptr->m_idx && player_ptr->riding != g_ptr->m_idx) {
+            PlayerEnergy(player_ptr).set_player_turn_energy(100);
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
-            do_cmd_attack(creature_ptr, y, x, HISSATSU_NONE);
+            do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
         } else if (o_idx) {
-            more = exe_open_chest(creature_ptr, y, x, o_idx);
+            more = exe_open_chest(player_ptr, y, x, o_idx);
         } else {
-            more = exe_open(creature_ptr, y, x);
+            more = exe_open(player_ptr, y, x);
         }
     }
 
-    if (!more)
-        disturb(creature_ptr, FALSE, FALSE);
+    if (!more) {
+        disturb(player_ptr, false, false);
+    }
 }
 
 /*!
@@ -141,102 +158,106 @@ void do_cmd_open(player_type *creature_ptr)
  * @details
  * Unlocking a locked door/chest is worth one experience point.
  */
-void do_cmd_close(player_type *creature_ptr)
+void do_cmd_close(PlayerType *player_ptr)
 {
     POSITION y, x;
     DIRECTION dir;
-    bool more = FALSE;
-    if (creature_ptr->wild_mode)
+    bool more = false;
+    if (player_ptr->wild_mode) {
         return;
+    }
 
-    if (creature_ptr->special_defense & KATA_MUSOU)
-        set_action(creature_ptr, ACTION_NONE);
+    PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
-    if (easy_open && (count_dt(creature_ptr, &y, &x, is_open, FALSE) == 1))
-        command_dir = coords_to_dir(creature_ptr, y, x);
+    if (easy_open && (count_dt(player_ptr, &y, &x, is_open, false) == 1)) {
+        command_dir = coords_to_dir(player_ptr, y, x);
+    }
 
     if (command_arg) {
         command_rep = command_arg - 1;
-        creature_ptr->redraw |= (PR_STATE);
+        player_ptr->redraw |= (PR_STATE);
         command_arg = 0;
     }
 
-    if (get_rep_dir(creature_ptr, &dir, FALSE)) {
+    if (get_rep_dir(player_ptr, &dir, false)) {
         grid_type *g_ptr;
         FEAT_IDX feat;
-        y = creature_ptr->y + ddy[dir];
-        x = creature_ptr->x + ddx[dir];
-        g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
-        feat = get_feat_mimic(g_ptr);
-        if (!has_flag(f_info[feat].flags, FF_CLOSE)) {
+        y = player_ptr->y + ddy[dir];
+        x = player_ptr->x + ddx[dir];
+        g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
+        feat = g_ptr->get_feat_mimic();
+        if (terrains_info[feat].flags.has_not(TerrainCharacteristics::CLOSE)) {
             msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
         } else if (g_ptr->m_idx) {
-            PlayerEnergy(creature_ptr).set_player_turn_energy(100);
+            PlayerEnergy(player_ptr).set_player_turn_energy(100);
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
-            do_cmd_attack(creature_ptr, y, x, HISSATSU_NONE);
+            do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
         } else {
-            more = exe_close(creature_ptr, y, x);
+            more = exe_close(player_ptr, y, x);
         }
     }
 
-    if (!more)
-        disturb(creature_ptr, FALSE, FALSE);
+    if (!more) {
+        disturb(player_ptr, false, false);
+    }
 }
 
 /*!
  * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
  * Disarms a trap, or chest
  */
-void do_cmd_disarm(player_type *creature_ptr)
+void do_cmd_disarm(PlayerType *player_ptr)
 {
     POSITION y, x;
     DIRECTION dir;
     OBJECT_IDX o_idx;
-    bool more = FALSE;
-    if (creature_ptr->wild_mode)
+    bool more = false;
+    if (player_ptr->wild_mode) {
         return;
+    }
 
-    if (creature_ptr->special_defense & KATA_MUSOU)
-        set_action(creature_ptr, ACTION_NONE);
+    PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
     if (easy_disarm) {
-        int num_traps = count_dt(creature_ptr, &y, &x, is_trap, TRUE);
-        int num_chests = count_chests(creature_ptr, &y, &x, TRUE);
+        int num_traps = count_dt(player_ptr, &y, &x, is_trap, true);
+        int num_chests = count_chests(player_ptr, &y, &x, true);
         if (num_traps || num_chests) {
             bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
-            if (!too_many)
-                command_dir = coords_to_dir(creature_ptr, y, x);
+            if (!too_many) {
+                command_dir = coords_to_dir(player_ptr, y, x);
+            }
         }
     }
 
     if (command_arg) {
         command_rep = command_arg - 1;
-        creature_ptr->redraw |= (PR_STATE);
+        player_ptr->redraw |= (PR_STATE);
         command_arg = 0;
     }
 
-    if (get_rep_dir(creature_ptr, &dir, TRUE)) {
+    if (get_rep_dir(player_ptr, &dir, true)) {
         grid_type *g_ptr;
         FEAT_IDX feat;
-        y = creature_ptr->y + ddy[dir];
-        x = creature_ptr->x + ddx[dir];
-        g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
-        feat = get_feat_mimic(g_ptr);
-        o_idx = chest_check(creature_ptr->current_floor_ptr, y, x, TRUE);
-        if (!is_trap(creature_ptr, feat) && !o_idx) {
+        y = player_ptr->y + ddy[dir];
+        x = player_ptr->x + ddx[dir];
+        g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
+        feat = g_ptr->get_feat_mimic();
+        o_idx = chest_check(player_ptr->current_floor_ptr, y, x, true);
+        if (!is_trap(player_ptr, feat) && !o_idx) {
             msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
-        } else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx) {
+        } else if (g_ptr->m_idx && player_ptr->riding != g_ptr->m_idx) {
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
-            do_cmd_attack(creature_ptr, y, x, HISSATSU_NONE);
+            do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
         } else if (o_idx) {
-            more = exe_disarm_chest(creature_ptr, y, x, o_idx);
+            more = exe_disarm_chest(player_ptr, y, x, o_idx);
         } else {
-            more = exe_disarm(creature_ptr, y, x, dir);
+            more = exe_disarm(player_ptr, y, x, dir);
         }
     }
 
-    if (!more)
-        disturb(creature_ptr, FALSE, FALSE);
+    if (!more) {
+        disturb(player_ptr, false, false);
+    }
 }
 
 /*!
@@ -256,46 +277,46 @@ void do_cmd_disarm(player_type *creature_ptr)
  * Creatures can also open or bash doors, see elsewhere.
  * </pre>
  */
-void do_cmd_bash(player_type *creature_ptr)
+void do_cmd_bash(PlayerType *player_ptr)
 {
     POSITION y, x;
     DIRECTION dir;
     grid_type *g_ptr;
-    bool more = FALSE;
-    if (creature_ptr->wild_mode)
+    bool more = false;
+    if (player_ptr->wild_mode) {
         return;
+    }
 
-    if (creature_ptr->special_defense & KATA_MUSOU)
-        set_action(creature_ptr, ACTION_NONE);
+    PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
     if (command_arg) {
         command_rep = command_arg - 1;
-        creature_ptr->redraw |= (PR_STATE);
+        player_ptr->redraw |= (PR_STATE);
         command_arg = 0;
     }
 
-    if (get_rep_dir(creature_ptr, &dir, FALSE)) {
+    if (get_rep_dir(player_ptr, &dir, false)) {
         FEAT_IDX feat;
-        y = creature_ptr->y + ddy[dir];
-        x = creature_ptr->x + ddx[dir];
-        g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
-        feat = get_feat_mimic(g_ptr);
-        if (!has_flag(f_info[feat].flags, FF_BASH)) {
+        y = player_ptr->y + ddy[dir];
+        x = player_ptr->x + ddx[dir];
+        g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
+        feat = g_ptr->get_feat_mimic();
+        if (terrains_info[feat].flags.has_not(TerrainCharacteristics::BASH)) {
             msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
         } else if (g_ptr->m_idx) {
-            PlayerEnergy(creature_ptr).set_player_turn_energy(100);
+            PlayerEnergy(player_ptr).set_player_turn_energy(100);
             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
-            do_cmd_attack(creature_ptr, y, x, HISSATSU_NONE);
+            do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
         } else {
-            more = exe_bash(creature_ptr, y, x, dir);
+            more = exe_bash(player_ptr, y, x, dir);
         }
     }
 
-    if (!more)
-        disturb(creature_ptr, FALSE, FALSE);
+    if (!more) {
+        disturb(player_ptr, false, false);
+    }
 }
 
-
 /*!
  * @brief 「くさびを打つ」ために必要なオブジェクトを所持しているかどうかの判定を返す /
  * Find the index of some "spikes", if possible.
@@ -306,61 +327,63 @@ void do_cmd_bash(player_type *creature_ptr)
  * Let user choose a pile of spikes, perhaps?
  * </pre>
  */
-static bool get_spike(player_type *creature_ptr, INVENTORY_IDX *ip)
+static bool get_spike(PlayerType *player_ptr, INVENTORY_IDX *ip)
 {
     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
-        object_type *o_ptr = &creature_ptr->inventory_list[i];
-        if (!o_ptr->k_idx)
+        auto *o_ptr = &player_ptr->inventory_list[i];
+        if (!o_ptr->bi_id) {
             continue;
+        }
 
-        if (o_ptr->tval == TV_SPIKE) {
+        if (o_ptr->tval == ItemKindType::SPIKE) {
             *ip = i;
-            return TRUE;
+            return true;
         }
     }
 
-    return FALSE;
+    return false;
 }
 
 /*!
  * @brief 「くさびを打つ」動作コマンドのメインルーチン /
  * Jam a closed door with a spike
- * @param creature_ptr プレーヤーへの参照ポインタ
+ * @param player_ptr プレイヤーへの参照ポインタ
  * @details
  * <pre>
  * This command may NOT be repeated
  * </pre>
  */
-void do_cmd_spike(player_type *creature_ptr)
+void do_cmd_spike(PlayerType *player_ptr)
 {
     DIRECTION dir;
-    if (creature_ptr->wild_mode)
+    if (player_ptr->wild_mode) {
         return;
+    }
 
-    if (creature_ptr->special_defense & KATA_MUSOU)
-        set_action(creature_ptr, ACTION_NONE);
+    PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
-    if (!get_rep_dir(creature_ptr, &dir, FALSE))
+    if (!get_rep_dir(player_ptr, &dir, false)) {
         return;
+    }
 
-    POSITION y = creature_ptr->y + ddy[dir];
-    POSITION x = creature_ptr->x + ddx[dir];
+    POSITION y = player_ptr->y + ddy[dir];
+    POSITION x = player_ptr->x + ddx[dir];
     grid_type *g_ptr;
-    g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
-    FEAT_IDX feat = get_feat_mimic(g_ptr);
+    g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
+    FEAT_IDX feat = g_ptr->get_feat_mimic();
     INVENTORY_IDX item;
-    if (!has_flag(f_info[feat].flags, FF_SPIKE)) {
+    if (terrains_info[feat].flags.has_not(TerrainCharacteristics::SPIKE)) {
         msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
-    } else if (!get_spike(creature_ptr, &item)) {
+    } else if (!get_spike(player_ptr, &item)) {
         msg_print(_("くさびを持っていない!", "You have no spikes!"));
     } else if (g_ptr->m_idx) {
-        PlayerEnergy(creature_ptr).set_player_turn_energy(100);
+        PlayerEnergy(player_ptr).set_player_turn_energy(100);
         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
-        do_cmd_attack(creature_ptr, y, x, HISSATSU_NONE);
+        do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
     } else {
-        PlayerEnergy(creature_ptr).set_player_turn_energy(100);
-        msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_info[feat].name.c_str());
-        cave_alter_feat(creature_ptr, y, x, FF_SPIKE);
-        vary_item(creature_ptr, item, -1);
+        PlayerEnergy(player_ptr).set_player_turn_energy(100);
+        msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), terrains_info[feat].name.data());
+        cave_alter_feat(player_ptr, y, x, TerrainCharacteristics::SPIKE);
+        vary_item(player_ptr, item, -1);
     }
 }