]> granicus.if.org Git - nethack/commitdiff
Lua: Traps without victims
authorPasi Kallinen <paxed@alt.org>
Sat, 25 Feb 2023 15:56:44 +0000 (17:56 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 25 Feb 2023 16:05:09 +0000 (18:05 +0200)
Traps may get corpses generated on them on early dungeon levels,
to warn off fragile starting heroes. Allow creating traps in lua
without the corpse.

doc/lua.adoc
include/hack.h
include/sp_lev.h
src/mklev.c
src/sp_lev.c

index c49bba557f8d002fa857d86ecacec0fe1d183088..a2d575eeafc965081ceca878e216192bd5eb4645 100644 (file)
@@ -929,6 +929,7 @@ Example:
  des.trap({ type = "hole", x = 1, y = 1 });
  des.trap({ type = "hole", coord = {2, 2} });
  des.trap({ type = "web", coord = {2, 2}, spider_on_web = false, seen = true });
+ des.trap({ type = "falling rock", victim = false });
  des.trap({ type = "rolling boulder", coord = {7, 5}, launchfrom = {-2, -2} });
  des.trap("hole", 3, 4);
  des.trap("level teleport", {5, 8});
index a1fc3093b9789d85536b681cfd5992245a9b08e9..4fecb3c1fe5912a08b88dfddaf56d7685506afc8 100644 (file)
@@ -584,6 +584,7 @@ enum bodypart_types {
 #define MKTRAP_MAZEFLAG      0x1 /* trap placed on coords as if in maze */
 #define MKTRAP_NOSPIDERONWEB 0x2 /* web will not generate a spider */
 #define MKTRAP_SEEN          0x4 /* trap is seen */
+#define MKTRAP_NOVICTIM      0x8 /* no victim corpse or items on it */
 
 #define MON_POLE_DIST 5 /* How far monsters can use pole-weapons */
 #define PET_MISSILE_RANGE2 36 /* Square of distance within which pets shoot */
index aa5f9a810af075cdc53cb6ac559fbddf09f1ed1d..d4d4d8c4b82810192303bdf48a3b441e1e37662c 100644 (file)
@@ -127,6 +127,7 @@ typedef struct {
     xint16 type;
     boolean spider_on_web;
     boolean seen;
+    boolean novictim;
 } spltrap;
 
 typedef struct {
index 3de0635e45520f9565b34ab623e923ccc4c4c435..d6f4a588fe74cf563b5248ceb98193584bb7a248 100644 (file)
@@ -1540,7 +1540,8 @@ mktrap(
        lethal, and tend not to generate on shallower levels anyway.
        Finally, pits are excluded because it's weird to see an item
        in a pit and yet not be able to identify that the pit is there. */
-    if (kind != NO_TRAP && lvl <= (unsigned) rnd(4)
+    if (kind != NO_TRAP && !(mktrapflags & MKTRAP_NOVICTIM)
+        && lvl <= (unsigned) rnd(4)
         && kind != SQKY_BOARD && kind != RUST_TRAP
         /* rolling boulder trap might not have a boulder if there was no
            viable path (such as when placed in the corner of a room), in
index 27655c47330c0b93185ec4974b10117fdda788b5..87d1c25b22625017b814884a2f92a65ad1b7e131 100644 (file)
@@ -1797,6 +1797,8 @@ create_trap(spltrap* t, struct mkroom* croom)
         mktrap_flags |= MKTRAP_NOSPIDERONWEB;
     if (t->seen)
         mktrap_flags |= MKTRAP_SEEN;
+    if (t->novictim)
+        mktrap_flags |= MKTRAP_NOVICTIM;
 
     tm.x = x;
     tm.y = y;
@@ -4275,6 +4277,7 @@ lspo_trap(lua_State *L)
 
     tmptrap.spider_on_web = TRUE;
     tmptrap.seen = FALSE;
+    tmptrap.novictim = FALSE;
 
     if (argc == 1 && lua_type(L, 1) == LUA_TSTRING) {
         const char *trapstr = luaL_checkstring(L, 1);
@@ -4300,6 +4303,7 @@ lspo_trap(lua_State *L)
         tmptrap.type = get_table_traptype_opt(L, "type", -1);
         tmptrap.spider_on_web = get_table_boolean_opt(L, "spider_on_web", 1);
         tmptrap.seen = get_table_boolean_opt(L, "seen", FALSE);
+        tmptrap.novictim = !get_table_boolean_opt(L, "victim", TRUE);
 
         lua_getfield(L, -1, "launchfrom");
         if (lua_type(L, -1) == LUA_TTABLE) {