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

Function walkfrom

src/mkmaze.c:1231–1275  ·  view source on GitHub ↗

Make the mazewalk iterative by faking a stack. This is needed to * ensure the mazewalk is successful in the limited stack space of * the program. This iterative version uses the minimum amount of stack * that is totally safe. */

Source from the content-addressed store, hash-verified

1229 * that is totally safe.
1230 */
1231void
1232walkfrom(coordxy x, coordxy y, schar typ)
1233{
1234#define CELLS (ROWNO * COLNO) / 4 /* a maze cell is 4 squares */
1235 char mazex[CELLS + 1], mazey[CELLS + 1]; /* char's are OK */
1236 int q, a, dir, pos;
1237 int dirs[4];
1238
1239 if (!typ) {
1240 if (svl.level.flags.corrmaze)
1241 typ = CORR;
1242 else
1243 typ = ROOM;
1244 }
1245
1246 pos = 1;
1247 mazex[pos] = (char) x;
1248 mazey[pos] = (char) y;
1249 while (pos) {
1250 x = (int) mazex[pos];
1251 y = (int) mazey[pos];
1252 if (!IS_DOOR(levl[x][y].typ)) {
1253 /* might still be on edge of MAP, so don't overwrite */
1254 levl[x][y].typ = typ;
1255 levl[x][y].flags = 0;
1256 }
1257 q = 0;
1258 for (a = 0; a < 4; a++)
1259 if (okay(x, y, a))
1260 dirs[q++] = a;
1261 if (!q)
1262 pos--;
1263 else {
1264 dir = dirs[rn2(q)];
1265 mz_move(x, y, dir);
1266 levl[x][y].typ = typ;
1267 mz_move(x, y, dir);
1268 pos++;
1269 if (pos > CELLS)
1270 panic("Overflow in walkfrom");
1271 mazex[pos] = (char) x;
1272 mazey[pos] = (char) y;
1273 }
1274 }
1275}
1276#else /* !MICRO */
1277
1278void

Callers 2

create_mazeFunction · 0.85
lspo_mazewalkFunction · 0.85

Calls 3

okayFunction · 0.85
rn2Function · 0.85
panicFunction · 0.50

Tested by

no test coverage detected