]> granicus.if.org Git - nethack/commitdiff
Lua: ice theme room and melting ice
authorPasi Kallinen <paxed@alt.org>
Tue, 15 Mar 2022 20:05:32 +0000 (22:05 +0200)
committerPasi Kallinen <paxed@alt.org>
Tue, 15 Mar 2022 20:05:36 +0000 (22:05 +0200)
Allow the ice theme room to occasionally have melting ice.
Add nh.abscoord() to convert room-relative to map-absolute coords.

dat/themerms.lua
doc/lua.adoc
include/extern.h
src/nhlua.c
src/sp_lev.c

index 4bcda7f0e4c7f9c0734784a2cb2a8559dda268a7..f37a186b926eea28e46066c9e85074ffd0b3baeb 100644 (file)
@@ -73,7 +73,16 @@ themerooms = {
    function()
       des.room({ type = "themed", filled = 1,
                  contents = function()
-                    des.terrain(selection.floodfill(1,1), "I");
+                    local ice = selection.floodfill(1,1);
+                    des.terrain(ice, "I");
+                    if (percent(25)) then
+                       local mintime = 1000 - (nh.level_difficulty() * 100);
+                       local ice_melter = function(x,y)
+                          local ax,ay = nh.abscoord(x,y);
+                          nh.start_timer_at(ax,ay, "melt-ice", mintime + nh.rn2(1000));
+                       end;
+                       ice:iterate(ice_melter);
+                    end
                  end
       });
    end,
index 3e05966afc31e377a5e1ec97e44030003b007ef6..e0360347c37ca621e2ccbfe12a34be2dd498c317 100644 (file)
@@ -6,6 +6,17 @@
 
 Functions exposed from the NetHack core. They are all in the `nh` table.
 
+=== abscoord
+
+Convert a relative coordinate to absolute.
+des-routines tend to use relative coordinates, nh and obj use absolute.
+(This mess is still very much in need of improvement.)
+
+Example:
+
+ local ax, ay = nh.abscoord(x, y);
+
+
 === an
 
 Returns a string with "a " or "an " prepended to it.
index f05f1eff1ed3ebc0c272cb8c12ec483376da16e5..7051faa4e0bbb3eed4b6258a2a7b3735822bb266 100644 (file)
@@ -2527,6 +2527,7 @@ extern void selection_do_gradient(struct selectionvar *, long, long, long,
                                   long, long, long, long, long);
 extern int lspo_reset_level(lua_State *);
 extern int lspo_finalize_level(lua_State *);
+extern int nhl_abs_coord(lua_State *);
 extern void update_croom(void);
 extern const char *get_trapname_bytype(int);
 extern void l_register_des(lua_State *);
index 36bf59343476be5a207b277a0afdc3d0cc933fee..3cfce4b92f6a72e4e5725f6df651a8e554576f03 100644 (file)
@@ -1152,6 +1152,8 @@ static const struct luaL_Reg nhl_functions[] = {
     {"stop_timer_at", nhl_timer_stop_at},
     {"start_timer_at", nhl_timer_start_at},
 
+    {"abscoord", nhl_abs_coord},
+
     {"pline", nhl_pline},
     {"verbalize", nhl_verbalize},
     {"menu", nhl_menu},
index 97f2ec936ed6c7c1dedcb2782e095a4368f75d0b..44ea80e4058e04615515610f2015f74b0784d5e9 100644 (file)
@@ -4922,6 +4922,24 @@ l_table_getset_feature_flag(
     }
 }
 
+/* convert relative coordinate to absolute */
+int
+nhl_abs_coord(lua_State *L)
+{
+    int argc = lua_gettop(L);
+    xchar x = -1, y = -1;
+
+    if (argc == 2) {
+        x = (xchar) lua_tointeger(L, 1);
+        y = (xchar) lua_tointeger(L, 2);
+        get_location_coord(&x, &y, ANY_LOC, NULL, SP_COORD_PACK(x,y));
+    } else
+        nhl_error(L, "nhl_abs_coord: Wrong args");
+    lua_pushinteger(L, x);
+    lua_pushinteger(L, y);
+    return 2;
+}
+
 /* feature("fountain", x, y); */
 /* feature("fountain", {x,y}); */
 /* feature({ type="fountain", x=NN, y=NN }); */