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

Function invoke_create_portal

src/artifact.c:1866–1931  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1864}
1865
1866staticfn int
1867invoke_create_portal(struct obj *obj)
1868{
1869 int i, num_ok_dungeons, last_ok_dungeon = 0;
1870 d_level newlev;
1871 winid tmpwin = create_nhwindow(NHW_MENU);
1872 anything any;
1873 int clr = NO_COLOR;
1874
1875 any = cg.zeroany; /* set all bits to zero */
1876 start_menu(tmpwin, MENU_BEHAVE_STANDARD);
1877 /* use index+1 (can't use 0) as identifier */
1878 for (i = num_ok_dungeons = 0; i < svn.n_dgns; i++) {
1879 if (!svd.dungeons[i].dunlev_ureached)
1880 continue;
1881 if (i == tutorial_dnum) /* can't portal into tutorial */
1882 continue;
1883 any.a_int = i + 1;
1884 add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0,
1885 ATR_NONE, clr,
1886 svd.dungeons[i].dname, MENU_ITEMFLAGS_NONE);
1887 num_ok_dungeons++;
1888 last_ok_dungeon = i;
1889 }
1890 end_menu(tmpwin, "Open a portal to which dungeon?");
1891 if (num_ok_dungeons > 1) {
1892 /* more than one entry; display menu for choices */
1893 menu_item *selected;
1894 int n;
1895
1896 n = select_menu(tmpwin, PICK_ONE, &selected);
1897 if (n <= 0) {
1898 destroy_nhwindow(tmpwin);
1899 nothing_special(obj);
1900 return ECMD_TIME;
1901 }
1902 i = selected[0].item.a_int - 1;
1903 free((genericptr_t) selected);
1904 } else
1905 i = last_ok_dungeon; /* also first & only OK dungeon */
1906 destroy_nhwindow(tmpwin);
1907
1908 /*
1909 * i is now index into dungeon structure for the new dungeon.
1910 * Find the closest level in the given dungeon, open
1911 * a use-once portal to that dungeon and go there.
1912 * The closest level is either the entry or dunlev_ureached.
1913 */
1914 newlev.dnum = i;
1915 if (svd.dungeons[i].depth_start >= depth(&u.uz))
1916 newlev.dlevel = svd.dungeons[i].entry_lev;
1917 else
1918 newlev.dlevel = svd.dungeons[i].dunlev_ureached;
1919
1920 if (u.uhave.amulet || In_endgame(&u.uz) || In_endgame(&newlev)
1921 || newlev.dnum == u.uz.dnum || !next_to_u()) {
1922 You_feel("very disoriented for a moment.");
1923 } else {

Callers 1

arti_invokeFunction · 0.85

Calls 8

add_menuFunction · 0.85
select_menuFunction · 0.85
nothing_specialFunction · 0.85
depthFunction · 0.85
next_to_uFunction · 0.85
You_feelFunction · 0.85
YouFunction · 0.85
goto_levelFunction · 0.85

Tested by

no test coverage detected