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

Function get_level

src/dungeon.c:1801–1845  ·  view source on GitHub ↗

* It is expected that the second argument of get_level is a depth value, * either supplied by the user (teleport control) or randomly generated. * But more than one level can be at the same depth. If the target level * is "above" the present depth location, get_level must trace "up" from * the player's location (through the ancestors dungeons) the dungeon * within which the target level is l

Source from the content-addressed store, hash-verified

1799 * in dungeons that build up is confined within them.
1800 */
1801void
1802get_level(d_level *newlevel, int levnum)
1803{
1804 branch *br;
1805 xint16 dgn = u.uz.dnum;
1806
1807 if (levnum <= 0) {
1808 /* can only currently happen in endgame */
1809 levnum = u.uz.dlevel;
1810 } else if (levnum > (svd.dungeons[dgn].depth_start
1811 + svd.dungeons[dgn].num_dunlevs - 1)) {
1812 /* beyond end of dungeon, jump to last level */
1813 levnum = svd.dungeons[dgn].num_dunlevs;
1814 } else {
1815 /* The desired level is in this dungeon or a "higher" one. */
1816
1817 /*
1818 * Branch up the tree until we reach a dungeon that contains the
1819 * levnum.
1820 */
1821 if (levnum < svd.dungeons[dgn].depth_start) {
1822 do {
1823 /*
1824 * Find the parent dungeon of this dungeon.
1825 *
1826 * This assumes that end2 is always the "child" and it is
1827 * unique.
1828 */
1829 for (br = svb.branches; br; br = br->next)
1830 if (br->end2.dnum == dgn)
1831 break;
1832 if (!br)
1833 panic("get_level: can't find parent dungeon");
1834
1835 dgn = br->end1.dnum;
1836 } while (levnum < svd.dungeons[dgn].depth_start);
1837 }
1838
1839 /* We're within the same dungeon; calculate the level. */
1840 levnum = levnum - svd.dungeons[dgn].depth_start + 1;
1841 }
1842
1843 newlevel->dnum = dgn;
1844 newlevel->dlevel = levnum;
1845}
1846
1847/* are you in the quest dungeon? */
1848boolean

Callers 10

peffect_gain_levelFunction · 0.85
level_teleFunction · 0.85
mlevel_tele_trapFunction · 0.85
moverock_coreFunction · 0.85
digactualholeFunction · 0.85
wiz_migrate_monsFunction · 0.85
launch_objFunction · 0.85
use_defensiveFunction · 0.85
use_miscFunction · 0.85
migrate_orcFunction · 0.85

Calls 1

panicFunction · 0.50

Tested by

no test coverage detected