diff --git a/src/sp_lev.c b/src/sp_lev.c index 4f8df6b9c..1d6b0cd3a 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -3827,7 +3827,7 @@ selection_do_grow(ov, dir) struct opvar *ov; int dir; { - int x, y, c; + int x, y; char tmp[COLNO][ROWNO]; if (ov->spovartyp != SPOVAR_SEL) @@ -3835,40 +3835,31 @@ int dir; if (!ov) return; - (void) memset(tmp, 0, sizeof(tmp)); + (void) memset(tmp, 0, sizeof tmp); - for (x = 0; x < COLNO; x++) + for (x = 1; x < COLNO; x++) for (y = 0; y < ROWNO; y++) { - c = 0; - if ((dir & W_WEST) && (x > 0) - && (selection_getpoint(x - 1, y, ov))) - c++; - if ((dir & (W_WEST | W_NORTH)) && (x > 0) && (y > 0) - && (selection_getpoint(x - 1, y - 1, ov))) - c++; - if ((dir & W_NORTH) && (y > 0) - && (selection_getpoint(x, y - 1, ov))) - c++; - if ((dir & (W_NORTH | W_EAST)) && (y > 0) && (x < COLNO - 1) - && (selection_getpoint(x + 1, y - 1, ov))) - c++; - if ((dir & W_EAST) && (x < COLNO - 1) - && (selection_getpoint(x + 1, y, ov))) - c++; - if ((dir & (W_EAST | W_SOUTH)) && (x < COLNO - 1) - && (y < ROWNO - 1) && (selection_getpoint(x + 1, y + 1, ov))) - c++; - if ((dir & W_SOUTH) && (y < ROWNO - 1) - && (selection_getpoint(x, y + 1, ov))) - c++; - if ((dir & (W_SOUTH | W_WEST)) && (y < ROWNO - 1) && (x > 0) - && (selection_getpoint(x - 1, y + 1, ov))) - c++; - if (c) + /* note: dir is a mask of multiple directions, but the only + way to specify diagonals is by including the two adjacent + orthogonal directions, which effectively specifies three- + way growth [WEST|NORTH => WEST plus WEST|NORTH plus NORTH] */ + if (((dir & W_WEST) && selection_getpoint(x + 1, y, ov)) + || (((dir & (W_WEST | W_NORTH)) == (W_WEST | W_NORTH)) + && selection_getpoint(x + 1, y + 1, ov)) + || ((dir & W_NORTH) && selection_getpoint(x, y + 1, ov)) + || (((dir & (W_NORTH | W_EAST)) == (W_NORTH | W_EAST)) + && selection_getpoint(x - 1, y + 1, ov)) + || ((dir & W_EAST) && selection_getpoint(x - 1, y, ov)) + || (((dir & (W_EAST | W_SOUTH)) == (W_EAST | W_SOUTH)) + && selection_getpoint(x - 1, y - 1, ov)) + || ((dir & W_SOUTH) && selection_getpoint(x, y - 1, ov)) + || (((dir & (W_SOUTH | W_WEST)) == (W_SOUTH | W_WEST)) + && selection_getpoint(x + 1, y - 1, ov))) { tmp[x][y] = 1; + } } - for (x = 0; x < COLNO; x++) + for (x = 1; x < COLNO; x++) for (y = 0; y < ROWNO; y++) if (tmp[x][y]) selection_setpoint(x, y, ov, 1);