Index: cmd2.c =================================================================== RCS file: /home/angband/angband/angband/src/cmd2.c,v retrieving revision 1.9 diff -u -r1.9 cmd2.c --- cmd2.c 2001/02/03 18:19:07 1.9 +++ cmd2.c 2001/03/29 18:27:01 @@ -476,29 +476,61 @@ #if defined(ALLOW_EASY_OPEN) /* - * Return the number of features around (or under) the character. - * Usually look for doors and floor traps. + * Return TRUE if the given feature is an open (or broken) door */ -static int count_feats(int *y, int *x, byte f1, byte f2) +static bool is_open(int feat) { - int d, count; + return ((feat == FEAT_OPEN) || (feat == FEAT_BROKEN)); +} - /* Count how many matches */ - count = 0; + +/* + * Return TRUE if the given feature is a closed door + */ +static bool is_closed(int feat) +{ + return ((feat >= FEAT_DOOR_HEAD) && + (feat <= FEAT_DOOR_TAIL)); +} + + +/* + * Return TRUE if the given feature is a trap + */ +static bool is_trap(int feat) +{ + return ((feat >= FEAT_TRAP_HEAD) && + (feat <= FEAT_TRAP_TAIL)); +} + + +/* + * Return the number of doors/traps around (or under) the character. + */ +static int count_feats(int *y, int *x, bool (*test)(int feat), bool under) +{ + int d; + int xx, yy; + int count = 0; /* Count how many matches */ /* Check around (and under) the character */ for (d = 0; d < 9; d++) { + /* if not searching under player continue */ + if ((d == 8) && !under) continue; + /* Extract adjacent (legal) location */ - int yy = p_ptr->py + ddy_ddd[d]; - int xx = p_ptr->px + ddx_ddd[d]; + yy = p_ptr->py + ddy_ddd[d]; + xx = p_ptr->px + ddx_ddd[d]; + + /* Paranoia */ + if (!in_bounds_fully(yy, xx)) continue; /* Must have knowledge */ if (!(cave_info[yy][xx] & (CAVE_MARK))) continue; /* Not looking for this feature */ - if (cave_feat[yy][xx] < f1) continue; - if (cave_feat[yy][xx] > f2) continue; + if (!((*test)(cave_feat[yy][xx]))) continue; /* Count it */ ++count; @@ -718,9 +750,16 @@ /* Easy Open */ if (easy_open) { - /* Handle a single closed door or locked chest */ - if ((count_feats(&y, &x, FEAT_DOOR_HEAD, FEAT_DOOR_TAIL) + - count_chests(&y, &x, FALSE)) == 1) + int num_doors, num_chests; + + /* Count closed doors */ + num_doors = count_feats(&y, &x, is_closed, FALSE); + + /* Count chests (locked) */ + num_chests = count_chests(&y, &x, FALSE); + + /* See if only one target */ + if ((num_doors + num_chests) == 1) { p_ptr->command_dir = coords_to_dir(y, x); } @@ -886,14 +925,10 @@ /* Easy Close */ if (easy_open) { - /* Handle a single open door */ - if (count_feats(&y, &x, FEAT_OPEN, FEAT_OPEN) == 1) + /* Count open doors */ + if (count_feats(&y, &x, is_open, FALSE) == 1) { - /* Don't close door player is on */ - if ((y != p_ptr->py) || (x != p_ptr->px)) - { - p_ptr->command_dir = coords_to_dir(y, x); - } + p_ptr->command_dir = coords_to_dir(y, x); } } @@ -1417,11 +1452,19 @@ /* Easy Disarm */ if (easy_open) { - /* Handle a single visible trap or trapped chest */ - if ((count_feats(&y, &x, FEAT_TRAP_HEAD, FEAT_TRAP_TAIL) + - count_chests(&y, &x, TRUE)) == 1) + int num_traps, num_chests; + + /* Count visible traps */ + num_traps = count_feats(&y, &x, is_trap, TRUE); + + /* Count chests (trapped) */ + num_chests = count_chests(&y, &x, TRUE); + + /* See if only one target */ + if (num_traps || num_chests) { - p_ptr->command_dir = coords_to_dir(y, x); + if (num_traps + num_chests <= 1) + p_ptr->command_dir = coords_to_dir(y, x); } }