/* * Close an open door. */ void do_cmd_close(cmd_code code, cmd_arg args[]) { int y, x, dir; bool more = FALSE; dir = args[0].direction; /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; /* Verify legality */ if (!do_cmd_close_test(y, x)) { /* Cancel repeat */ disturb(0, 0); return; } /* Take a turn */ p_ptr->energy_use = 100; /* Apply confusion */ if (confuse_dir(&dir)) { /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; } /* Monster */ if (cave_m_idx[y][x] > 0) { if (mon_list[cave_m_idx[y][x]].align & (AL_PET_MASK)) msg_print("There is a friendly monster in the way!"); else { /* Message */ msg_print("There is a monster in the way!"); /* Attack */ py_attack(y, x); } } /* Door */ else { /* Close door */ more = do_cmd_close_aux(y, x); } /* Cancel repeat unless told not to */ if (!more) disturb(0, 0); }
/** * Close an open door. */ void do_cmd_close(struct command *cmd) { int y, x, dir; int err; bool more = false; /* Get arguments */ err = cmd_get_arg_direction(cmd, "direction", &dir); if (err || dir == DIR_UNKNOWN) { int y2, x2; /* Count open doors */ if (count_feats(&y2, &x2, square_isopendoor, false) == 1) { dir = coords_to_dir(y2, x2); cmd_set_arg_direction(cmd, "direction", dir); } else if (cmd_get_direction(cmd, "direction", &dir, false)) { return; } } /* Get location */ y = player->py + ddy[dir]; x = player->px + ddx[dir]; /* Verify legality */ if (!do_cmd_close_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]; } /* Monster - alert, then attack */ if (cave->squares[y][x].mon > 0) { msg("There is a monster in the way!"); py_attack(y, x); } else /* Door - close it */ more = do_cmd_close_aux(y, x); /* Cancel repeat unless told not to */ if (!more) disturb(player, 0); }
/* * Close an open door. */ void do_cmd_close(cmd_code code, cmd_arg args[]) { int y, x, dir; bool more = FALSE; dir = args[0].direction; /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; /* Verify legality */ if (!do_cmd_close_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]; } /* Monster */ if (cave->m_idx[y][x] > 0) { /* Message */ msg("There is a monster in the way!"); /* Attack */ py_attack(y, x); } /* Door */ else { /* Close door */ more = do_cmd_close_aux(y, x); } /* Cancel repeat unless told not to */ if (!more) disturb(p_ptr, 0, 0); }
/* * Manipulate an adjacent grid in some way * * Attack monsters, tunnel through walls, disarm traps, open doors. * * This command must always take energy, to prevent free detection * of invisible monsters. * * The "semantics" of this command must be chosen before the player * is confused, and it must be verified against the new grid. */ void do_cmd_alter_aux(int dir) { int y, x; int feat; bool more = FALSE; /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; /* Original feature */ feat = cave_feat[y][x]; /* Must have knowledge to know feature XXX XXX */ if (!(cave_info[y][x] & (CAVE_MARK))) feat = FEAT_NONE; /* Take a turn */ p_ptr->energy_use = 100; /* Apply confusion */ if (confuse_dir(&dir)) { /* Get location */ y = p_ptr->py + ddy[dir]; x = p_ptr->px + ddx[dir]; } /* Attack monsters */ if (cave_m_idx[y][x] > 0) { if (mon_list[cave_m_idx[y][x]].align & (AL_PET_MASK)) { msg_print("There is a friendly monster in the way!"); } else { /* Attack */ py_attack(y, x); } } /* Tunnel through walls */ else if (feat >= FEAT_SECRET) { more = do_cmd_tunnel_aux(y, x); } #if 0 /* Bash jammed doors */ else if (feat >= FEAT_DOOR_HEAD + 0x08) { more = do_cmd_bash_aux(y, x); } #endif /* Open closed doors */ else if (feat >= FEAT_DOOR_HEAD) { more = do_cmd_open_aux(y, x); } /* Disarm traps */ else if (feat >= FEAT_TRAP_HEAD) { more = do_cmd_disarm_aux(y, x); } #if 0 /* Close open doors */ else if (feat == FEAT_OPEN) { more = do_cmd_close_aux(y, x); } #endif /* Oops */ else { msg_print("You spin around."); } /* Cancel repetition unless we can continue */ if (!more) disturb(0, 0); }
/* * Close an open door. */ void do_cmd_close(void) { int py = p_ptr->py; int px = p_ptr->px; int y, x, dir; bool more = FALSE; /* Option: Pick a direction -TNB- */ if (easy_open) { /* See if there's only one closeable door */ if (count_feats(&y, &x, is_open, FALSE) == 1) { p_ptr->command_dir = coords_to_dir(y, x); } } /* Get a direction (or abort) */ if (!get_rep_dir(&dir)) return; /* Get location */ y = py + ddy[dir]; x = px + ddx[dir]; /* Verify legality */ if (!do_cmd_close_test(y, x)) return; /* Take a turn */ p_ptr->energy_use = 100; /* Apply confusion */ if (confuse_dir(&dir)) { /* Get location */ y = py + ddy[dir]; x = px + ddx[dir]; } /* Allow repeated command */ if (p_ptr->command_arg) { /* Set repeat count */ p_ptr->command_rep = p_ptr->command_arg - 1; /* Redraw the state */ p_ptr->redraw |= (PR_STATE); /* Cancel the arg */ p_ptr->command_arg = 0; } /* Monster */ if (cave_m_idx[y][x] > 0) { /* Message */ msg_print("There is a monster in the way!"); /* Attack */ py_attack(y, x); } /* Door */ else { /* Close door */ more = do_cmd_close_aux(y, x); } /* Cancel repeat unless told not to */ if (!more) disturb(0, 0); }