]> granicus.if.org Git - nethack/commitdiff
Rolling boulder launch coordinates
authorPasi Kallinen <paxed@alt.org>
Sat, 12 Mar 2022 16:34:40 +0000 (18:34 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 12 Mar 2022 16:34:44 +0000 (18:34 +0200)
Allow defining rolling boulder launching location in special level
lua scripts:

 des.trap({ type="rolling boulder", coord={7, 5}, launchfrom={-2, -2} });

launchfrom is relative to the trap coord.

doc/lua.adoc
src/sp_lev.c
src/trap.c

index 9e1f71ef4c5a377a4f0c8687d10dae019dbc8ef6..9b45c4419ed8eb5ad6c74bd124ff5b3959a39b4a 100644 (file)
@@ -741,13 +741,14 @@ Example:
 
 === trap
 
-Create a trap.
+Create a trap. The `launchfrom` is relative to the rolling boulder trap coord.
 
 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 = "rolling boulder", coord = {7, 5}, launchfrom = {-2, -2} });
  des.trap("hole", 3, 4);
  des.trap("level teleport", {5, 8});
  des.trap("rust")
index 053bfcede20a64c4bd98f9e667ed35376c58a743..1073a4399c299f49be9878b5ce50441ba9e9f5b2 100644 (file)
@@ -4123,6 +4123,16 @@ 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);
+
+        lua_getfield(L, -1, "launchfrom");
+        if (lua_type(L, -1) == LUA_TTABLE) {
+            int lx = -1, ly = -1;
+
+            get_coord(L, -1, &lx, &ly);
+            lua_pop(L, 1);
+            g.launchplace.x = lx;
+            g.launchplace.y = ly;
+        }
     }
 
     if (tmptrap.type == NO_TRAP)
@@ -4134,6 +4144,7 @@ lspo_trap(lua_State *L)
         tmptrap.coord = SP_COORD_PACK(x, y);
 
     create_trap(&tmptrap, g.coder->croom);
+    g.launchplace.x = g.launchplace.y = 0;
 
     return 0;
 }
index e4a0ae63eaef62303710612521a95e70469a2cf3..b49b6b83ce42283a4c9e343c02b4ed82465bd9f4 100644 (file)
@@ -3030,6 +3030,14 @@ find_random_launch_coord(struct trap *ttmp, coord *cc)
     if (!ttmp || !cc)
         return FALSE;
 
+    bcc.x = ttmp->tx + g.launchplace.x;
+    bcc.y = ttmp->ty + g.launchplace.y;
+    if (isok(bcc.x, bcc.y) && linedup(ttmp->tx, ttmp->ty, bcc.x, bcc.y, 1)) {
+        cc->x = bcc.x;
+        cc->y = bcc.y;
+        return TRUE;
+    }
+
     if (ttmp->ttyp == ROLLING_BOULDER_TRAP)
         mindist = 2;
     distance = rn1(5, 4); /* 4..8 away */