]> granicus.if.org Git - nethack/commitdiff
special level's lit state when changing terrain
authorPatR <rankin@nethack.org>
Sun, 6 Sep 2020 23:17:33 +0000 (16:17 -0700)
committerPatR <rankin@nethack.org>
Sun, 6 Sep 2020 23:17:33 +0000 (16:17 -0700)
Part of pull request #308:  when using des.terrain to set terrain,
default for lit state becomes 'unchanged' rather than 'unlit'.
des.replace_terrain already operates that way.  Replace lit state
magic numbers -1 and -2 with SET_LIT_RANDOM and SET_LIT_NOCHANGE.

Also change SET_TYPLIT() to not operate on map column 0 and move
it from rm.h to sp_lev.h.  It never belonged there, is only used
in sp_lev.c, and now because of the SET_LIT_ macros it couldn't be
used anywhere else unless sp_lev.h gets included too.

doc/fixes37.0
include/rm.h
include/sp_lev.h
src/sp_lev.c

index dc210bd01cf0b044f933835450e71d5cef5a972f..3364e09c41e9976d9fdd0f246d2aca61305f54fb 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.297 $ $NHDT-Date: 1599255099 2020/09/04 21:31:39 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.298 $ $NHDT-Date: 1599434249 2020/09/06 23:17:29 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -326,6 +326,8 @@ the fix to make worm visibility checks work as intended forced the coordinates
        reverses the segments and can throw some away if there isn't room,
        but throwing away the extra segment removed the worm from the map
 using 'O' to try to change 'symset' was a no-op; 'roguesymset' worked
+change default for lit attribute in special level des.terrain directives to
+       'unchanged' instead of 'unlit'
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 3f06e9d837f887747fc61644c54640dab7e920f4..761e8b30cbb1c9a712e31f0f6d9a89c14c76ef2c 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 rm.h    $NHDT-Date: 1596498558 2020/08/03 23:49:18 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.83 $ */
+/* NetHack 3.7 rm.h    $NHDT-Date: 1599434249 2020/09/06 23:17:29 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.84 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Pasi Kallinen, 2017. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -436,22 +436,6 @@ struct rm {
     Bitfield(candig, 1); /* Exception to Can_dig_down; was a trapdoor */
 };
 
-#define SET_TYPLIT(x, y, ttyp, llit)                              \
-    {                                                             \
-        if ((x) >= 0 && (y) >= 0 && (x) < COLNO && (y) < ROWNO) { \
-            if ((ttyp) < MAX_TYPE)                                \
-                levl[(x)][(y)].typ = (ttyp);                      \
-            if ((ttyp) == LAVAPOOL)                               \
-                levl[(x)][(y)].lit = 1;                           \
-            else if ((schar)(llit) != -2) {                       \
-                if ((schar)(llit) == -1)                          \
-                    levl[(x)][(y)].lit = rn2(2);                  \
-                else                                              \
-                    levl[(x)][(y)].lit = (llit);                  \
-            }                                                     \
-        }                                                         \
-    }
-
 /*
  * Add wall angle viewing by defining "modes" for each wall type.  Each
  * mode describes which parts of a wall are finished (seen as as wall)
@@ -631,10 +615,10 @@ typedef struct {
  * Macros for encapsulation of level.monsters references.
  */
 #if 0
-#define MON_AT(x, y)                            \
+#define MON_AT(x, y) \
     (g.level.monsters[x][y] != (struct monst *) 0 \
      && !(g.level.monsters[x][y])->mburied)
-#define MON_BURIED_AT(x, y)                     \
+#define MON_BURIED_AT(x, y) \
     (g.level.monsters[x][y] != (struct monst *) 0 \
      && (g.level.monsters[x][y])->mburied)
 #else   /* without 'mburied' */
