Move mtrack push and clear to separate functions

This commit is contained in:
Pasi Kallinen
2022-07-16 18:43:22 +03:00
parent fcbeed21cc
commit 94c1e94d20
7 changed files with 28 additions and 17 deletions

View File

@@ -1641,6 +1641,8 @@ extern boolean resist_conflict(struct monst *);
extern boolean itsstuck(struct monst *);
extern boolean mb_trapped(struct monst *, boolean);
extern void mon_track_add(struct monst *, coordxy, coordxy);
extern void mon_track_clear(struct monst *);
extern boolean monhaskey(struct monst *, boolean);
extern void mon_regen(struct monst *, boolean);
extern int dochugw(struct monst *, boolean);

View File

@@ -357,7 +357,7 @@ mon_arrive(struct monst *mtmp, int when)
ylocale = mtmp->mtrack[1].y;
fromdlev.dnum = mtmp->mtrack[2].x;
fromdlev.dlevel = mtmp->mtrack[2].y;
memset(mtmp->mtrack, 0, sizeof mtmp->mtrack);
mon_track_clear(mtmp);
if (mtmp == u.usteed)
return; /* don't place steed on the map */

View File

@@ -1278,10 +1278,7 @@ dog_move(register struct monst *mtmp,
pline("%s %s reluctantly over %s.", noit_Monnam(mtmp),
vtense((char *) 0, locomotion(mtmp->data, "step")), what);
}
for (j = MTSZ - 1; j > 0; j--)
mtmp->mtrack[j] = mtmp->mtrack[j - 1];
mtmp->mtrack[0].x = omx;
mtmp->mtrack[0].y = omy;
mon_track_add(mtmp, omx, omy);
/* We have to know if the pet's going to do a combined eat and
* move before moving it, but it can't eat until after being
* moved. Thus the do_eat flag.

View File

@@ -871,7 +871,7 @@ clone_mon(struct monst *mon,
/* ms->isminion handled below */
/* clone shouldn't be reluctant to move on spots 'parent' just moved on */
(void) memset((genericptr_t) m2->mtrack, 0, sizeof m2->mtrack);
mon_track_clear(m2);
place_monster(m2, m2->mx, m2->my);
if (emits_light(m2->data))

View File

@@ -3788,9 +3788,8 @@ wake_nearto(coordxy x, coordxy y, int distance)
if (mtmp->mtame) {
if (!mtmp->isminion)
EDOG(mtmp)->whistletime = g.moves;
/* Clear mtrack. This is to fix up a pet who is
stuck "fleeing" its master. */
memset(mtmp->mtrack, 0, sizeof mtmp->mtrack);
/* Fix up a pet who is stuck "fleeing" its master */
mon_track_clear(mtmp);
}
}
}

View File

@@ -48,6 +48,24 @@ mb_trapped(struct monst *mtmp, boolean canseeit)
return FALSE;
}
/* push coordinate x,y to mtrack, making monster remember where it was */
void
mon_track_add(struct monst *mtmp, coordxy x, coordxy y)
{
int j;
for (j = MTSZ - 1; j > 0; j--)
mtmp->mtrack[j] = mtmp->mtrack[j - 1];
mtmp->mtrack[0].x = x;
mtmp->mtrack[0].y = y;
}
void
mon_track_clear(struct monst *mtmp)
{
memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
}
/* check whether a monster is carrying a locking/unlocking tool */
boolean
monhaskey(
@@ -394,7 +412,7 @@ monflee(
mtmp->mflee = 1;
}
/* ignore recently-stepped spaces when made to flee */
memset(mtmp->mtrack, 0, sizeof(mtmp->mtrack));
mon_track_clear(mtmp);
}
static void
@@ -1373,8 +1391,6 @@ m_move(register struct monst* mtmp, register int after)
}
if (mmoved) {
register int j;
if (mmoved == MMOVE_MOVED && (u.ux != nix || u.uy != niy) && itsstuck(mtmp))
return MMOVE_DONE;
@@ -1439,10 +1455,7 @@ m_move(register struct monst* mtmp, register int after)
maybe_unhide_at(mtmp->mx, mtmp->my);
for (j = MTSZ - 1; j > 0; j--)
mtmp->mtrack[j] = mtmp->mtrack[j - 1];
mtmp->mtrack[0].x = omx;
mtmp->mtrack[0].y = omy;
mon_track_add(mtmp, omx, omy);
} else {
if (is_unicorn(ptr) && rn2(2) && !tele_restrict(mtmp)) {
(void) rloc(mtmp, RLOC_MSG);

View File

@@ -1313,7 +1313,7 @@ rloc_to_core(
}
}
memset(mtmp->mtrack, 0, sizeof mtmp->mtrack);
mon_track_clear(mtmp);
place_monster(mtmp, x, y); /* put monster down */
update_monster_region(mtmp);