MCPcopy Create free account
hub / github.com/NetHack/NetHack / selection_do_grow

Function selection_do_grow

src/selvar.c:320–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318}
319
320void
321selection_do_grow(struct selectionvar *ov, int dir)
322{
323 coordxy x, y;
324 struct selectionvar *tmp;
325 NhRect rect = cg.zeroNhRect;
326
327 if (!ov)
328 return;
329
330 tmp = selection_new();
331
332 if (dir == W_RANDOM)
333 dir = random_wdir();
334
335 selection_getbounds(ov, &rect);
336
337 for (x = max(0, rect.lx-1); x <= min(COLNO-1, rect.hx+1); x++)
338 for (y = max(0, rect.ly-1); y <= min(ROWNO-1, rect.hy+1); y++) {
339 /* note: dir is a mask of multiple directions, but the only
340 way to specify diagonals is by including the two adjacent
341 orthogonal directions, which effectively specifies three-
342 way growth [WEST|NORTH => WEST plus WEST|NORTH plus NORTH] */
343 if (((dir & W_WEST) && selection_getpoint(x + 1, y, ov))
344 || (((dir & (W_WEST | W_NORTH)) == (W_WEST | W_NORTH))
345 && selection_getpoint(x + 1, y + 1, ov))
346 || ((dir & W_NORTH) && selection_getpoint(x, y + 1, ov))
347 || (((dir & (W_NORTH | W_EAST)) == (W_NORTH | W_EAST))
348 && selection_getpoint(x - 1, y + 1, ov))
349 || ((dir & W_EAST) && selection_getpoint(x - 1, y, ov))
350 || (((dir & (W_EAST | W_SOUTH)) == (W_EAST | W_SOUTH))
351 && selection_getpoint(x - 1, y - 1, ov))
352 || ((dir & W_SOUTH) && selection_getpoint(x, y - 1, ov))
353 || (((dir & (W_SOUTH | W_WEST)) == (W_SOUTH | W_WEST))
354 && selection_getpoint(x + 1, y - 1, ov))) {
355 selection_setpoint(x, y, tmp, 1);
356 }
357 }
358
359 selection_getbounds(tmp, &rect);
360
361 for (x = rect.lx; x <= rect.hx; x++)
362 for (y = rect.ly; y <= rect.hy; y++)
363 if (selection_getpoint(x, y, tmp))
364 selection_setpoint(x, y, ov, 1);
365
366 selection_free(tmp, TRUE);
367}
368
369staticfn int (*selection_flood_check_func)(coordxy, coordxy);
370

Callers 2

l_selection_growFunction · 0.85
lspo_regionFunction · 0.85

Calls 6

selection_newFunction · 0.85
random_wdirFunction · 0.85
selection_getboundsFunction · 0.85
selection_getpointFunction · 0.85
selection_setpointFunction · 0.85
selection_freeFunction · 0.85

Tested by

no test coverage detected