]> granicus.if.org Git - nethack/commitdiff
glyph macro formatting
authorPatR <rankin@nethack.org>
Sat, 16 Jul 2022 22:36:25 +0000 (15:36 -0700)
committerPatR <rankin@nethack.org>
Sat, 16 Jul 2022 22:36:25 +0000 (15:36 -0700)
Change some more
  (first_line <op> \
   second_line)
to
  (first_line \
   <op> second_line)
for various values of <op> besides '&&' and '||'.  Also clean up some
indentation and backslash+newline alignment.

For object_is_piletop() don't bother to validate that an object which
is classified as being on the floor is actually on the floor at its
specified map coordinates.  That check was propagating to expansions
of multiple macros and if it ever failed it would just be hiding a
very serious bug without helping to fix that.

include/defsym.h
include/display.h

index 57b6d1599ba3fdee3869d67c289e9c69453e5437..34879231df6c51bb365c1165152a19ef197dd1b6 100644 (file)
     PCHAR2( 2, '-',  S_hwall, "horizontal wall", "wall",  CLR(CLR_GRAY))
     PCHAR2( 3, '-',  S_tlcorn, "top left corner wall", "wall",  CLR(CLR_GRAY))
     PCHAR2( 4, '-',  S_trcorn, "top right corner wall", "wall",  CLR(CLR_GRAY))
-    PCHAR2( 5, '-',  S_blcorn, "bottom left corner wall", "wall", CLR(CLR_GRAY))
-    PCHAR2( 6, '-',  S_brcorn, "bottom right corner wall", "wall", CLR(CLR_GRAY))
+    PCHAR2( 5, '-',  S_blcorn,
+           "bottom left corner wall", "wall", CLR(CLR_GRAY))
+    PCHAR2( 6, '-',  S_brcorn,
+           "bottom right corner wall", "wall", CLR(CLR_GRAY))
     PCHAR2( 7, '-',  S_crwall, "cross wall", "wall", CLR(CLR_GRAY))
     PCHAR2( 8, '-',  S_tuwall, "tuwall", "wall", CLR(CLR_GRAY))
     PCHAR2( 9, '-',  S_tdwall, "tdwall", "wall", CLR(CLR_GRAY))
     PCHAR2(11, '|',  S_trwall, "trwall", "wall", CLR(CLR_GRAY))
     /* start cmap A                                                      */
     PCHAR2(12, '.',  S_ndoor, "no door", "doorway", CLR(CLR_GRAY))
