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

Function mkstairs

src/mklev.c:2158–2197  ·  view source on GitHub ↗

Create stairs up or down at x,y. If force is TRUE, change the terrain to ROOM first */

Source from the content-addressed store, hash-verified

2156/* Create stairs up or down at x,y.
2157 If force is TRUE, change the terrain to ROOM first */
2158void
2159mkstairs(
2160 coordxy x, coordxy y,
2161 char up, /* [why 'char' when usage is boolean?] */
2162 struct mkroom *croom UNUSED,
2163 boolean force)
2164{
2165 int ltyp;
2166 d_level dest;
2167
2168 if (!x || !isok(x, y)) {
2169 impossible("mkstairs: bogus stair attempt at <%d,%d>", x, y);
2170 return;
2171 }
2172 if (force)
2173 levl[x][y].typ = ROOM;
2174 ltyp = levl[x][y].typ; /* somexyspace() allows ice */
2175 if (ltyp != ROOM && ltyp != CORR && ltyp != ICE) {
2176 int glyph = back_to_glyph(x, y),
2177 sidx = glyph_to_cmap(glyph);
2178
2179 impossible("mkstairs: placing stairs %s on %s at <%d,%d>",
2180 up ? "up" : "down", defsyms[sidx].explanation, x, y);
2181 }
2182
2183 /*
2184 * We can't make a regular stair off an end of the dungeon. This
2185 * attempt can happen when a special level is placed at an end and
2186 * has an up or down stair specified in its description file.
2187 */
2188 if (dunlev(&u.uz) == (up ? 1 : dunlevs_in_dungeon(&u.uz)))
2189 return;
2190
2191 dest.dnum = u.uz.dnum;
2192 dest.dlevel = u.uz.dlevel + (up ? -1 : 1);
2193 stairway_add(x, y, up ? TRUE : FALSE, FALSE, &dest);
2194
2195 (void) set_levltyp(x, y, STAIRS);
2196 levl[x][y].ladder = up ? LA_UP : LA_DOWN;
2197}
2198
2199/* is room a good one to generate up or down stairs in? */
2200staticfn boolean

Callers 5

generate_stairsFunction · 0.85
mkinvokeareaFunction · 0.85
put_lregion_hereFunction · 0.85
makemazFunction · 0.85
l_create_stairwayFunction · 0.85

Calls 8

isokFunction · 0.85
back_to_glyphFunction · 0.85
glyph_to_cmapFunction · 0.85
dunlevFunction · 0.85
dunlevs_in_dungeonFunction · 0.85
stairway_addFunction · 0.85
set_levltypFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected