]> granicus.if.org Git - nethack/commitdiff
Unify lua setting wallprop
authorPasi Kallinen <paxed@alt.org>
Sun, 9 Feb 2020 12:30:11 +0000 (14:30 +0200)
committerPasi Kallinen <paxed@alt.org>
Sun, 9 Feb 2020 12:30:11 +0000 (14:30 +0200)
src/sp_lev.c

index efe71d17bc1e338965fbcc6735b4f9d3f5f8dd95..7317130d61d94b66dc37720295636a5a20511d97 100644 (file)
@@ -92,6 +92,7 @@ static void FDECL(sel_set_feature, (int, int, genericptr_t));
 static int FDECL(get_coord, (lua_State *, int, int *, int *));
 static int FDECL(get_table_region, (lua_State *, const char *,
                                     int *, int *, int *, int *, BOOLEAN_P));
+static void FDECL(set_wallprop_in_selection, (lua_State *, int));
 
 /* lua_CFunction prototypes */
 int FDECL(lspo_altar, (lua_State *));
@@ -5169,13 +5170,11 @@ lua_State *L;
     return 0;
 }
 
-/* non_diggable(selection); */
-/* non_diggable(); */
-int
-lspo_non_diggable(L)
+static void
+set_wallprop_in_selection(L, prop)
 lua_State *L;
+int prop;
 {
-    int prop = W_NONDIGGABLE;
     int argc = lua_gettop(L);
     boolean freesel = FALSE;
     struct selectionvar *sel = (struct selectionvar *) 0;
@@ -5197,7 +5196,15 @@ lua_State *L;
             free(sel);
         }
     }
+}
 
+/* non_diggable(selection); */
+/* non_diggable(); */
+int
+lspo_non_diggable(L)
+lua_State *L;
+{
+    set_wallprop_in_selection(L, W_NONDIGGABLE);
     return 0;
 }
 
@@ -5207,29 +5214,7 @@ int
 lspo_non_passwall(L)
 lua_State *L;
 {
-    int prop = W_NONPASSWALL;
-    int argc = lua_gettop(L);
-    boolean freesel = FALSE;
-    struct selectionvar *sel = (struct selectionvar *) 0;
-
-    create_des_coder();
-
-    if (argc == 1)
-        sel = l_selection_check(L, -1);
-    else if (argc == 0) {
-        freesel = TRUE;
-        sel = selection_new();
-        selection_not(sel);
-    }
-
-    if (sel) {
-        selection_iterate(sel, sel_set_wall_property, (genericptr_t) &prop);
-        if (freesel) {
-            selection_free(sel);
-            free(sel);
-        }
-    }
-
+    set_wallprop_in_selection(L, W_NONPASSWALL);
     return 0;
 }