/** * Disarms a trap, or a chest * * Traps must be visible, chests must be known trapped */ void do_cmd_disarm(struct command *cmd) { int y, x, dir; int err; struct object *obj; bool more = false; /* Get arguments */ err = cmd_get_arg_direction(cmd, "direction", &dir); if (err || dir == DIR_UNKNOWN) { int y2, x2; int n_traps, n_chests; n_traps = count_feats(&y2, &x2, square_isknowntrap, true); n_chests = count_chests(&y2, &x2, CHEST_TRAPPED); if (n_traps + n_chests == 1) { dir = coords_to_dir(y2, x2); cmd_set_arg_direction(cmd, "direction", dir); } else if (cmd_get_direction(cmd, "direction", &dir, n_chests > 0)) { /* If there are chests to disarm, 5 is allowed as a direction */ return; } } /* Get location */ y = player->py + ddy[dir]; x = player->px + ddx[dir]; /* Check for chests */ obj = chest_check(y, x, CHEST_TRAPPED); /* Verify legality */ if (!obj && !do_cmd_disarm_test(y, x)) { /* Cancel repeat */ disturb(player, 0); return; } /* Take a turn */ player->upkeep->energy_use = z_info->move_energy; /* Apply confusion */ if (player_confuse_dir(player, &dir, false)) { /* Get location */ y = player->py + ddy[dir]; x = player->px + ddx[dir]; /* Check for chests */ obj = chest_check(y, x, CHEST_TRAPPED); } /* Monster */ if (cave->squares[y][x].mon > 0) { msg("There is a monster in the way!"); py_attack(y, x); } else if (obj) /* Chest */ more = do_cmd_disarm_chest(y, x, obj); else if (square_iscloseddoor(cave, y, x) && !square_islockeddoor(cave, y, x)) /* Door to lock */ more = do_cmd_lock_door(y, x); else /* Disarm trap */ more = do_cmd_disarm_aux(y, x); /* Cancel repeat unless told not to */ if (!more) disturb(player, 0); }
/* * Disarms a trap, or a chest */ void do_cmd_disarm(cmd_code code, cmd_arg args[]) { int y, x, dir; s16b o_idx; bool more = FALSE; dir = args[0].direction; /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; /* Check for chests */ o_idx = chest_check(y, x); /* Verify legality */ if (!o_idx && !do_cmd_disarm_test(y, x)) { /* Cancel repeat */ disturb(p_ptr, 0, 0); return; } /* Take a turn */ p_ptr->energy_use = 100; /* Apply confusion */ if (player_confuse_dir(p_ptr, &dir, FALSE)) { /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; /* Check for chests */ o_idx = chest_check(y, x); } /* Monster */ if (cave->m_idx[y][x] > 0) { msg("There is a monster in the way!"); py_attack(y, x); } /* Chest */ else if (o_idx) more = do_cmd_disarm_chest(y, x, o_idx); /* Door to lock */ else if (cave->feat[y][x] == FEAT_DOOR_HEAD) more = do_cmd_lock_door(y, x); /* Disarm trap */ else more = do_cmd_disarm_aux(y, x); /* Cancel repeat unless told not to */ if (!more) disturb(p_ptr, 0, 0); }