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

Function generate_stairs_find_room

src/mklev.c:2218–2245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2216
2217/* find a good room to generate an up or down stairs in */
2218staticfn struct mkroom *
2219generate_stairs_find_room(void)
2220{
2221 struct mkroom *croom;
2222 int i, phase, ai;
2223 int *rmarr;
2224
2225 if (!svn.nroom)
2226 return (struct mkroom *) 0;
2227
2228 rmarr = (int *) alloc(sizeof(int) * svn.nroom);
2229
2230 for (phase = 2; phase > -1; phase--) {
2231 ai = 0;
2232 for (i = 0; i < svn.nroom; i++)
2233 if (generate_stairs_room_good(&svr.rooms[i], phase))
2234 rmarr[ai++] = i;
2235 if (ai > 0) {
2236 i = rmarr[rn2(ai)];
2237 free(rmarr);
2238 return &svr.rooms[i];
2239 }
2240 }
2241
2242 free(rmarr);
2243 croom = &svr.rooms[rn2(svn.nroom)];
2244 return croom;
2245}
2246
2247/* construct stairs up and down within the same branch,
2248 up and down in different rooms if possible */

Callers 2

find_branch_roomFunction · 0.85
generate_stairsFunction · 0.85

Calls 3

rn2Function · 0.85
allocFunction · 0.70

Tested by

no test coverage detected