From deec8317ce8b5779e58c4239653c83cf461d6b53 Mon Sep 17 00:00:00 2001 From: PatR Date: Fri, 30 Jan 2026 14:17:53 -0800 Subject: [PATCH] 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 --- src/nhlsel.c | 6 +++++- src/selvar.c | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/nhlsel.c b/src/nhlsel.c index b06b53545..9b5ef24c4 100644 --- a/src/nhlsel.c +++ b/src/nhlsel.c @@ -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; diff --git a/src/selvar.c b/src/selvar.c index 5d08ca95e..a35b9f7bd 100644 --- a/src/selvar.c +++ b/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; }