Use struct to pass data out of mfndpos
Instead of passing two array pointers to mfndpos, fold the data into a specific struct.
This commit is contained in:
@@ -71,6 +71,10 @@
|
||||
#include "artifact.h"
|
||||
#endif
|
||||
|
||||
#ifndef MFNDPOS_H
|
||||
#include "mfndpos.h"
|
||||
#endif
|
||||
|
||||
/* ### alloc.c ### */
|
||||
|
||||
#if 0
|
||||
@@ -1748,7 +1752,7 @@ extern boolean can_touch_safely(struct monst *, struct obj *) NONNULLARG12;
|
||||
extern int can_carry(struct monst *, struct obj *) NONNULLARG12;
|
||||
extern long mon_allowflags(struct monst *) NONNULLARG1;
|
||||
extern boolean m_in_air(struct monst *) NONNULLARG1;
|
||||
extern int mfndpos(struct monst *, coord *, long *, long) NONNULLPTRS;
|
||||
extern int mfndpos(struct monst *, struct mfndposdata *, long) NONNULLPTRS;
|
||||
extern boolean monnear(struct monst *, coordxy, coordxy) NONNULLARG1;
|
||||
extern void dmonsfree(void);
|
||||
extern void elemental_clog(struct monst *) NONNULLARG1;
|
||||
@@ -1918,7 +1922,7 @@ extern boolean accessible(coordxy, coordxy);
|
||||
extern void set_apparxy(struct monst *) NONNULLARG1;
|
||||
extern boolean can_ooze(struct monst *) NONNULLARG1;
|
||||
extern boolean can_fog(struct monst *) NONNULLARG1;
|
||||
extern boolean should_displace(struct monst *, coord *, long *, int, coordxy,
|
||||
extern boolean should_displace(struct monst *, struct mfndposdata, coordxy,
|
||||
coordxy) NONNULLPTRS;
|
||||
extern boolean undesirable_disp(struct monst *, coordxy, coordxy) NONNULLARG1;
|
||||
extern boolean can_hide_under_obj(struct obj *);
|
||||
|
||||
@@ -30,4 +30,10 @@
|
||||
#endif
|
||||
/* clang-format on */
|
||||
|
||||
struct mfndposdata {
|
||||
int cnt;
|
||||
coord poss[9];
|
||||
long info[9];
|
||||
};
|
||||
|
||||
#endif /* MFNDPOS_H */
|
||||
|
||||
@@ -983,8 +983,8 @@ dog_move(
|
||||
coordxy nx, ny; /* temporary coordinates */
|
||||
xint16 cnt, uncursedcnt, chcnt;
|
||||
int chi = -1, nidist, ndist;
|
||||
coord poss[9];
|
||||
long info[9], allowflags;
|
||||
long allowflags;
|
||||
struct mfndposdata mfp;
|
||||
#define GDIST(x, y) (dist2(x, y, gg.gx, gg.gy))
|
||||
|
||||
/*
|
||||
@@ -1020,7 +1020,6 @@ dog_move(
|
||||
nix = omx; /* set before newdogpos */
|
||||
niy = omy;
|
||||
cursemsg[0] = FALSE; /* lint suppression */
|
||||
info[0] = 0; /* ditto */
|
||||
|
||||
if (edog) {
|
||||
j = dog_invent(mtmp, edog, udist);
|
||||
@@ -1054,7 +1053,7 @@ dog_move(
|
||||
}
|
||||
#endif
|
||||
allowflags = mon_allowflags(mtmp);
|
||||
cnt = mfndpos(mtmp, poss, info, allowflags);
|
||||
cnt = mfndpos(mtmp, &mfp, allowflags);
|
||||
|
||||
/* Normally dogs don't step on cursed items, but if they have no
|
||||
* other choice they will. This requires checking ahead of time
|
||||
@@ -1062,16 +1061,16 @@ dog_move(
|
||||
*/
|
||||
uncursedcnt = 0;
|
||||
for (i = 0; i < cnt; i++) {
|
||||
nx = poss[i].x;
|
||||
ny = poss[i].y;
|
||||
if (MON_AT(nx, ny) && !((info[i] & ALLOW_M) || info[i] & ALLOW_MDISP))
|
||||
nx = mfp.poss[i].x;
|
||||
ny = mfp.poss[i].y;
|
||||
if (MON_AT(nx, ny) && !((mfp.info[i] & ALLOW_M) || mfp.info[i] & ALLOW_MDISP))
|
||||
continue;
|
||||
if (cursed_object_at(nx, ny))
|
||||
continue;
|
||||
uncursedcnt++;
|
||||
}
|
||||
|
||||
better_with_displacing = should_displace(mtmp, poss, info, cnt,
|
||||
better_with_displacing = should_displace(mtmp, mfp,
|
||||
gg.gx, gg.gy);
|
||||
|
||||
chcnt = 0;
|
||||
@@ -1079,8 +1078,8 @@ dog_move(
|
||||
nidist = GDIST(nix, niy);
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
nx = poss[i].x;
|
||||
ny = poss[i].y;
|
||||
nx = mfp.poss[i].x;
|
||||
ny = mfp.poss[i].y;
|
||||
cursemsg[i] = FALSE;
|
||||
|
||||
/* if leashed, we drag him along. */
|
||||
@@ -1093,7 +1092,7 @@ dog_move(
|
||||
|
||||
ranged_only = FALSE;
|
||||
|
||||
if ((info[i] & ALLOW_M) && MON_AT(nx, ny)) {
|
||||
if ((mfp.info[i] & ALLOW_M) && MON_AT(nx, ny)) {
|
||||
int mstatus;
|
||||
struct monst *mtmp2 = m_at(nx, ny);
|
||||
/* weight the audacity of the pet to attack a differently-leveled
|
||||
@@ -1162,7 +1161,7 @@ dog_move(
|
||||
}
|
||||
return MMOVE_DONE;
|
||||
}
|
||||
if ((info[i] & ALLOW_MDISP) && MON_AT(nx, ny)
|
||||
if ((mfp.info[i] & ALLOW_MDISP) && MON_AT(nx, ny)
|
||||
&& better_with_displacing && !undesirable_disp(mtmp, nx, ny)) {
|
||||
int mstatus;
|
||||
struct monst *mtmp2 = m_at(nx, ny);
|
||||
@@ -1189,7 +1188,7 @@ dog_move(
|
||||
*/
|
||||
struct trap *trap;
|
||||
|
||||
if ((info[i] & ALLOW_TRAPS) && (trap = t_at(nx, ny))) {
|
||||
if ((mfp.info[i] & ALLOW_TRAPS) && (trap = t_at(nx, ny))) {
|
||||
if (mtmp->mleashed) {
|
||||
if (!Deaf)
|
||||
whimper(mtmp);
|
||||
@@ -1271,7 +1270,7 @@ dog_move(
|
||||
if (nix != omx || niy != omy) {
|
||||
boolean wasseen;
|
||||
|
||||
if (info[chi] & ALLOW_U) {
|
||||
if (mfp.info[chi] & ALLOW_U) {
|
||||
if (mtmp->mleashed) { /* play it safe */
|
||||
pline_mon(mtmp, "%s breaks loose of %s leash!",
|
||||
Monnam(mtmp), mhis(mtmp));
|
||||
|
||||
34
src/mon.c
34
src/mon.c
@@ -2111,8 +2111,7 @@ m_in_air(struct monst *mtmp)
|
||||
int
|
||||
mfndpos(
|
||||
struct monst *mon,
|
||||
coord *poss, /* coord poss[9] */
|
||||
long *info, /* long info[9] */
|
||||
struct mfndposdata *data,
|
||||
long flag)
|
||||
{
|
||||
struct permonst *mdat = mon->data;
|
||||
@@ -2132,6 +2131,8 @@ mfndpos(
|
||||
y = mon->my;
|
||||
nowtyp = levl[x][y].typ;
|
||||
|
||||
(void)memset((genericptr_t) data, 0, sizeof(struct mfndposdata));
|
||||
|
||||
nodiag = NODIAG(mdat - mons);
|
||||
wantpool = (mdat->mlet == S_EEL);
|
||||
poolok = ((!Is_waterlevel(&u.uz) && m_in_air(mon))
|
||||
@@ -2247,11 +2248,11 @@ mfndpos(
|
||||
dispy = ny;
|
||||
}
|
||||
|
||||
info[cnt] = 0;
|
||||
data->info[cnt] = 0;
|
||||
if (onscary(dispx, dispy, mon)) {
|
||||
if (!(flag & ALLOW_SSM))
|
||||
continue;
|
||||
info[cnt] |= ALLOW_SSM;
|
||||
data->info[cnt] |= ALLOW_SSM;
|
||||
}
|
||||
if (u_at(nx, ny)
|
||||
|| (nx == mon->mux && ny == mon->muy)) {
|
||||
@@ -2267,25 +2268,25 @@ mfndpos(
|
||||
}
|
||||
if (!(flag & ALLOW_U))
|
||||
continue;
|
||||
info[cnt] |= ALLOW_U;
|
||||
data->info[cnt] |= ALLOW_U;
|
||||
} else {
|
||||
if (MON_AT(nx, ny)) {
|
||||
struct monst *mtmp2 = m_at(nx, ny);
|
||||
long mmflag = flag | mm_aggression(mon, mtmp2);
|
||||
|
||||
if (mmflag & ALLOW_M) {
|
||||
info[cnt] |= ALLOW_M;
|
||||
data->info[cnt] |= ALLOW_M;
|
||||
if (mtmp2->mtame) {
|
||||
if (!(mmflag & ALLOW_TM))
|
||||
continue;
|
||||
info[cnt] |= ALLOW_TM;
|
||||
data->info[cnt] |= ALLOW_TM;
|
||||
}
|
||||
} else {
|
||||
flag &= ~ALLOW_MDISP; /* depends upon defender */
|
||||
mmflag = flag | mm_displacement(mon, mtmp2);
|
||||
if (!(mmflag & ALLOW_MDISP))
|
||||
continue;
|
||||
info[cnt] |= ALLOW_MDISP;
|
||||
data->info[cnt] |= ALLOW_MDISP;
|
||||
}
|
||||
}
|
||||
/* Note: ALLOW_SANCT only prevents movement, not
|
||||
@@ -2296,23 +2297,23 @@ mfndpos(
|
||||
&& in_your_sanctuary((struct monst *) 0, nx, ny)) {
|
||||
if (!(flag & ALLOW_SANCT))
|
||||
continue;
|
||||
info[cnt] |= ALLOW_SANCT;
|
||||
data->info[cnt] |= ALLOW_SANCT;
|
||||
}
|
||||
}
|
||||
if (checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
|
||||
if (flag & NOGARLIC)
|
||||
continue;
|
||||
info[cnt] |= NOGARLIC;
|
||||
data->info[cnt] |= NOGARLIC;
|
||||
}
|
||||
if (checkobj && sobj_at(BOULDER, nx, ny)) {
|
||||
if (!(flag & ALLOW_ROCK))
|
||||
continue;
|
||||
info[cnt] |= ALLOW_ROCK;
|
||||
data->info[cnt] |= ALLOW_ROCK;
|
||||
}
|
||||
if (monseeu && monlineu(mon, nx, ny)) {
|
||||
if (flag & NOTONL)
|
||||
continue;
|
||||
info[cnt] |= NOTONL;
|
||||
data->info[cnt] |= NOTONL;
|
||||
}
|
||||
/* check for diagonal tight squeeze */
|
||||
if (nx != x && ny != y && bad_rock(mdat, x, ny)
|
||||
@@ -2332,17 +2333,17 @@ mfndpos(
|
||||
}
|
||||
/* fixed-destination teleport trap, was used by hero */
|
||||
if (fixed_tele_trap(ttmp) && hastrack(nx, ny))
|
||||
info[cnt] |= ALLOW_TRAPS;
|
||||
data->info[cnt] |= ALLOW_TRAPS;
|
||||
else if (!m_harmless_trap(mon, ttmp)) {
|
||||
if (!(flag & ALLOW_TRAPS)) {
|
||||
if (mon_knows_traps(mon, ttmp->ttyp))
|
||||
continue;
|
||||
}
|
||||
info[cnt] |= ALLOW_TRAPS;
|
||||
data->info[cnt] |= ALLOW_TRAPS;
|
||||
}
|
||||
}
|
||||
poss[cnt].x = nx;
|
||||
poss[cnt].y = ny;
|
||||
data->poss[cnt].x = nx;
|
||||
data->poss[cnt].y = ny;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
@@ -2350,6 +2351,7 @@ mfndpos(
|
||||
wantpool = FALSE;
|
||||
goto nexttry;
|
||||
}
|
||||
data->cnt = cnt;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
@@ -1069,9 +1069,7 @@ itsstuck(struct monst *mtmp)
|
||||
boolean
|
||||
should_displace(
|
||||
struct monst *mtmp,
|
||||
coord *poss, /* coord poss[9] */
|
||||
long *info, /* long info[9] */
|
||||
int cnt,
|
||||
struct mfndposdata data,
|
||||
coordxy ggx,
|
||||
coordxy ggy)
|
||||
{
|
||||
@@ -1081,11 +1079,11 @@ should_displace(
|
||||
int i, nx, ny;
|
||||
int ndist;
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
nx = poss[i].x;
|
||||
ny = poss[i].y;
|
||||
for (i = 0; i < data.cnt; i++) {
|
||||
nx = data.poss[i].x;
|
||||
ny = data.poss[i].y;
|
||||
ndist = dist2(nx, ny, ggx, ggy);
|
||||
if (MON_AT(nx, ny) && (info[i] & ALLOW_MDISP) && !(info[i] & ALLOW_M)
|
||||
if (MON_AT(nx, ny) && (data.info[i] & ALLOW_MDISP) && !(data.info[i] & ALLOW_M)
|
||||
&& !undesirable_disp(mtmp, nx, ny)) {
|
||||
if (shortest_with_displacing == -1
|
||||
|| (ndist < shortest_with_displacing))
|
||||
@@ -1726,7 +1724,7 @@ m_move(struct monst *mtmp, int after)
|
||||
struct permonst *ptr;
|
||||
int chi, mmoved = MMOVE_NOTHING, /* not strictly nec.: chi >= 0 will do */
|
||||
preferredrange_min = 0, preferredrange_max = 0;
|
||||
long info[9];
|
||||
struct mfndposdata mfp;
|
||||
long flag;
|
||||
coordxy omx = mtmp->mx, omy = mtmp->my;
|
||||
|
||||
@@ -1922,9 +1920,8 @@ m_move(struct monst *mtmp, int after)
|
||||
int jcnt, cnt;
|
||||
int ndist, nidist;
|
||||
coord *mtrk;
|
||||
coord poss[9];
|
||||
|
||||
cnt = mfndpos(mtmp, poss, info, flag);
|
||||
cnt = mfndpos(mtmp, &mfp, flag);
|
||||
if (cnt == 0 && !is_unicorn(mtmp->data)) {
|
||||
if (find_defensive(mtmp, TRUE) && use_defensive(mtmp))
|
||||
return MMOVE_DONE;
|
||||
@@ -1941,22 +1938,22 @@ m_move(struct monst *mtmp, int after)
|
||||
if (is_unicorn(ptr) && noteleport_level(mtmp)) {
|
||||
/* on noteleport levels, perhaps we cannot avoid hero */
|
||||
for (i = 0; i < cnt; i++)
|
||||
if (!(info[i] & NOTONL))
|
||||
if (!(mfp.info[i] & NOTONL))
|
||||
avoid = TRUE;
|
||||
}
|
||||
better_with_displacing =
|
||||
should_displace(mtmp, poss, info, cnt, ggx, ggy);
|
||||
should_displace(mtmp, mfp, ggx, ggy);
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (avoid && (info[i] & NOTONL))
|
||||
if (avoid && (mfp.info[i] & NOTONL))
|
||||
continue;
|
||||
nx = poss[i].x;
|
||||
ny = poss[i].y;
|
||||
nx = mfp.poss[i].x;
|
||||
ny = mfp.poss[i].y;
|
||||
|
||||
if (m_avoid_kicked_loc(mtmp, nx, ny))
|
||||
continue;
|
||||
|
||||
if (MON_AT(nx, ny) && (info[i] & ALLOW_MDISP)
|
||||
&& !(info[i] & ALLOW_M) && !better_with_displacing)
|
||||
if (MON_AT(nx, ny) && (mfp.info[i] & ALLOW_MDISP)
|
||||
&& !(mfp.info[i] & ALLOW_M) && !better_with_displacing)
|
||||
continue;
|
||||
if (appr != 0) {
|
||||
mtrk = &mtmp->mtrack[0];
|
||||
@@ -2004,8 +2001,8 @@ m_move(struct monst *mtmp, int after)
|
||||
* mfndpos) has no effect for normal attacks, though it lets a
|
||||
* confused monster attack you by accident.
|
||||
*/
|
||||
assert(IndexOk(chi, info));
|
||||
if (info[chi] & ALLOW_U) {
|
||||
assert(IndexOk(chi, mfp.info));
|
||||
if (mfp.info[chi] & ALLOW_U) {
|
||||
nix = mtmp->mux;
|
||||
niy = mtmp->muy;
|
||||
}
|
||||
@@ -2020,11 +2017,11 @@ m_move(struct monst *mtmp, int after)
|
||||
* Pets get taken care of above and shouldn't reach this code.
|
||||
* Conflict gets handled even farther away (movemon()).
|
||||
*/
|
||||
if ((info[chi] & ALLOW_M) != 0
|
||||
if ((mfp.info[chi] & ALLOW_M) != 0
|
||||
|| (nix == mtmp->mux && niy == mtmp->muy))
|
||||
return m_move_aggress(mtmp, nix, niy);
|
||||
|
||||
if ((info[chi] & ALLOW_MDISP) != 0) {
|
||||
if ((mfp.info[chi] & ALLOW_MDISP) != 0) {
|
||||
struct monst *mtmp2;
|
||||
int mstatus;
|
||||
|
||||
@@ -2041,7 +2038,7 @@ m_move(struct monst *mtmp, int after)
|
||||
if (!m_in_out_region(mtmp, nix, niy))
|
||||
return MMOVE_DONE;
|
||||
|
||||
if ((info[chi] & ALLOW_ROCK) && m_can_break_boulder(mtmp)) {
|
||||
if ((mfp.info[chi] & ALLOW_ROCK) && m_can_break_boulder(mtmp)) {
|
||||
(void) m_break_boulder(mtmp, nix, niy);
|
||||
return MMOVE_DONE;
|
||||
}
|
||||
|
||||
17
src/priest.c
17
src/priest.c
@@ -46,8 +46,7 @@ move_special(struct monst *mtmp, boolean in_his_shop, schar appr,
|
||||
coordxy nx, ny, nix, niy;
|
||||
schar i;
|
||||
schar chcnt, cnt;
|
||||
coord poss[9];
|
||||
long info[9];
|
||||
struct mfndposdata mfp;
|
||||
long ninfo = 0;
|
||||
long allowflags;
|
||||
#if 0 /* dead code; see below */
|
||||
@@ -64,11 +63,11 @@ move_special(struct monst *mtmp, boolean in_his_shop, schar appr,
|
||||
nix = omx;
|
||||
niy = omy;
|
||||
allowflags = mon_allowflags(mtmp);
|
||||
cnt = mfndpos(mtmp, poss, info, allowflags);
|
||||
cnt = mfndpos(mtmp, &mfp, allowflags);
|
||||
|
||||
if (mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */
|
||||
for (i = 0; i < cnt; i++)
|
||||
if (!(info[i] & NOTONL))
|
||||
if (!(mfp.info[i] & NOTONL))
|
||||
goto pick_move;
|
||||
avoid = FALSE;
|
||||
}
|
||||
@@ -77,18 +76,18 @@ move_special(struct monst *mtmp, boolean in_his_shop, schar appr,
|
||||
pick_move:
|
||||
chcnt = 0;
|
||||
for (i = 0; i < cnt; i++) {
|
||||
nx = poss[i].x;
|
||||
ny = poss[i].y;
|
||||
nx = mfp.poss[i].x;
|
||||
ny = mfp.poss[i].y;
|
||||
if (IS_ROOM(levl[nx][ny].typ)
|
||||
|| (mtmp->isshk && (!in_his_shop || ESHK(mtmp)->following))) {
|
||||
if (avoid && (info[i] & NOTONL) && !(info[i] & ALLOW_M))
|
||||
if (avoid && (mfp.info[i] & NOTONL) && !(mfp.info[i] & ALLOW_M))
|
||||
continue;
|
||||
if ((!appr && !rn2(++chcnt))
|
||||
|| (appr && GDIST(nx, ny) < GDIST(nix, niy))
|
||||
|| (info[i] & ALLOW_M)) {
|
||||
|| (mfp.info[i] & ALLOW_M)) {
|
||||
nix = nx;
|
||||
niy = ny;
|
||||
ninfo = info[i];
|
||||
ninfo = mfp.info[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user