* 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
| 1799 | * in dungeons that build up is confined within them. |
| 1800 | */ |
| 1801 | void |
| 1802 | get_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? */ |
| 1848 | boolean |
no test coverage detected