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

Function init_dungeon_levels

src/dungeon.c:796–864  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

794}
795
796staticfn void
797init_dungeon_levels(
798 lua_State *L,
799 struct proto_dungeon *pd,
800 int dngidx)
801{
802 char *lvl_name, *lvl_bonetag, *lvl_chain;
803 int lvl_base, lvl_range, lvl_nlevels, lvl_chance,
804 lvl_align, lvl_flags;
805 struct tmplevel *tmpl;
806 int bi, f, nlevels;
807
808 lua_len(L, -1);
809 nlevels = (int) lua_tointeger(L, -1);
810 pd->tmpdungeon[dngidx].levels = nlevels;
811 lua_pop(L, 1);
812 for (f = 0; f < nlevels; f++) {
813 lua_pushinteger(L, f + 1);
814 lua_gettable(L, -2);
815 if (lua_type(L, -1) == LUA_TTABLE) {
816 lvl_name = get_table_str(L, "name");
817 lvl_bonetag = get_table_str_opt(L, "bonetag", emptystr);
818 lvl_chain = get_table_str_opt(L, "chainlevel", NULL);
819 lvl_base = get_table_int(L, "base");
820 lvl_range = get_table_int_opt(L, "range", 0);
821 lvl_nlevels = get_table_int_opt(L, "nlevels", 0);
822 lvl_chance = get_table_int_opt(L, "chance", 100);
823 lvl_align = get_dgn_align(L);
824 lvl_flags = get_dgn_flags(L);
825 /* array index is offset by cumulative number of levels
826 defined for preceding branches (iterations of 'while'
827 loop we're inside, not branch connections below) */
828 tmpl = &pd->tmplevel[pd->n_levs + f];
829
830 debugpline4("LEVEL[%i]:%s,(%i,%i)",
831 f, lvl_name, lvl_base, lvl_range);
832 tmpl->name = lvl_name;
833 tmpl->chainlvl = lvl_chain;
834 tmpl->lev.base = lvl_base;
835 tmpl->lev.rand = lvl_range;
836 tmpl->chance = lvl_chance;
837 tmpl->rndlevs = lvl_nlevels;
838 tmpl->flags = lvl_flags | lvl_align;
839 tmpl->boneschar = *lvl_bonetag ? *lvl_bonetag : 0;
840 free(lvl_bonetag);
841 tmpl->chain = -1;
842 if (lvl_chain) {
843 debugpline1("CHAINLEVEL: %s", lvl_chain);
844 for (bi = 0; bi < pd->n_levs + f; bi++) {
845 debugpline2("checking(%i):%s",
846 bi, pd->tmplevel[bi].name);
847 if (!strcmp(pd->tmplevel[bi].name, lvl_chain)) {
848 tmpl->chain = bi;
849 break;
850 }
851 }
852 if (tmpl->chain == -1)
853 panic("Could not chain level %s to %s",

Callers 1

init_dungeon_dungeonsFunction · 0.85

Calls 7

get_table_strFunction · 0.85
get_table_str_optFunction · 0.85
get_table_intFunction · 0.85
get_table_int_optFunction · 0.85
get_dgn_alignFunction · 0.85
get_dgn_flagsFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected