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

Function place_level

src/dungeon.c:665–705  ·  view source on GitHub ↗

* Place a level. First, find the possible places on a dungeon map * template. Next pick one. Then try to place the next level. If * successful, we're done. Otherwise, try another (and another) until * all possible places have been tried. If all possible places have * been exhausted, return false. */

Source from the content-addressed store, hash-verified

663 * been exhausted, return false.
664 */
665staticfn boolean
666place_level(int proto_index, struct proto_dungeon *pd)
667{
668 boolean map[MAXLEVEL + 1]; /* valid levels are 1..MAXLEVEL inclusive */
669 s_level *lev;
670 int npossible;
671#ifdef DDEBUG
672 int i;
673#endif
674
675 if (proto_index == pd->n_levs)
676 return TRUE; /* at end of proto levels */
677
678 lev = pd->final_lev[proto_index];
679
680 /* No level created for this prototype, goto next. */
681 if (!lev)
682 return place_level(proto_index + 1, pd);
683
684 npossible = possible_places(proto_index, map, pd);
685
686 for (; npossible; --npossible) {
687 lev->dlevel.dlevel = pick_level(map, rn2(npossible));
688#ifdef DDEBUG
689 indent(proto_index - pd->start);
690 fprintf(stderr, "%s: trying %d [ ", lev->proto, lev->dlevel.dlevel);
691 for (i = 1; i <= MAXLEVEL; i++)
692 if (map[i])
693 fprintf(stderr, "%d ", i);
694 fprintf(stderr, "]\n");
695#endif
696 if (place_level(proto_index + 1, pd))
697 return TRUE;
698 map[lev->dlevel.dlevel] = FALSE; /* this choice didn't work */
699 }
700#ifdef DDEBUG
701 indent(proto_index - pd->start);
702 fprintf(stderr, "%s: failed\n", lev->proto);
703#endif
704 return FALSE;
705}
706
707static struct level_map {
708 const char *lev_name;

Callers 1

init_dungeonsFunction · 0.85

Calls 5

possible_placesFunction · 0.85
pick_levelFunction · 0.85
rn2Function · 0.85
indentFunction · 0.85
fprintfFunction · 0.85

Tested by

no test coverage detected