/* * Count the number of walls adjacent to the given grid. * * Note -- Assumes "in_bounds(y, x)" * * We count only granite walls and permanent walls. */ static int next_to_walls(int y, int x) { int k = 0; if (in_bounds(y + 1, x) && is_extra_bold(y + 1, x)) k++; if (in_bounds(y - 1, x) && is_extra_bold(y - 1, x)) k++; if (in_bounds(y, x + 1) && is_extra_bold(y, x + 1)) k++; if (in_bounds(y, x - 1) && is_extra_bold(y, x - 1)) k++; return (k); }
/* Set a square to be floor. (Includes range checking.) */ void set_floor(int x, int y) { if (!in_bounds(y, x)) { /* Out of bounds */ return; } if (cave[y][x].info & CAVE_ROOM) { /* A room border don't touch. */ return; } /* Set to be floor if is a wall (don't touch lakes). */ if (is_extra_bold(y, x)) place_floor_bold(y, x); }
/* * This routine adds the square to the tunnel * It also checks for SOLID walls - and returns a nearby * non-SOLID square in (x,y) so that a simple avoiding * routine can be used. The returned boolean value reflects * whether or not this routine hit a SOLID wall. * * "affectwall" toggles whether or not this new square affects * the boundaries of rooms. - This is used by the catacomb * routine. */ static bool set_tunnel(int *x, int *y, bool affectwall) { int i, j, dx, dy; cave_type *c_ptr = &cave[*y][*x]; if (!in_bounds(*y, *x)) return TRUE; if (is_inner_grid(c_ptr)) { return TRUE; } if (is_extra_bold(*y,*x)) { /* Save the tunnel location */ if (dun->tunn_n < TUNN_MAX) { dun->tunn[dun->tunn_n].y = *y; dun->tunn[dun->tunn_n].x = *x; dun->tunn_n++; return TRUE; } else return FALSE; } if (is_floor_bold(*y, *x)) { /* Don't do anything */ return TRUE; } if (is_outer_grid(c_ptr) && affectwall) { /* Save the wall location */ if (dun->wall_n < WALL_MAX) { dun->wall[dun->wall_n].y = *y; dun->wall[dun->wall_n].x = *x; dun->wall_n++; } else return FALSE; /* Forbid re-entry near this piercing */ for (j = *y - 1; j <= *y + 1; j++) { for (i = *x - 1; i <= *x + 1; i++) { /* Convert adjacent "outer" walls as "solid" walls */ if (is_outer_bold(j, i)) { /* Change the wall to a "solid" wall */ place_solid_noperm_bold(j, i); } } } /* Clear mimic type */ cave[*y][*x].mimic = 0; place_floor_bold(*y, *x); return TRUE; } if (is_solid_grid(c_ptr) && affectwall) { /* cannot place tunnel here - use a square to the side */ /* find usable square and return value in (x,y) */ i = 50; dy = 0; dx = 0; while ((i > 0) && is_solid_bold(*y + dy, *x + dx)) { dy = randint0(3) - 1; dx = randint0(3) - 1; if (!in_bounds(*y + dy, *x + dx)) { dx = 0; dy = 0; } i--; } if (i == 0) { /* Failed for some reason: hack - ignore the solidness */ place_outer_grid(c_ptr); dx = 0; dy = 0; } /* Give new, acceptable coordinate. */ *x = *x + dx; *y = *y + dy; return FALSE; } return TRUE; }