Some code reorg for the getloc nearest/farthest locs
This commit is contained in:
@@ -123,9 +123,13 @@ const void *b;
|
|||||||
return dist_1 - dist_2;
|
return dist_1 - dist_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GLOC_MONS 0
|
enum gloctypes {
|
||||||
#define GLOC_OBJS 1
|
GLOC_MONS = 0,
|
||||||
#define GLOC_DOOR 2
|
GLOC_OBJS,
|
||||||
|
GLOC_DOOR,
|
||||||
|
|
||||||
|
NUM_GLOCS
|
||||||
|
};
|
||||||
|
|
||||||
STATIC_OVL boolean
|
STATIC_OVL boolean
|
||||||
gather_locs_interesting(x,y, gloc)
|
gather_locs_interesting(x,y, gloc)
|
||||||
@@ -300,10 +304,9 @@ const char *goal;
|
|||||||
static const char pick_chars[] = ".,;:";
|
static const char pick_chars[] = ".,;:";
|
||||||
const char *cp;
|
const char *cp;
|
||||||
boolean hilite_state = FALSE;
|
boolean hilite_state = FALSE;
|
||||||
coord *monarr = (coord *) 0, *objarr = (coord *) 0,
|
coord *garr[NUM_GLOCS] = DUMMY;
|
||||||
*doorarr = (coord *) 0;
|
int gcount[NUM_GLOCS] = DUMMY;
|
||||||
int moncount = 0, monidx = 0, objcount = 0, objidx = 0,
|
int gidx[NUM_GLOCS] = DUMMY;
|
||||||
doorcount = 0, dooridx = 0;
|
|
||||||
|
|
||||||
if (!goal)
|
if (!goal)
|
||||||
goal = "desired location";
|
goal = "desired location";
|
||||||
@@ -424,51 +427,30 @@ const char *goal;
|
|||||||
} else if (c == '@') { /* return to hero's spot */
|
} else if (c == '@') { /* return to hero's spot */
|
||||||
/* reset 'm','M' and 'o','O'; otherwise, there's no way for player
|
/* reset 'm','M' and 'o','O'; otherwise, there's no way for player
|
||||||
to achieve that except by manually cycling through all spots */
|
to achieve that except by manually cycling through all spots */
|
||||||
monidx = objidx = dooridx = 0;
|
for (i = 0; i < NUM_GLOCS; i++)
|
||||||
|
gidx[i] = 0;
|
||||||
cx = u.ux;
|
cx = u.ux;
|
||||||
cy = u.uy;
|
cy = u.uy;
|
||||||
goto nxtc;
|
goto nxtc;
|
||||||
} else if (c == 'm' || c == 'M') { /* nearest or farthest monster */
|
} else if (c == 'm' || c == 'M' /* nearest or farthest monster */
|
||||||
if (!monarr) {
|
|| c == 'o' || c == 'O' /* nearest or farthest object */
|
||||||
gather_locs(&monarr, &moncount, GLOC_MONS);
|
|| c == 'd' || c == 'D') { /* door/doorway */
|
||||||
monidx = 0; /* monarr[0] is hero's spot */
|
int gloc = (c == 'o' || c == 'O') ? GLOC_OBJS
|
||||||
|
: (c == 'd' || c == 'D') ? GLOC_DOOR
|
||||||
|
: GLOC_MONS;
|
||||||
|
|
||||||
|
if (!garr[gloc]) {
|
||||||
|
gather_locs(&garr[gloc], &gcount[gloc], gloc);
|
||||||
|
gidx[gloc] = 0; /* garr[][0] is hero's spot */
|
||||||
}
|
}
|
||||||
if (c == 'm') {
|
if (c == 'm' || c == 'o' || c == 'd') {
|
||||||
monidx = (monidx + 1) % moncount;
|
gidx[gloc] = (gidx[gloc] + 1) % gcount[gloc];
|
||||||
} else {
|
} else {
|
||||||
if (--monidx < 0)
|
if (--gidx[gloc] < 0)
|
||||||
monidx = moncount - 1;
|
gidx[gloc] = gcount[gloc] - 1;
|
||||||
}
|
}
|
||||||
cx = monarr[monidx].x;
|
cx = garr[gloc][gidx[gloc]].x;
|
||||||
cy = monarr[monidx].y;
|
cy = garr[gloc][gidx[gloc]].y;
|
||||||
goto nxtc;
|
|
||||||
} else if (c == 'o' || c == 'O') { /* nearest or farthest object */
|
|
||||||
if (!objarr) {
|
|
||||||
gather_locs(&objarr, &objcount, GLOC_OBJS);
|
|
||||||
objidx = 0; /* objarr[0] is hero's spot */
|
|
||||||
}
|
|
||||||
if (c == 'o') {
|
|
||||||
objidx = (objidx + 1) % objcount;
|
|
||||||
} else {
|
|
||||||
if (--objidx < 0)
|
|
||||||
objidx = objcount - 1;
|
|
||||||
}
|
|
||||||
cx = objarr[objidx].x;
|
|
||||||
cy = objarr[objidx].y;
|
|
||||||
goto nxtc;
|
|
||||||
} else if (c == 'd' || c == 'D') { /* door/doorway */
|
|
||||||
if (!doorarr) {
|
|
||||||
gather_locs(&doorarr, &doorcount, GLOC_DOOR);
|
|
||||||
dooridx = 0; /* objarr[0] is hero's spot */
|
|
||||||
}
|
|
||||||
if (c == 'd') {
|
|
||||||
dooridx = (dooridx + 1) % doorcount;
|
|
||||||
} else {
|
|
||||||
if (--dooridx < 0)
|
|
||||||
dooridx = doorcount - 1;
|
|
||||||
}
|
|
||||||
cx = doorarr[dooridx].x;
|
|
||||||
cy = doorarr[dooridx].y;
|
|
||||||
goto nxtc;
|
goto nxtc;
|
||||||
} else {
|
} else {
|
||||||
if (!index(quitchars, c)) {
|
if (!index(quitchars, c)) {
|
||||||
@@ -564,10 +546,9 @@ const char *goal;
|
|||||||
clear_nhwindow(WIN_MESSAGE);
|
clear_nhwindow(WIN_MESSAGE);
|
||||||
ccp->x = cx;
|
ccp->x = cx;
|
||||||
ccp->y = cy;
|
ccp->y = cy;
|
||||||
if (monarr)
|
for (i = 0; i < NUM_GLOCS; i++)
|
||||||
free((genericptr_t) monarr);
|
if (garr[i])
|
||||||
if (objarr)
|
free((genericptr_t) garr[i]);
|
||||||
free((genericptr_t) objarr);
|
|
||||||
getpos_hilitefunc = (void FDECL((*), (int))) 0;
|
getpos_hilitefunc = (void FDECL((*), (int))) 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user