@@ -642,15 +626,15 @@ typedef struct {
 #endif
 #ifdef EXTRA_SANITY_CHECKS
 #define place_worm_seg(m, x, y) \
-    do {                                                        \
+    do {                                                            \
         if (g.level.monsters[x][y] && g.level.monsters[x][y] != m)  \
-            impossible("place_worm_seg over mon");              \
-        g.level.monsters[x][y] = m;                               \
+            impossible("place_worm_seg over mon");                  \
+        g.level.monsters[x][y] = m;                                 \
     } while(0)
 #define remove_monster(x, y) \
-    do {                                                \
+    do {                                                  \
         if (!g.level.monsters[x][y])                      \
-            impossible("no monster to remove");         \
+            impossible("no monster to remove");           \
         g.level.monsters[x][y] = (struct monst *) 0;      \
     } while(0)
 #else
index d68250b02ff24196c5a1d28cdbad5c3a462c171d..8213599070cf960797a49b75970095a3d42c4699 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 sp_lev.h        $NHDT-Date: 1596498560 2020/08/03 23:49:20 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.38 $ */
+/* NetHack 3.7 sp_lev.h        $NHDT-Date: 1599434249 2020/09/06 23:17:29 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.39 $ */
 /* Copyright (c) 1989 by Jean-Christophe Collet                          */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -62,6 +62,11 @@ enum lvlinit_types {
 #define SEL_GRADIENT_RADIAL 0
 #define SEL_GRADIENT_SQUARE 1
 
+/* light states for terrain replacements, specifically for SET_TYPLIT
+ * (not used for init_level) */
+#define SET_LIT_RANDOM -1
+#define SET_LIT_NOCHANGE -2
+
 #define SP_COORD_IS_RANDOM 0x01000000L
 /* Humidity flags for get_location() and friends, used with
  * SP_COORD_PACK_RANDOM() */
@@ -188,4 +193,20 @@ struct mapfragment {
     char *data;
 };
 
+#define SET_TYPLIT(x, y, ttyp, llit) \
+    {                                                             \
+        if ((x) >= 1 && (y) >= 0 && (x) < COLNO && (y) < ROWNO) { \
+            if ((ttyp) < MAX_TYPE)                                \
+                levl[(x)][(y)].typ = (ttyp);                      \
+            if ((ttyp) == LAVAPOOL)                               \
+                levl[(x)][(y)].lit = 1;                           \
+            else if ((schar)(llit) != SET_LIT_NOCHANGE) {         \
+                if ((schar)(llit) == SET_LIT_RANDOM)              \
+                    levl[(x)][(y)].lit = rn2(2);                  \
+                else                                              \
+                    levl[(x)][(y)].lit = (llit);                  \
+            }                                                     \
+        }                                                         \
+    }
+
 #endif /* SP_LEV_H */
index d49d685798eb7cb2aa73d48bd5d40a16b369194e..d08888028dee46e3beb30d2252e7ee35cecdaebf 100755 (executable)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 sp_lev.c        $NHDT-Date: 1596498212 2020/08/03 23:43:32 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.201 $ */
+/* NetHack 3.7 sp_lev.c        $NHDT-Date: 1599434249 2020/09/06 23:17:29 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.202 $ */
 /*      Copyright (c) 1989 by Jean-Christophe Collet */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -10,7 +10,7 @@
  */
 
 #define IN_SP_LEV_C
+
 #include "hack.h"
 #include "sp_lev.h"
 
@@ -5089,12 +5089,15 @@ lua_State *L;
     return 0;
 }
 
-/* terrain({ x=NN, y=NN, typ=MAPCHAR, lit=BOOL }); */
-/* terrain({ coord={X, Y}, typ=MAPCHAR, lit=BOOL }); */
-/* terrain({ selection=SELECTION, typ=MAPCHAR, lit=BOOL }); */
-/* terrain( SELECTION, MAPCHAR [, BOOL ] ); */
-/* terrain({x,y}, MAPCHAR); */
-/* terrain(x,y, MAPCHAR); */
+/*
+ * [lit_state: 1 On, 0 Off, -1 random, -2 leave as-is]
+ * terrain({ x=NN, y=NN, typ=MAPCHAR, lit=lit_state });
+ * terrain({ coord={X, Y}, typ=MAPCHAR, lit=lit_state });
+ * terrain({ selection=SELECTION, typ=MAPCHAR, lit=lit_state });
+ * terrain( SELECTION, MAPCHAR [, lit_state ] );
+ * terrain({x,y}, MAPCHAR);
+ * terrain(x,y, MAPCHAR);
+ */
 int
 lspo_terrain(L)
 lua_State *L;
@@ -5105,7 +5108,7 @@ lua_State *L;
     int argc = lua_gettop(L);
 
     create_des_coder();
-    tmpterrain.tlit = 0;
+    tmpterrain.tlit = SET_LIT_NOCHANGE;
     tmpterrain.ter = INVALID_TYPE;
 
     if (argc == 1) {
@@ -5120,7 +5123,7 @@ lua_State *L;
             lua_pop(L, 1);
         }
         tmpterrain.ter = get_table_mapchr(L, "typ");
-        tmpterrain.tlit = get_table_int_opt(L, "lit", 0);
+        tmpterrain.tlit = get_table_int_opt(L, "lit", SET_LIT_NOCHANGE);
     } else if (argc == 2 && lua_type(L, 1) == LUA_TTABLE
                && lua_type(L, 2) == LUA_TSTRING) {
         int tx, ty;
@@ -5154,10 +5157,16 @@ lua_State *L;
     return 0;
 }
 
-/* replace_terrain({ x1=NN,y1=NN, x2=NN,y2=NN, fromterrain=MAPCHAR, toterrain=MAPCHAR, lit=N, chance=NN }); */
-/* replace_terrain({ region={x1,y1, x2,y2}, fromterrain=MAPCHAR, toterrain=MAPCHAR, lit=N, chance=NN }); */
-/* replace_terrain({ selection=selection.area(2,5, 40,10), fromterrain=MAPCHAR, toterrain=MAPCHAR }); */
-/* replace_terrain({ selection=SEL, mapfragment=[[...]], toterrain=MAPCHAR }); */
+/*
+ * replace_terrain({ x1=NN,y1=NN, x2=NN,y2=NN, fromterrain=MAPCHAR,
+ *                   toterrain=MAPCHAR, lit=N, chance=NN });
+ * replace_terrain({ region={x1,y1, x2,y2}, fromterrain=MAPCHAR,
+ *                   toterrain=MAPCHAR, lit=N, chance=NN });
+ * replace_terrain({ selection=selection.area(2,5, 40,10),
+ *                   fromterrain=MAPCHAR, toterrain=MAPCHAR });
+ * replace_terrain({ selection=SEL, mapfragment=[[...]],
+ *                   toterrain=MAPCHAR });
+ */
 int
 lspo_replace_terrain(L)
 lua_State *L;
@@ -5195,7 +5204,7 @@ lua_State *L;
     }
 
     chance = get_table_int_opt(L, "chance", 100);
-    tolit = get_table_int_opt(L, "lit", -2);
+    tolit = get_table_int_opt(L, "lit", SET_LIT_NOCHANGE);
     x1 = get_table_int_opt(L, "x1", -1);
     y1 = get_table_int_opt(L, "y1", -1);
     x2 = get_table_int_opt(L, "x2", -1);