From: Pasi Kallinen Date: Wed, 6 Jan 2016 19:42:45 +0000 (+0200) Subject: Make getpos monster targeting use glyph lookup X-Git-Tag: NetHack-3.6.1_RC01~1064^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d1281c9ac38c30eb68e5e0e7df3182a04943e5a;p=nethack Make getpos monster targeting use glyph lookup --- diff --git a/src/do_name.c b/src/do_name.c index 567720e67..2341adb0e 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -244,24 +244,28 @@ const char *goal; goto nxtc; } else if (c == 'm' || c == 'M') { if (!monarr) { - struct monst *mtmp; + int x,y,s; moncount = 0; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (canspotmon(mtmp) - && (mtmp->mx != u.ux || mtmp->my != u.uy)) - moncount++; - } - /* moncount + 1: always allocate a non-zero amount */ - monarr = (coord *) alloc(sizeof (coord) * (moncount + 1)); - monidx = 0; - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (canspotmon(mtmp) - && (mtmp->mx != u.ux || mtmp->my != u.uy)) { - monarr[monidx].x = mtmp->mx; - monarr[monidx].y = mtmp->my; - monidx++; + for (s = 0; s < 2; s++) { + if (s) { + /* moncount + 1: always allocate a non-zero amount */ + monarr = (coord *) alloc(sizeof (coord) * (moncount + 1)); + monidx = 0; } + if (!s || s && moncount) + for (x = 0; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) + if (glyph_is_monster(glyph_at(x,y)) + && !(x == u.ux && y == u.uy)) { + if (!s) + moncount++; + else { + monarr[monidx].x = x; + monarr[monidx].y = y; + monidx++; + } + } } qsort(monarr, moncount, sizeof (coord), cmp_coord_distu); /* ready for first increment/decrement to change to zero */