MCPcopy Create free account
hub / github.com/NetHack/NetHack / create_maze

Function create_maze

src/mkmaze.c:949–1039  ·  view source on GitHub ↗

Create a maze with specified corridor width and wall thickness * TODO: rewrite walkfrom so it works on temp space, not levl */

Source from the content-addressed store, hash-verified

947 * TODO: rewrite walkfrom so it works on temp space, not levl
948 */
949void
950create_maze(int corrwid, int wallthick, boolean rmdeadends)
951{
952 coordxy x,y;
953 coord mm;
954 int tmp_xmax = gx.x_maze_max;
955 int tmp_ymax = gy.y_maze_max;
956 int rdx = 0;
957 int rdy = 0;
958 int scale;
959
960 if (corrwid == -1)
961 corrwid = rnd(4);
962
963 if (wallthick == -1)
964 wallthick = rnd(4) - corrwid;
965
966 if (wallthick < 1)
967 wallthick = 1;
968 else if (wallthick > 5)
969 wallthick = 5;
970
971 if (corrwid < 1)
972 corrwid = 1;
973 else if (corrwid > 5)
974 corrwid = 5;
975
976 scale = corrwid + wallthick;
977 rdx = (gx.x_maze_max / scale);
978 rdy = (gy.y_maze_max / scale);
979
980 if (svl.level.flags.corrmaze)
981 for (x = 2; x < (rdx * 2); x++)
982 for (y = 2; y < (rdy * 2); y++)
983 levl[x][y].typ = STONE;
984 else
985 for (x = 2; x <= (rdx * 2); x++)
986 for (y = 2; y <= (rdy * 2); y++)
987 levl[x][y].typ = ((x % 2) && (y % 2)) ? STONE : HWALL;
988
989 /* set upper bounds for maze0xy and walkfrom */
990 gx.x_maze_max = (rdx * 2);
991 gy.y_maze_max = (rdy * 2);
992
993 /* create maze */
994 maze0xy(&mm);
995 walkfrom((int) mm.x, (int) mm.y, 0);
996
997 if (rmdeadends)
998 maze_remove_deadends((svl.level.flags.corrmaze) ? CORR : ROOM);
999
1000 /* restore bounds */
1001 gx.x_maze_max = tmp_xmax;
1002 gy.y_maze_max = tmp_ymax;
1003
1004 /* scale maze up if needed */
1005 if (scale > 2) {
1006 char tmpmap[COLNO][ROWNO];

Callers 2

makemazFunction · 0.85
splev_initlevFunction · 0.85

Calls 4

rndFunction · 0.85
maze0xyFunction · 0.85
walkfromFunction · 0.85
maze_remove_deadendsFunction · 0.85

Tested by

no test coverage detected