-    PCHAR2(13, '-',  S_vodoor, "vertical open door", "open door", CLR(CLR_BROWN))
-    PCHAR2(14, '|',  S_hodoor, "horizontal open door", "open door", CLR(CLR_BROWN))
+    PCHAR2(13, '-',  S_vodoor,
+           "vertical open door", "open door", CLR(CLR_BROWN))
+    PCHAR2(14, '|',  S_hodoor,
+           "horizontal open door", "open door", CLR(CLR_BROWN))
     PCHAR2(15, '+',  S_vcdoor,
            "vertical closed door", "closed door", CLR(CLR_BROWN))
     PCHAR2(16, '+',  S_hcdoor,
index cdd5a81a6db336287c87a4f7af271c6dd585feb0..969b37ec3540055575d81e6a7abf751e3c1f7d5a 100644 (file)
@@ -17,7 +17,7 @@
  * vobj_at()
  *
  * Returns the head of the list of objects that the player can see
- * at location (x,y).
+ * at location (x,y).  [Vestige of unimplemented invisible objects.]
  */
 #define vobj_at(x, y) (g.level.objects[x][y])
 
@@ -541,18 +541,20 @@ enum glyph_offsets {
 
 #define warning_to_glyph(mwarnlev) ((mwarnlev) + GLYPH_WARNING_OFF)
 #define mon_to_glyph(mon, rng) \
-    ((int) what_mon(monsndx((mon)->data), rng) + \
-            (((mon)->female == 0) ?  GLYPH_MON_MALE_OFF : GLYPH_MON_FEM_OFF))
+    ((int) what_mon(monsndx((mon)->data), rng)                          \
+     + (((mon)->female == 0) ?  GLYPH_MON_MALE_OFF : GLYPH_MON_FEM_OFF))
 #define detected_mon_to_glyph(mon, rng) \
-    ((int) what_mon(monsndx((mon)->data), rng) + \
-            (((mon)->female == 0) ?  GLYPH_DETECT_MALE_OFF : GLYPH_DETECT_FEM_OFF))
+    ((int) what_mon(monsndx((mon)->data), rng)                          \
+     + (((mon)->female == 0) ?  GLYPH_DETECT_MALE_OFF : GLYPH_DETECT_FEM_OFF))
 #define ridden_mon_to_glyph(mon, rng) \
-    ((int) what_mon(monsndx((mon)->data), rng) + \
-            (((mon)->female == 0) ?  GLYPH_RIDDEN_MALE_OFF : GLYPH_RIDDEN_FEM_OFF))
+    ((int) what_mon(monsndx((mon)->data), rng)                          \
+     + (((mon)->female == 0) ?  GLYPH_RIDDEN_MALE_OFF : GLYPH_RIDDEN_FEM_OFF))
 #define pet_to_glyph(mon, rng) \
-    ((int) what_mon(monsndx((mon)->data), rng) + \
-            (((mon)->female == 0) ? GLYPH_PET_MALE_OFF : GLYPH_PET_FEM_OFF))
+    ((int) what_mon(monsndx((mon)->data), rng)                          \
+     + (((mon)->female == 0) ? GLYPH_PET_MALE_OFF : GLYPH_PET_FEM_OFF))
 
+/* treat unaligned as the default instead of explicitly checking for it;
+   altar alignment uses 3 bits with 4 defined values and 4 unused ones */
 #define altar_to_glyph(amsk) \
     ((((amsk) & AM_SANCTUM) == AM_SANCTUM)                \
       ? (GLYPH_ALTAR_OFF + altar_other)                   \
@@ -562,9 +564,8 @@ enum glyph_offsets {
             ? (GLYPH_ALTAR_OFF + altar_neutral)           \
             : (((amsk) & AM_MASK) == AM_CHAOTIC)          \
                ? (GLYPH_ALTAR_OFF + altar_chaotic)        \
-               : (((amsk) & AM_MASK) == AM_NONE)          \
-                  ? (GLYPH_ALTAR_OFF + altar_unaligned)   \
-                  : (GLYPH_ALTAR_OFF + altar_neutral))
+               /* (((amsk) & AM_MASK) == AM_UNALIGNED) */ \
+               : (GLYPH_ALTAR_OFF + altar_unaligned))
 
 /* not used, nor is it correct
 #define zap_to_glyph(zaptype, cmap_idx) \
@@ -613,7 +614,7 @@ enum glyph_offsets {
     : ((cmap_idx) == S_altar)   ? altar_to_glyph(AM_NEUTRAL)                \
     : ((cmap_idx) <  S_arrow_trap + MAXTCHARS) ? cmap_b_to_glyph(cmap_idx)  \
     : ((cmap_idx) <= S_goodpos) ? cmap_c_to_glyph(cmap_idx)                 \
-    : NO_GLYPH )
+      : NO_GLYPH )
 
 #define trap_to_glyph(trap)                                \
     cmap_to_glyph(trap_to_defsym(((int) (trap)->ttyp)))
@@ -636,7 +637,7 @@ enum glyph_offsets {
 
 /* The hero's glyph when seen as a monster.
  */
-#define hero_glyph                                                      \
+#define hero_glyph \
     monnum_to_glyph((Upolyd || !flags.showrace) ? u.umonnum : g.urace.mnum, \
                     (Ugender))
 
@@ -754,20 +755,20 @@ enum glyph_offsets {
 #define glyph_is_pet(glyph) \
     (glyph_is_male_pet(glyph) || glyph_is_female_pet(glyph))
 #define glyph_is_ridden_female_monster(glyph) \
-    ((glyph) >= GLYPH_RIDDEN_FEM_OFF && (glyph) < \
-        (GLYPH_RIDDEN_FEM_OFF + NUMMONS))
+    ((glyph) >= GLYPH_RIDDEN_FEM_OFF                    \
+     && (glyph) < (GLYPH_RIDDEN_FEM_OFF + NUMMONS))
 #define glyph_is_ridden_male_monster(glyph) \
-    ((glyph) >= GLYPH_RIDDEN_MALE_OFF && (glyph) < \
-        (GLYPH_RIDDEN_MALE_OFF + NUMMONS))
+    ((glyph) >= GLYPH_RIDDEN_MALE_OFF                   \
+     && (glyph) < (GLYPH_RIDDEN_MALE_OFF + NUMMONS))
 #define glyph_is_ridden_monster(glyph) \
     (glyph_is_ridden_male_monster(glyph) \
         || glyph_is_ridden_female_monster(glyph))
 #define glyph_is_detected_female_monster(glyph) \
-    ((glyph) >= GLYPH_DETECT_FEM_OFF && (glyph) < \
-        (GLYPH_DETECT_FEM_OFF + NUMMONS))
+    ((glyph) >= GLYPH_DETECT_FEM_OFF                    \
+     && (glyph) < (GLYPH_DETECT_FEM_OFF + NUMMONS))
 #define glyph_is_detected_male_monster(glyph) \
-    ((glyph) >= GLYPH_DETECT_MALE_OFF && (glyph) < \
-        (GLYPH_DETECT_MALE_OFF + NUMMONS))
+    ((glyph) >= GLYPH_DETECT_MALE_OFF                   \
+     && (glyph) < (GLYPH_DETECT_MALE_OFF + NUMMONS))
 #define glyph_is_detected_monster(glyph) \
     (glyph_is_detected_male_monster(glyph) \
         || glyph_is_detected_female_monster(glyph))
@@ -796,16 +797,16 @@ enum glyph_offsets {
                        : NO_GLYPH)
 
 #define obj_is_piletop(obj) \
-    ((obj)->where == OBJ_FLOOR                                   \
-        && g.level.objects[(obj)->ox][(obj)->oy]                  \
-            && g.level.objects[(obj)->ox][(obj)->oy]->nexthere)
+    ((obj)->where == OBJ_FLOOR                                  \
+        /*&& g.level.objects[(obj)->ox][(obj)->oy]*/            \
+        && g.level.objects[(obj)->ox][(obj)->oy]->nexthere)
 
 #define glyph_is_body_piletop(glyph) \
-    (((glyph) >= GLYPH_BODY_PILETOP_OFF) \
-                 && ((glyph) < (GLYPH_BODY_PILETOP_OFF + NUMMONS)))
+    (((glyph) >= GLYPH_BODY_PILETOP_OFF)                        \
+     && ((glyph) < (GLYPH_BODY_PILETOP_OFF + NUMMONS)))
 #define glyph_is_body(glyph) \
     ((((glyph) >= GLYPH_BODY_OFF) && ((glyph) < (GLYPH_BODY_OFF + NUMMONS))) \
-    || glyph_is_body_piletop(glyph))
+     || glyph_is_body_piletop(glyph))
 
 #define glyph_is_fem_statue_piletop(glyph) \
     (((glyph) >= GLYPH_STATUE_FEM_PILETOP_OFF)                  \
@@ -833,23 +834,24 @@ enum glyph_offsets {
 
 #if 0
 #define glyph_is_object(glyph) \
-((((glyph) >= GLYPH_OBJ_OFF) && ((glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS))) \
- || (((glyph) >= GLYPH_OBJ_PILETOP_OFF) \
-     && ((glyph) < (GLYPH_OBJ_PILETOP_OFF + NUM_OBJECTS))) \
- || (((glyph) >= GLYPH_STATUE_MALE_OFF) \
-     && ((glyph) < (GLYPH_STATUE_MALE_OFF + NUMMONS))) \
- || (((glyph) >= GLYPH_STATUE_MALE_PILETOP_OFF) \
-     && ((glyph) < (GLYPH_STATUE_MALE_PILETOP_OFF + NUMMONS))) \
- || (((glyph) >= GLYPH_STATUE_FEM_OFF) \
-     && ((glyph) < (GLYPH_STATUE_FEM_OFF + NUMMONS))) \
- || (((glyph) >= GLYPH_STATUE_FEM_PILETOP_OFF) \
-     && ((glyph) < (GLYPH_STATUE_FEM_PILETOP_OFF + NUMMONS))) \
- || (((glyph) >= GLYPH_BODY_OFF) && ((glyph) < (GLYPH_BODY_OFF + NUMMONS))) \
- || (((glyph) >= GLYPH_BODY_PILETOP_OFF) \
-     && ((glyph) < (GLYPH_BODY_PILETOP_OFF + NUMMONS))))
+  ((((glyph) >= GLYPH_OBJ_OFF) && ((glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS))) \
+   || (((glyph) >= GLYPH_OBJ_PILETOP_OFF)                               \
+       && ((glyph) < (GLYPH_OBJ_PILETOP_OFF + NUM_OBJECTS)))            \
+   || (((glyph) >= GLYPH_STATUE_MALE_OFF)                               \
+       && ((glyph) < (GLYPH_STATUE_MALE_OFF + NUMMONS)))                \
+   || (((glyph) >= GLYPH_STATUE_MALE_PILETOP_OFF)                       \
+       && ((glyph) < (GLYPH_STATUE_MALE_PILETOP_OFF + NUMMONS)))        \
+   || (((glyph) >= GLYPH_STATUE_FEM_OFF)                                \
+       && ((glyph) < (GLYPH_STATUE_FEM_OFF + NUMMONS)))                 \
+   || (((glyph) >= GLYPH_STATUE_FEM_PILETOP_OFF)                        \
+       && ((glyph) < (GLYPH_STATUE_FEM_PILETOP_OFF + NUMMONS)))         \
+   || (((glyph) >= GLYPH_BODY_OFF)                                      \
+       && ((glyph) < (GLYPH_BODY_OFF + NUMMONS)))                       \
+   || (((glyph) >= GLYPH_BODY_PILETOP_OFF)                              \
+       && ((glyph) < (GLYPH_BODY_PILETOP_OFF + NUMMONS))))
 #endif
-#define glyph_is_object(glyph)                               \
-    (glyph_is_normal_object(glyph) || glyph_is_statue(glyph) \
+#define glyph_is_object(glyph) \
+    (glyph_is_normal_object(glyph) || glyph_is_statue(glyph)    \
      || glyph_is_body(glyph))
 
 /* briefly used for Qt's "paper doll" inventory which shows map tiles for
@@ -857,8 +859,8 @@ enum glyph_offsets {
    so this isn't used anywhere */
 #define obj_to_true_glyph(obj)                                  \
     (((obj)->otyp == STATUE)                                    \
-     ? ((int) (obj)->corpsenm +                                 \
-        (((obj)->spe & CORPSTAT_GENDER) == CORPSTAT_FEMALE)     \
+     ? ((int) (obj)->corpsenm                                   \
+        + (((obj)->spe & CORPSTAT_GENDER) == CORPSTAT_FEMALE)   \
              ? (obj_is_piletop(obj)                             \
                 ? (GLYPH_STATUE_FEM_PILETOP_OFF)                \
                 : (GLYPH_STATUE_FEM_OFF))                       \
@@ -866,28 +868,25 @@ enum glyph_offsets {
                 ? (GLYPH_STATUE_MALE_PILETOP_OFF)               \
                 : (GLYPH_STATUE_MALE_OFF))                      \
      : (((obj)->otyp == CORPSE)                                 \
-         ? ((int) (obj)->corpsenm +                             \
-             (obj_is_piletop(obj)                               \
+         ? ((int) (obj)->corpsenm                               \
+            + (obj_is_piletop(obj)                              \
                 ? (GLYPH_BODY_PILETOP_OFF)                      \
                 ? (GLYPH_BODY_OFF)))                            \
          : ((int) (obj)->otyp + GLYPH_OBJ_OFF))))
 
 #define glyph_to_obj(glyph) \
-    (glyph_is_body(glyph)                            \
-       ? CORPSE                                      \
-       : glyph_is_statue(glyph)                      \
-         ? STATUE                                    \
-         : glyph_is_normal_object(glyph)             \
-           ? ((glyph) -                              \
-               (glyph_is_normal_piletop_obj(glyph)   \
-                 ? GLYPH_OBJ_PILETOP_OFF             \
-                 : GLYPH_OBJ_OFF))                   \
+    (glyph_is_body(glyph) ? CORPSE                              \
+     : glyph_is_statue(glyph) ? STATUE                          \
+       : glyph_is_normal_object(glyph)                          \
+           ? ((glyph) - (glyph_is_normal_piletop_obj(glyph)     \
+                           ? GLYPH_OBJ_PILETOP_OFF              \
+                           : GLYPH_OBJ_OFF))                    \
            : NO_GLYPH)
 
 #define glyph_to_body_corpsenm(glyph) \
-            (glyph_is_body_piletop(glyph)               \
-                ? ((glyph) - GLYPH_BODY_PILETOP_OFF)    \
-                : ((glyph) - GLYPH_BODY_OFF))
+    (glyph_is_body_piletop(glyph)                       \
+       ? ((glyph) - GLYPH_BODY_PILETOP_OFF)             \
+       : ((glyph) - GLYPH_BODY_OFF))
 
 #define glyph_to_statue_corpsenm(glyph) \
     (glyph_is_fem_statue_piletop(glyph)                 \
@@ -900,11 +899,11 @@ enum glyph_offsets {
                    ? ((glyph) - GLYPH_STATUE_MALE_OFF)  \
                    : NO_GLYPH)
 
-/* These have the unfortunate side effect of needing a global variable    */
+/* These have the unfortunate side effect of needing a global variable  */
 /* to store a result. 'otg_temp' is defined and declared in decl.{ch}.  */
 #define random_obj_to_glyph(rng) \
-    ((g.otg_temp = random_object(rng)) == CORPSE                   \
-         ? (random_monster(rng) + GLYPH_BODY_OFF)                  \
+    ((g.otg_temp = random_object(rng)) == CORPSE        \
+         ? (random_monster(rng) + GLYPH_BODY_OFF)       \
          : (g.otg_temp + GLYPH_OBJ_OFF))
 #define corpse_to_glyph(obj) \
     ((int) ((obj)->corpsenm + (obj_is_piletop(obj)        \
@@ -918,58 +917,57 @@ enum glyph_offsets {
    also done so that special levels such a Sokoban can "hide" items
    under the boulders. */
 #define normal_obj_to_glyph(obj) \
-    ((int) ((obj)->otyp + \
-            ((obj_is_piletop(obj) && ((obj)->otyp != BOULDER))      \
-                                ? GLYPH_OBJ_PILETOP_OFF             \
-                                : GLYPH_OBJ_OFF)))
+    ((int) ((obj)->otyp + ((obj_is_piletop(obj) && ((obj)->otyp != BOULDER)) \
+                           ? GLYPH_OBJ_PILETOP_OFF                           \
+                           : GLYPH_OBJ_OFF)))
 
 /* MRKR: Statues now have glyphs corresponding to the monster they    */
 /*       represent and look like monsters when you are hallucinating. */
 
 #define statue_to_glyph(obj, rng) \
     ((Hallucination)                                                \
-     ? ((random_monster(rng)) +                                     \
-          ((!(rng)(2)) ? GLYPH_MON_MALE_OFF : GLYPH_MON_FEM_OFF))   \
-     : ((int) (obj)->corpsenm +                                     \
-               ((((obj)->spe & CORPSTAT_GENDER) == CORPSTAT_FEMALE) \
-                    ? (obj_is_piletop(obj)                          \
-                          ? GLYPH_STATUE_FEM_PILETOP_OFF            \
-                          : GLYPH_STATUE_FEM_OFF)                   \
-                    : (obj_is_piletop(obj)                          \
-                          ? GLYPH_STATUE_MALE_PILETOP_OFF           \
-                          : GLYPH_STATUE_MALE_OFF))))
+     ? ((random_monster(rng))                                       \
+        + ((!(rng)(2)) ? GLYPH_MON_MALE_OFF : GLYPH_MON_FEM_OFF))   \
+     : ((int) (obj)->corpsenm                                       \
+        + ((((obj)->spe & CORPSTAT_GENDER) == CORPSTAT_FEMALE)      \
+           ? (obj_is_piletop(obj)                                   \
+              ? GLYPH_STATUE_FEM_PILETOP_OFF                        \
+              : GLYPH_STATUE_FEM_OFF)                               \
+           : (obj_is_piletop(obj)                                   \
+              ? GLYPH_STATUE_MALE_PILETOP_OFF                       \
+              : GLYPH_STATUE_MALE_OFF))))
 
 #define obj_to_glyph(obj, rng) \
-           (((obj)->otyp == STATUE)                   \
-               ? statue_to_glyph(obj, rng)            \
-               : ((Hallucination)                     \
-                    ? random_obj_to_glyph(rng)        \
-                    : (((obj)->otyp == CORPSE)        \
-                        ? corpse_to_glyph(obj)        \
-                        : normal_obj_to_glyph(obj))))
+    (((obj)->otyp == STATUE)                             \
+        ? statue_to_glyph(obj, rng)                      \
+        : ((Hallucination)                               \
+             ? random_obj_to_glyph(rng)                  \
+             : (((obj)->otyp == CORPSE)                  \
+                  ? corpse_to_glyph(obj)                 \
+                  : normal_obj_to_glyph(obj))))
 
 #define GLYPH_TRAP_OFF \
     (GLYPH_CMAP_B_OFF + (S_arrow_trap - S_grave))
-#define glyph_is_trap(glyph)      \
-    ((glyph) >= (GLYPH_TRAP_OFF) && \
-     (glyph) < ((GLYPH_TRAP_OFF) + MAXTCHARS))
-#define glyph_is_warning(glyph)   \
-    ((glyph) >= GLYPH_WARNING_OFF \
+#define glyph_is_trap(glyph) \
+    ((glyph) >= (GLYPH_TRAP_OFF)                        \
+     && (glyph) < ((GLYPH_TRAP_OFF) + MAXTCHARS))
+#define glyph_is_warning(glyph) \
+    ((glyph) >= GLYPH_WARNING_OFF                       \
      && (glyph) < (GLYPH_WARNING_OFF + WARNCOUNT))
 #define glyph_is_unexplored(glyph) ((glyph) == GLYPH_UNEXPLORED)
 #define glyph_is_nothing(glyph) ((glyph) == GLYPH_NOTHING)
 
-/*
+#if 0
 #define glyph_is_piletop(glyph) \
     (glyph_is_body_piletop(glyph) || glyph_is_statue_piletop(glyph) \
         || glyph_is_obj_piletop(glyph))
-*/
+#endif
 
 /* mgflags for altering map_glyphinfo() internal behaviour */
-#define MG_FLAG_NORMAL      0x00
+#define MG_FLAG_NORMAL     0x00
 #define MG_FLAG_NOOVERRIDE 0x01 /* disregard accessibility override values */
 
-/* Special mapped glyphflags encoded by reset_glyphmap() and/or map_glyphinfo() */
+/* Special mapped glyphflags encoded by reset_glyphmap() + map_glyphinfo() */
 #define MG_HERO    0x00001  /* represents the hero */
 #define MG_CORPSE  0x00002  /* represents a body */
 #define MG_INVIS   0x00004  /* represents invisible monster */
@@ -979,12 +977,12 @@ enum glyph_offsets {
 #define MG_STATUE  0x00040  /* represents a statue */
 #define MG_OBJPILE 0x00080  /* more than one stack of objects */
 #define MG_BW_LAVA 0x00100  /* 'black & white lava': highlight lava if it
-                               can't be distringuished from water by color */
+                             * can't be distringuished from water by color */
 #define MG_BW_ICE  0x00200  /* similar for ice vs floor */
 #define MG_NOTHING 0x00400  /* char represents GLYPH_NOTHING */
 #define MG_UNEXPL  0x00800  /* char represents GLYPH_UNEXPLORED */
-#define MG_MALE    0x01000  /* represents a male mon variation or statue of one */
-#define MG_FEMALE  0x02000  /* represents a female mon variation or statue of one */
+#define MG_MALE    0x01000  /* represents a male mon or statue of one */
+#define MG_FEMALE  0x02000  /* represents a female mon or statue of one */
 #define MG_BADXY   0x04000  /* bad coordinates were passed */
 
 typedef struct {