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

Function maze_remove_deadends

src/mkmaze.c:903–944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

901}
902
903staticfn void
904maze_remove_deadends(xint16 typ)
905{
906 char dirok[4];
907 coordxy x, y, dir, idx, idx2, dx, dy, dx2, dy2;
908
909 dirok[0] = 0; /* lint suppression */
910 for (x = 2; x < gx.x_maze_max; x++)
911 for (y = 2; y < gy.y_maze_max; y++)
912 if (ACCESSIBLE(levl[x][y].typ) && (x % 2) && (y % 2)) {
913 idx = idx2 = 0;
914 for (dir = 0; dir < 4; dir++) {
915 /* note: mz_move() is a macro which modifies
916 one of its first two parameters */
917 dx = dx2 = x;
918 dy = dy2 = y;
919 mz_move(dx, dy, dir);
920 if (!maze_inbounds(dx, dy)) {
921 idx2++;
922 continue;
923 }
924 mz_move(dx2, dy2, dir);
925 mz_move(dx2, dy2, dir);
926 if (!maze_inbounds(dx2, dy2)) {
927 idx2++;
928 continue;
929 }
930 if (!ACCESSIBLE(levl[dx][dy].typ)
931 && ACCESSIBLE(levl[dx2][dy2].typ)) {
932 dirok[idx++] = dir;
933 idx2++;
934 }
935 }
936 if (idx2 >= 3 && idx > 0) {
937 dx = x;
938 dy = y;
939 dir = dirok[rn2(idx)];
940 mz_move(dx, dy, dir);
941 levl[dx][dy].typ = typ;
942 }
943 }
944}
945
946/* Create a maze with specified corridor width and wall thickness
947 * TODO: rewrite walkfrom so it works on temp space, not levl

Callers 1

create_mazeFunction · 0.85

Calls 2

maze_inboundsFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected