]> granicus.if.org Git - nethack/commitdiff
Lua: Allow setting debug_flags
authorPasi Kallinen <paxed@alt.org>
Thu, 29 Jul 2021 04:36:08 +0000 (07:36 +0300)
committerPasi Kallinen <paxed@alt.org>
Thu, 29 Jul 2021 04:36:08 +0000 (07:36 +0300)
include/flag.h
src/eat.c
src/nhlua.c
test/testmove.lua

index c8a7567143b2938db7116c8894572ca2a8d9f059..fa8ed6f5823b2efa18a828d5076fd5d457e45a65 100644 (file)
@@ -205,6 +205,7 @@ struct instance_flags {
     boolean vision_inited; /* true if vision is ready */
     boolean sanity_check;  /* run sanity checks */
     boolean debug_mongen;  /* debug: prevent monster generation */
+    boolean debug_hunger;  /* debug: prevent hunger */
     boolean mon_polycontrol; /* debug: control monster polymorphs */
     boolean in_dumplog;    /* doing the dumplog right now? */
     boolean in_parse;      /* is a command being parsed? */
index 43b76c3e3d123f569163ca8f2281f533a0907cde..3d7133b720177b663d974c48211a1a47456f44c1 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -2842,7 +2842,7 @@ gethungry(void)
 {
     int accessorytime;
 
-    if (u.uinvulnerable)
+    if (u.uinvulnerable || iflags.debug_hunger)
         return; /* you don't feel hungrier */
 
     /* being polymorphed into a creature which doesn't eat prevents
index e2704c3a53a57dbfb034b91c911278e3e27bec38..95e5d74645744e865f441c8e3172c7e1b71f46b1 100644 (file)
@@ -21,7 +21,7 @@ static int nhl_dnum_name(lua_State *);
 static int nhl_stairways(lua_State *);
 static int nhl_pushkey(lua_State *);
 static int nhl_doturn(lua_State *);
-static int nhl_monster_generation(lua_State *);
+static int nhl_debug_flags(lua_State *);
 static int nhl_test(lua_State *);
 static int nhl_getmap(lua_State *);
 static void nhl_add_table_entry_bool(lua_State *, const char *, boolean);
@@ -973,17 +973,22 @@ nhl_doturn(lua_State *L)
     return 0;
 }
 
-/* disable or enable monster generation. debugging use only. */
-/* disabling also kills all monsters on current level. */
-/* local prevvalue = nh.monster_generation(false); */
+/* set debugging flags. debugging use only, of course. */
+/* nh.debug_flags({ mongen = false, hunger = false }); */
 static int
-nhl_monster_generation(lua_State *L)
+nhl_debug_flags(lua_State *L)
 {
     int argc = lua_gettop(L);
-    boolean val = !iflags.debug_mongen; /* value in lua is negated */
+    int val;
 
-    if (argc == 1) {
-        iflags.debug_mongen = !lua_toboolean(L, 1);
+    int i;
+
+    lcheck_param_table(L);
+
+    /* disable monster generation */
+    val = get_table_boolean_opt(L, "mongen", -1);
+    if (val != -1) {
+        iflags.debug_mongen = !(boolean)val; /* value in lua is negated */
         if (iflags.debug_mongen) {
             register struct monst *mtmp, *mtmp2;
 
@@ -996,8 +1001,13 @@ nhl_monster_generation(lua_State *L)
         }
     }
 
-    lua_pushboolean(L, val);
-    return 1;
+    /* prevent hunger */
+    val = get_table_boolean_opt(L, "hunger", -1);
+    if (val != -1) {
+        iflags.debug_hunger = !(boolean)val; /* value in lua is negated */
+    }
+
+    return 0;
 }
 
 
@@ -1034,7 +1044,7 @@ static const struct luaL_Reg nhl_functions[] = {
     {"stairways", nhl_stairways},
     {"pushkey", nhl_pushkey},
     {"doturn", nhl_doturn},
-    {"monster_generation", nhl_monster_generation},
+    {"debug_flags", nhl_debug_flags},
     {NULL, NULL}
 };
 
index 23956b44666a27f53e2946549807a520c94641c2..3e591e36b075082a105cbe16aa5e656b38a204e9 100644 (file)
@@ -13,7 +13,7 @@ local POS = { x = 10, y = 05 };
 local number_pad = 0;
 
 function initlev()
-   nh.monster_generation(false);
+   nh.debug_flags({mongen = false, hunger = false });
    des.level_flags("noflip");
    des.reset_level();
    des.level_init({ style = "solidfill", fg = ".", lit = true });