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

Function level_range

src/dungeon.c:379–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377 * end of the dungeon.
378 */
379staticfn int
380level_range(
381 xint16 dgn,
382 int base, int randc, int chain,
383 struct proto_dungeon *pd,
384 int *adjusted_base)
385{
386 int lmax = svd.dungeons[dgn].num_dunlevs;
387
388 if (chain >= 0) { /* relative to a special level */
389 s_level *levtmp = pd->final_lev[chain];
390 if (!levtmp)
391 panic("level_range: empty chain level!");
392
393 base += levtmp->dlevel.dlevel;
394 } else { /* absolute in the dungeon */
395 /* from end of dungeon */
396 if (base < 0)
397 base = (lmax + base + 1);
398 }
399
400 if (base < 1 || base > lmax)
401 panic("level_range: base value out of range");
402
403 *adjusted_base = base;
404
405 if (randc == -1) { /* from base to end of dungeon */
406 return (lmax - base + 1);
407 } else if (randc) {
408 /* make sure we don't run off the end of the dungeon */
409 return (((base + randc - 1) > lmax) ? lmax - base + 1 : randc);
410 } /* else only one choice */
411 return 1;
412}
413
414staticfn xint16
415parent_dlevel(const char *s, struct proto_dungeon *pd)

Callers 2

parent_dlevelFunction · 0.85
possible_placesFunction · 0.85

Calls 1

panicFunction · 0.50

Tested by

no test coverage detected