示例#1
0
static void fill_terrain_info(void)
{
    int i, j;

    ox = MAX(p_ptr->px - MAX_PF_RADIUS / 2, 0);
    oy = MAX(p_ptr->py - MAX_PF_RADIUS / 2, 0);

    ex = MIN(p_ptr->px + MAX_PF_RADIUS / 2 - 1, DUNGEON_WID);
    ey = MIN(p_ptr->py + MAX_PF_RADIUS / 2 - 1, DUNGEON_HGT);

    for (i = 0; i < MAX_PF_RADIUS * MAX_PF_RADIUS; i++)
	terrain[0][i] = -1;

    for (j = oy; j < ey; j++)
	for (i = ox; i < ex; i++)
	    if (is_valid_pf(j, i))
		terrain[j - oy][i - ox] = MAX_PF_LENGTH;

    terrain[p_ptr->py - oy][p_ptr->px - ox] = 1;
}
示例#2
0
static void fill_terrain_info(void)
{
	int i, j;

	ox = MAX(player->px - MAX_PF_RADIUS / 2, 0);
	oy = MAX(player->py - MAX_PF_RADIUS / 2, 0);

	ex = MIN(player->px + MAX_PF_RADIUS / 2 - 1, cave->width);
	ey = MIN(player->py + MAX_PF_RADIUS / 2 - 1, cave->height);

	for (i = 0; i < MAX_PF_RADIUS * MAX_PF_RADIUS; i++)
		terrain[0][i] = -1;

	for (j = oy; j < ey; j++)
		for (i = ox; i < ex; i++)
			if (is_valid_pf(j, i))
				terrain[j - oy][i - ox] = MAX_PF_LENGTH;

	terrain[player->py - oy][player->px - ox] = 1;
}
示例#3
0
/**
 * Take one step along the current "run" path
 *
 * Called with a real direction to begin a new run, and with zero
 * to continue a run in progress.
 */
void run_step(int dir)
{
    /* Start run */
    if (dir) {
	/* Paranoia */
	p_ptr->running_withpathfind = 0;

	/* Initialize */
	run_init(dir);

	/* Hack -- Set the run counter */
	p_ptr->running = (p_ptr->command_arg ? p_ptr->command_arg : 1000);

	/* Calculate torch radius */
	p_ptr->update |= (PU_TORCH);
    }

    /* Continue run */
    else {
	if (!p_ptr->running_withpathfind) {
	    /* Update run */
	    if (run_test()) {
		/* Disturb */
		disturb(0, 0);

		/* Done */
		return;
	    }
	}

	else {
	    /* Abort if we have finished */
	    if (pf_result_index < 0) {
		disturb(0, 0);
		p_ptr->running_withpathfind = FALSE;
		return;
	    }
	    /* Abort if we would hit a wall */
	    else if (pf_result_index == 0) {
		int y, x;

		/* Get next step */
		y = p_ptr->py + ddy[pf_result[pf_result_index] - '0'];
		x = p_ptr->px + ddx[pf_result[pf_result_index] - '0'];

		/* Known wall */
		if ((cave_info[y][x] & (CAVE_MARK)) && !is_valid_pf(y, x)) {
		    disturb(0, 0);
		    p_ptr->running_withpathfind = FALSE;
		    return;
		}
	    }
	    /* Hack -- walking stick lookahead. If the player has computed a
	     * path that is going to end up in a wall, we notice this and
	     * convert to a normal run. This allows us to click on unknown
	     * areas to explore the map. We have to look ahead two, otherwise
	     * we don't know which is the last direction moved and don't
	     * initialise the run properly. */
	    else if (pf_result_index > 0) {
		int y, x;

		/* Get next step */
		y = p_ptr->py + ddy[pf_result[pf_result_index] - '0'];
		x = p_ptr->px + ddx[pf_result[pf_result_index] - '0'];

		/* Known wall */
		if ((cave_info[y][x] & (CAVE_MARK)) && !is_valid_pf(y, x)) {
		    disturb(0, 0);
		    p_ptr->running_withpathfind = FALSE;
		    return;
		}

		/* Get step after */
		y = y + ddy[pf_result[pf_result_index - 1] - '0'];
		x = x + ddx[pf_result[pf_result_index - 1] - '0'];

		/* Known wall */
		if ((cave_info[y][x] & (CAVE_MARK)) && !is_valid_pf(y, x)) {
		    p_ptr->running_withpathfind = FALSE;

		    run_init(pf_result[pf_result_index] - '0');
		}
	    }

	    if (!player_is_crossing)
		p_ptr->run_cur_dir = pf_result[pf_result_index--] - '0';
	}
    }

    /* Decrease counter */
    p_ptr->running--;

    /* Take time */
    p_ptr->energy_use = 100;

    /* Move the player */
    move_player(p_ptr->run_cur_dir);
}