]> granicus.if.org Git - nethack/commitdiff
Move mtrack push and clear to separate functions
authorPasi Kallinen <paxed@alt.org>
Sat, 16 Jul 2022 15:43:22 +0000 (18:43 +0300)
committerPasi Kallinen <paxed@alt.org>
Sat, 16 Jul 2022 15:43:22 +0000 (18:43 +0300)
include/extern.h
src/dog.c
src/dogmove.c
src/makemon.c
src/mon.c
src/monmove.c
src/teleport.c

index 604ac1ca6fed07776daad8f86eed5c04a6e384ef..c3adf532c399fc04ab702944ebf98d868182a4e2 100644 (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);
index 64b06b8c00cae592ad554ec01b10ff00f0b5cc0f..9ed76097e9f950f6966ea4d8cdedf26e91fe14bf 100644 (file)
--- a/src/dog.c
+++ b/src/dog.c
@@ -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 */
index b774490d5def0f6982ccf724dd664bad4e05df5b..8b746c7a48659f92249023e0e3960e51c1ccd771 100644 (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.
index 531a9b99e7f999aa23820f3016202894bca7d101..de0e7729701b18ada998c257f775d004f724e5a4 100644 (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))
index 517054ff4af02894d723532d0aa0352253e54963..d7f6e9c8b8459dc05310fb3965e4d39e3b8b7bd6 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -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);
             }
         }
     }
index cb9eec9e6b90d18ce7dbb1cedaa90cdd31d16ff8..c2c8f3478b50be361da9ce954ded7cd160352f84 100644 (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);
index 35f9cd09c0a729fb8babaf31ebd64424c98fdbd2..4374d0e3cf78ee5ac3bed157f8e65d3757a58789 100644 (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);