From: Pasi Kallinen Date: Wed, 6 Jan 2016 01:04:13 +0000 (+0200) Subject: Allow quickly moving cursor on monsters X-Git-Tag: NetHack-3.6.1_RC01~1064^2~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c9ae20c5a99e498514336e94d9f22f227a43640;p=nethack Allow quickly moving cursor on monsters Original patch was mine, but this implementation took ideas from Dynahack by Tung Nguyen --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 436a270b9..16f77f7e7 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -87,6 +87,7 @@ requiver pickup_thrown objects if quiver is empty make mimics mimicing walls or trees also block light stepping onto lava destroyed non-fireproof water walking boots but left other vulnerable boot types intact +allow moving cursor to monsters with 'm' and 'M' when asked for map location Platform- and/or Interface-Specific Fixes diff --git a/src/do_name.c b/src/do_name.c index 889609034..5e5675b98 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -55,6 +55,7 @@ const char *goal; putstr(tmpwin, 0, "Use [HJKL] to move the cursor 8 units at a time."); putstr(tmpwin, 0, "Or enter a background symbol (ex. <)."); putstr(tmpwin, 0, "Use @ to move the cursor on yourself."); + putstr(tmpwin, 0, "Use m or M to move the cursor on monster."); if (getpos_hilitefunc) putstr(tmpwin, 0, "Use $ to display valid locations."); putstr(tmpwin, 0, "Use # to toggle automatic description."); @@ -71,6 +72,25 @@ const char *goal; destroy_nhwindow(tmpwin); } +static int +cmp_coord_distu(a, b) +const void *a; +const void *b; +{ + const coord *c1 = a; + const coord *c2 = b; + int dx, dy, dist1, dist2; + + dx = u.ux - c1->x; + dy = u.uy - c1->y; + dist1 = dx * dx + dy * dy; + dx = u.ux - c2->x; + dy = u.uy - c2->y; + dist2 = dx * dx + dy * dy; + + return dist1 - dist2; +} + int getpos(ccp, force, goal) coord *ccp; @@ -85,6 +105,9 @@ const char *goal; static const char pick_chars[] = ".,;:"; const char *cp; boolean hilite_state = FALSE; + coord *monarr = NULL; + int moncount = 0; + int monidx = 0; if (!goal) goal = "desired location"; @@ -217,6 +240,43 @@ const char *goal; cx = u.ux; cy = u.uy; goto nxtc; + } else if (c == 'm' || c == 'M') { + if (!monarr) { + moncount = 0; + monidx = 0; + struct monst *mtmp = fmon; + while (mtmp) { + if (canspotmon(mtmp) + && (mtmp->mx != u.ux && mtmp->my != u.uy)) + moncount++; + mtmp = mtmp->nmon; + } + monarr = (coord *)alloc(sizeof(coord) * moncount); + mtmp = fmon; + while (mtmp) { + if (canspotmon(mtmp) + && (mtmp->mx != u.ux && mtmp->my != u.uy)) { + monarr[monidx].x = mtmp->mx; + monarr[monidx].y = mtmp->my; + monidx++; + } + mtmp = mtmp->nmon; + } + qsort(monarr, moncount, sizeof(coord), cmp_coord_distu); + /* ready this for first increment/decrement to change to zero */ + monidx = (c == 'm') ? -1 : 1; + } + if (moncount) { + if (c == 'm') + monidx = (monidx + 1) % moncount; + else { + monidx--; + if (monidx < 0) monidx = moncount-1; + } + cx = monarr[monidx].x; + cy = monarr[monidx].y; + goto nxtc; + } } else { if (!index(quitchars, c)) { char matching[MAXPCHARS]; @@ -307,6 +367,8 @@ const char *goal; clear_nhwindow(WIN_MESSAGE); ccp->x = cx; ccp->y = cy; + if (monarr) + free(monarr); getpos_hilitefunc = (void FDECL((*), (int))) 0; return result; }