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:
Pasi Kallinen
2026-01-04 13:56:02 +02:00
parent 01928276d5
commit 37df18b59c
6 changed files with 70 additions and 63 deletions

View File

@@ -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;
}