From 49e4330cb2fd706c45ee91d718f547aeb223c2e2 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 20 Sep 2018 15:19:50 -0700 Subject: [PATCH] special levels 'grow selection' Fixes #132 This is based on the commit for github pull request #132, which indicates that the 'grow' pattern is reversed from what the .des file specifies. I don't understand how this is really supposed to work and the only place nethack uses it is on the Valkyrie Home level, which seems to be created roughly the same both before and after this change. --- src/sp_lev.c | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) 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);