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 26bddc0..71300a7 100644 (file)
 #include "status/experience.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
-#include "system/object-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"
 
@@ -44,20 +49,24 @@ static bool exe_open_chest(PlayerType *player_ptr, POSITION y, POSITION x, OBJEC
 {
     bool flag = true;
     bool more = false;
-    ObjectType *o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
+    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 = player_ptr->skill_dis;
-        if (player_ptr->blind || no_lite(player_ptr))
+        const auto effects = player_ptr->effects();
+        if (effects->blindness()->is_blind() || no_lite(player_ptr)) {
             i = i / 10;
+        }
 
-        if (player_ptr->confused || player_ptr->hallucinated)
+        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."));
@@ -65,8 +74,9 @@ static bool exe_open_chest(PlayerType *player_ptr, POSITION y, POSITION x, OBJEC
             flag = true;
         } else {
             more = true;
-            if (flush_failure)
+            if (flush_failure) {
                 flush();
+            }
 
             msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
         }
@@ -93,8 +103,9 @@ void do_cmd_open(PlayerType *player_ptr)
     DIRECTION dir;
     OBJECT_IDX o_idx;
     bool more = false;
-    if (player_ptr->wild_mode)
+    if (player_ptr->wild_mode) {
         return;
+    }
 
     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
@@ -103,8 +114,9 @@ void do_cmd_open(PlayerType *player_ptr)
         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)
+            if (!too_many) {
                 command_dir = coords_to_dir(player_ptr, y, x);
+            }
         }
     }
 
@@ -122,7 +134,7 @@ void do_cmd_open(PlayerType *player_ptr)
         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 (f_info[feat].flags.has_not(FloorFeatureType::OPEN) && !o_idx) {
+        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 && player_ptr->riding != g_ptr->m_idx) {
             PlayerEnergy(player_ptr).set_player_turn_energy(100);
@@ -135,8 +147,9 @@ void do_cmd_open(PlayerType *player_ptr)
         }
     }
 
-    if (!more)
+    if (!more) {
         disturb(player_ptr, false, false);
+    }
 }
 
 /*!
@@ -150,13 +163,15 @@ void do_cmd_close(PlayerType *player_ptr)
     POSITION y, x;
     DIRECTION dir;
     bool more = false;
-    if (player_ptr->wild_mode)
+    if (player_ptr->wild_mode) {
         return;
+    }
 
     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
-    if (easy_open && (count_dt(player_ptr, &y, &x, is_open, false) == 1))
+    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;
@@ -171,7 +186,7 @@ void do_cmd_close(PlayerType *player_ptr)
         x = player_ptr->x + ddx[dir];
         g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
         feat = g_ptr->get_feat_mimic();
-        if (f_info[feat].flags.has_not(FloorFeatureType::CLOSE)) {
+        if (terrains_info[feat].flags.has_not(TerrainCharacteristics::CLOSE)) {
             msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
         } else if (g_ptr->m_idx) {
             PlayerEnergy(player_ptr).set_player_turn_energy(100);
@@ -182,8 +197,9 @@ void do_cmd_close(PlayerType *player_ptr)
         }
     }
 
-    if (!more)
+    if (!more) {
         disturb(player_ptr, false, false);
+    }
 }
 
 /*!
@@ -196,8 +212,9 @@ void do_cmd_disarm(PlayerType *player_ptr)
     DIRECTION dir;
     OBJECT_IDX o_idx;
     bool more = false;
-    if (player_ptr->wild_mode)
+    if (player_ptr->wild_mode) {
         return;
+    }
 
     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
@@ -206,8 +223,9 @@ void do_cmd_disarm(PlayerType *player_ptr)
         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)
+            if (!too_many) {
                 command_dir = coords_to_dir(player_ptr, y, x);
+            }
         }
     }
 
@@ -237,8 +255,9 @@ void do_cmd_disarm(PlayerType *player_ptr)
         }
     }
 
-    if (!more)
+    if (!more) {
         disturb(player_ptr, false, false);
+    }
 }
 
 /*!
@@ -264,8 +283,9 @@ void do_cmd_bash(PlayerType *player_ptr)
     DIRECTION dir;
     grid_type *g_ptr;
     bool more = false;
-    if (player_ptr->wild_mode)
+    if (player_ptr->wild_mode) {
         return;
+    }
 
     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
@@ -281,7 +301,7 @@ void do_cmd_bash(PlayerType *player_ptr)
         x = player_ptr->x + ddx[dir];
         g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
         feat = g_ptr->get_feat_mimic();
-        if (f_info[feat].flags.has_not(FloorFeatureType::BASH)) {
+        if (terrains_info[feat].flags.has_not(TerrainCharacteristics::BASH)) {
             msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
         } else if (g_ptr->m_idx) {
             PlayerEnergy(player_ptr).set_player_turn_energy(100);
@@ -292,8 +312,9 @@ void do_cmd_bash(PlayerType *player_ptr)
         }
     }
 
-    if (!more)
+    if (!more) {
         disturb(player_ptr, false, false);
+    }
 }
 
 /*!
@@ -309,9 +330,10 @@ void do_cmd_bash(PlayerType *player_ptr)
 static bool get_spike(PlayerType *player_ptr, INVENTORY_IDX *ip)
 {
     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
-        ObjectType *o_ptr = &player_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 == ItemKindType::SPIKE) {
             *ip = i;
@@ -334,13 +356,15 @@ static bool get_spike(PlayerType *player_ptr, INVENTORY_IDX *ip)
 void do_cmd_spike(PlayerType *player_ptr)
 {
     DIRECTION dir;
-    if (player_ptr->wild_mode)
+    if (player_ptr->wild_mode) {
         return;
+    }
 
     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
 
-    if (!get_rep_dir(player_ptr, &dir, false))
+    if (!get_rep_dir(player_ptr, &dir, false)) {
         return;
+    }
 
     POSITION y = player_ptr->y + ddy[dir];
     POSITION x = player_ptr->x + ddx[dir];
@@ -348,7 +372,7 @@ void do_cmd_spike(PlayerType *player_ptr)
     g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
     FEAT_IDX feat = g_ptr->get_feat_mimic();
     INVENTORY_IDX item;
-    if (f_info[feat].flags.has_not(FloorFeatureType::SPIKE)) {
+    if (terrains_info[feat].flags.has_not(TerrainCharacteristics::SPIKE)) {
         msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
     } else if (!get_spike(player_ptr, &item)) {
         msg_print(_("くさびを持っていない!", "You have no spikes!"));
@@ -358,8 +382,8 @@ void do_cmd_spike(PlayerType *player_ptr)
         do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
     } else {
         PlayerEnergy(player_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(player_ptr, y, x, FloorFeatureType::SPIKE);
+        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);
     }
 }