OSDN Git Service

Enable to open chests or disarm traps at player's feet when there are chests and...
[hengbandforosx/hengbandosx.git] / src / cmd2.c
index 251a555..03b9b04 100644 (file)
@@ -438,7 +438,7 @@ void do_cmd_search(void)
 /*
  * Determine if a grid contains a chest
  */
-static s16b chest_check(int y, int x)
+static s16b chest_check(int y, int x, bool trapped)
 {
        cave_type *c_ptr = &cave[y][x];
 
@@ -459,8 +459,13 @@ static s16b chest_check(int y, int x)
                /* Skip unknown chests XXX XXX */
                /* if (!(o_ptr->marked & OM_FOUND)) continue; */
 
-               /* Check for chest */
-               if (o_ptr->tval == TV_CHEST) return (this_o_idx);
+               /* Check for non empty chest */
+               if ((o_ptr->tval == TV_CHEST) &&
+                       (((!trapped) && (o_ptr->pval)) || /* non empty */
+                       ((trapped) && (o_ptr->pval > 0)))) /* trapped only */
+               {
+                       return (this_o_idx);
+               }
        }
 
        /* No chest */
@@ -1032,7 +1037,7 @@ static int count_chests(int *y, int *x, bool trapped)
                int xx = px + ddx_ddd[d];
 
                /* No (visible) chest is there */
-               if ((o_idx = chest_check(yy, xx)) == 0) continue;
+               if ((o_idx = chest_check(yy, xx, FALSE)) == 0) continue;
 
                /* Grab the object */
                o_ptr = &o_list[o_idx];
@@ -1261,7 +1266,7 @@ void do_cmd_open(void)
                feat = get_feat_mimic(c_ptr);
 
                /* Check for chest */
-               o_idx = chest_check(y, x);
+               o_idx = chest_check(y, x, FALSE);
 
                /* Nothing useful */
                if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
@@ -2198,7 +2203,7 @@ void do_cmd_disarm(void)
                feat = get_feat_mimic(c_ptr);
 
                /* Check for chests */
-               o_idx = chest_check(y, x);
+               o_idx = chest_check(y, x, TRUE);
 
                /* Disarm a trap */
                if (!is_trap(feat) && !o_idx)