git issue #1467 - selection.match() boundaries
Issue reported by copperwater: | a = selection.match(some_mapfrag); | b = selection.match(another_mapfrag); | c = a + b; Instead of being a union of all the points that match either mapfrag, the resulting selection c is empty. [Report included a choice of two possible fixes.] I put both in, without adequate testing of either one. I didn't hit any problems with the existing special levels but didn't try many theme rooms. Closes #1467
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 nhlua.c $NHDT-Date: 1737545957 2025/01/22 03:39:17 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.64 $ */
|
||||
/* NetHack 3.7 nhlua.c $NHDT-Date: 1769840272 2026/01/30 22:17:52 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.69 $ */
|
||||
/* Copyright (c) 2018 by Pasi Kallinen */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
@@ -710,6 +710,10 @@ l_selection_match(lua_State *L)
|
||||
for (x = 1; x < sel->wid; x++)
|
||||
selection_setpoint(x, y, sel, mapfrag_match(mf, x,y) ? 1 : 0);
|
||||
|
||||
/* unless the (0, 1) coordinate is a match, this would wind up with a
|
||||
selection with lx=COLNO, hx=0, etc, so fix the boundaries */
|
||||
selection_recalc_bounds(sel);
|
||||
|
||||
mapfrag_free(&mf);
|
||||
|
||||
return 1;
|
||||
|
||||
19
src/selvar.c
19
src/selvar.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 selvar.c $NHDT-Date: 1709677544 2024/03/05 22:25:44 $ $NHDT-Branch: keni-mdlib-followup $:$NHDT-Revision: 1.360 $ */
|
||||
/* NetHack 3.7 selvar.c $NHDT-Date: 1769840272 2026/01/30 22:17:52 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.4 $ */
|
||||
/* Copyright (c) 2024 by Pasi Kallinen */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
@@ -189,11 +189,18 @@ selection_setpoint(
|
||||
return;
|
||||
|
||||
if (c && !sel->bounds_dirty) {
|
||||
if (sel->bounds.lx > x) sel->bounds.lx = x;
|
||||
if (sel->bounds.ly > y) sel->bounds.ly = y;
|
||||
if (sel->bounds.hx < x) sel->bounds.hx = x;
|
||||
if (sel->bounds.hy < y) sel->bounds.hy = y;
|
||||
} else {
|
||||
if (sel->bounds.lx > x)
|
||||
sel->bounds.lx = x;
|
||||
if (sel->bounds.ly > y)
|
||||
sel->bounds.ly = y;
|
||||
if (sel->bounds.hx < x)
|
||||
sel->bounds.hx = x;
|
||||
if (sel->bounds.hy < y)
|
||||
sel->bounds.hy = y;
|
||||
|
||||
/* only set bounds_dirty if changing a point from 1 to 0; if changing
|
||||
a point from 0 to 0, nothing has really changed with the bounds */
|
||||
} else if (sel->map[sel->wid * y + x] != 0) {
|
||||
sel->bounds_dirty = TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user