From: Pasi Kallinen Date: Tue, 7 Apr 2020 16:20:19 +0000 (+0300) Subject: Expose scaled mazes to special level lua X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=665eacf40c2d5e2149703410d238a02ea28c63fd;p=nethack Expose scaled mazes to special level lua Adds a new level init type which directly creates a maze, optionally setting corridor width and wall thickness, and removing dead ends. des.level_init({ style = "maze", corrwid = 3, wallthick = 1, deadends = false }); --- diff --git a/doc/lua.adoc b/doc/lua.adoc index 3f614a583..e4d590d7c 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -329,6 +329,7 @@ Example: des.level_init({ style = "solidfill", fg = " " }); des.level_init({ style = "mines", fg = ".", bg = "}", smoothed=1, joined=1, lit=0 }) + des.level_init({ style = "maze", corrwid = 3, wallthick = 1, deadends = false }); === levregion diff --git a/include/extern.h b/include/extern.h index 33198552b..6a451363f 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1340,6 +1340,7 @@ E boolean FDECL(litstate_rnd, (int)); /* ### mkmaze.c ### */ +E void FDECL(create_maze, (int, int, BOOLEAN_P)); E void FDECL(wallification, (int, int, int, int)); E void FDECL(fix_wall_spines, (int, int, int, int)); E void FDECL(walkfrom, (int, int, SCHAR_P)); diff --git a/include/sp_lev.h b/include/sp_lev.h index ccfd38513..4104d51c9 100644 --- a/include/sp_lev.h +++ b/include/sp_lev.h @@ -38,6 +38,7 @@ enum lvlinit_types { LVLINIT_NONE = 0, LVLINIT_SOLIDFILL, LVLINIT_MAZEGRID, + LVLINIT_MAZE, LVLINIT_MINES, LVLINIT_ROGUE, LVLINIT_SWAMP @@ -110,6 +111,8 @@ typedef struct { boolean smoothed, joined; xchar lit, walled; boolean icedpools; + int corrwid, wallthick; + boolean rm_deadends; } lev_init; typedef struct { diff --git a/src/mkmaze.c b/src/mkmaze.c index e431a6cca..719f26a67 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -26,7 +26,6 @@ static void FDECL(shiny_orc_stuff, (struct monst *)); static void NDECL(stolen_booty); static boolean FDECL(maze_inbounds, (int, int)); static void FDECL(maze_remove_deadends, (XCHAR_P)); -static void FDECL(create_maze, (int, int)); /* adjust a coordinate one step in the specified direction */ #define mz_move(X, Y, dir) \ @@ -842,10 +841,10 @@ xchar typ; /* Create a maze with specified corridor width and wall thickness * TODO: rewrite walkfrom so it works on temp space, not levl */ -static void -create_maze(corrwid, wallthick) -int corrwid; -int wallthick; +void +create_maze(corrwid, wallthick, rmdeadends) +int corrwid, wallthick; +boolean rmdeadends; { int x,y; coord mm; @@ -855,6 +854,12 @@ int wallthick; int rdy = 0; int scale; + if (corrwid == -1) + corrwid = rnd(4); + + if (wallthick == -1) + wallthick = rnd(4) - corrwid; + if (wallthick < 1) wallthick = 1; else if (wallthick > 5) @@ -886,7 +891,7 @@ int wallthick; maze0xy(&mm); walkfrom((int) mm.x, (int) mm.y, 0); - if (!rn2(5)) + if (rmdeadends) maze_remove_deadends((g.level.flags.corrmaze) ? CORR : ROOM); /* restore bounds */ @@ -1004,10 +1009,9 @@ const char *s; g.level.flags.corrmaze = !rn2(3); if (!Invocation_lev(&u.uz) && rn2(2)) { - int corrscale = rnd(4); - create_maze(corrscale,rnd(4)-corrscale); + create_maze(-1, -1, !rn2(5)); } else { - create_maze(1,1); + create_maze(1, 1, FALSE); } if (!g.level.flags.corrmaze) diff --git a/src/sp_lev.c b/src/sp_lev.c index 6a870778c..0830bbeff 100755 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -2901,6 +2901,9 @@ lev_init *linit; case LVLINIT_MAZEGRID: lvlfill_maze_grid(2, 0, g.x_maze_max, g.y_maze_max, linit->bg); break; + case LVLINIT_MAZE: + create_maze(linit->corrwid, linit->wallthick, linit->rm_deadends); + break; case LVLINIT_ROGUE: makeroguerooms(); break; @@ -3574,10 +3577,10 @@ lspo_level_init(L) lua_State *L; { static const char *const initstyles[] = { - "solidfill", "mazegrid", "rogue", "mines", "swamp", NULL + "solidfill", "mazegrid", "maze", "rogue", "mines", "swamp", NULL }; static const int initstyles2i[] = { - LVLINIT_SOLIDFILL, LVLINIT_MAZEGRID, LVLINIT_ROGUE, + LVLINIT_SOLIDFILL, LVLINIT_MAZEGRID, LVLINIT_MAZE, LVLINIT_ROGUE, LVLINIT_MINES, LVLINIT_SWAMP, 0 }; lev_init init_lev; @@ -3597,6 +3600,9 @@ lua_State *L; init_lev.lit = get_table_int_or_random(L, "lit", -1); /* TODO: allow lit=BOOL */ init_lev.walled = get_table_boolean_opt(L, "walled", 0); init_lev.filling = get_table_mapchr_opt(L, "filling", init_lev.fg); + init_lev.corrwid = get_table_int_opt(L, "corrwid", -1); + init_lev.wallthick = get_table_int_opt(L, "wallthick", -1); + init_lev.rm_deadends = !get_table_boolean_opt(L, "deadends", 1); g.coder->lvl_is_joined = init_lev.joined;