]> granicus.if.org Git - nethack/commitdiff
drawbridge revisited
authorPatR <rankin@nethack.org>
Tue, 28 Feb 2023 20:14:23 +0000 (12:14 -0800)
committerPatR <rankin@nethack.org>
Tue, 28 Feb 2023 20:14:23 +0000 (12:14 -0800)
Take the DEADMONSTER() check back out.  It adds some protection
against something that should never happen but also adds confusion
that it might actually happen.  Dead monsters aren't on the map.

Avoid 'if (cond) foo();' without braces if foo() might expand into
nothing.

Clean up the occupants[] array when finishing with drawbridge.

src/dbridge.c

index 8244e9a28c1906f20c509708c401d36c7c74f4fe..857b3f1498d6788f9b81370fa3a12ced6971eee8 100644 (file)
@@ -32,6 +32,7 @@ static boolean automiss(struct entity *);
 static boolean e_missed(struct entity *, boolean);
 static boolean e_jumps(struct entity *);
 static void do_entity(struct entity *);
+static void nokiller(void);
 
 boolean
 is_waterwall(coordxy x, coordxy y)
@@ -306,8 +307,10 @@ m_to_e(struct monst *mtmp, coordxy x, coordxy y, struct entity *etmp)
             etmp->edata = &mons[PM_LONG_WORM_TAIL];
         else
             etmp->edata = mtmp->data;
-    } else
+    } else {
         etmp->edata = (struct permonst *) 0;
+        etmp->ex = etmp->ey = 0;
+    }
 }
 
 static void
@@ -320,16 +323,14 @@ u_to_e(struct entity *etmp)
 }
 
 static void
-set_entity(coordxy x, coordxy y, struct entity *etmp)
+set_entity(
+    coordxy x, coordxy y, /* location of span or portcullis */
+    struct entity *etmp)  /* pointer to occupants[0] or occupants[1] */
 {
-    struct monst *mtmp;
-
     if (u_at(x, y))
         u_to_e(etmp);
-    else if ((mtmp = m_at(x, y)) != 0 && !DEADMONSTER(mtmp))
-        m_to_e(mtmp, x, y, etmp);
-    else
-        etmp->edata = (struct permonst *) 0;
+    else /* m_at() might yield Null; that's ok */
+        m_to_e(m_at(x, y), x, y, etmp);
 }
 
 #define is_u(etmp) (etmp->emon == &gy.youmonst)
@@ -731,8 +732,15 @@ do_entity(struct entity *etmp)
     }
 }
 
-/* clear stale reason for death before returning */
-#define nokiller() (gk.killer.name[0] = '\0', gk.killer.format = 0)
+/* clear stale reason for death and both 'entities' before returning */
+static void
+nokiller(void)
+{
+    gk.killer.name[0] = '\0';
+    gk.killer.format = 0;
+    m_to_e((struct monst *) 0, 0, 0, &go.occupants[0]);
+    m_to_e((struct monst *) 0, 0, 0, &go.occupants[1]);
+}
 
 /*
  * Close the drawbridge located at x,y
@@ -873,8 +881,7 @@ destroy_drawbridge(coordxy x, coordxy y)
         struct obj *otmp2;
         boolean lava = (lev1->drawbridgemask & DB_UNDER) == DB_LAVA;
 
-        if (!Deaf)
-            Soundeffect(se_loud_splash, 100);
+        Soundeffect(se_loud_splash, 100);  /* Deaf-aware */
         if (lev1->typ == DRAWBRIDGE_UP) {
             if (cansee(x2, y2) || u_at(x2, y2))
                 pline_The("portcullis of the drawbridge falls into the %s!",
@@ -896,8 +903,7 @@ destroy_drawbridge(coordxy x, coordxy y)
         }
     } else {
         /* no moat beneath */
-        if (!Deaf)
-            Soundeffect(se_lound_crash, 100);
+        Soundeffect(se_lound_crash, 100);  /* Deaf-aware */
         if (cansee(x, y) || u_at(x, y))
             pline_The("drawbridge disintegrates!");
         else