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

Function fill_empty_maze

src/sp_lev.c:2925–2979  ·  view source on GitHub ↗

* If there's a significant portion of maze unused by the special level, * we don't want it empty. * * Makes the number of traps, monsters, etc. proportional * to the size of the maze. */

Source from the content-addressed store, hash-verified

2923 * to the size of the maze.
2924 */
2925staticfn void
2926fill_empty_maze(void)
2927{
2928 int mapcountmax, mapcount, mapfact;
2929 coordxy x, y;
2930 coord mm;
2931
2932 mapcountmax = mapcount = (gx.x_maze_max - 2) * (gy.y_maze_max - 2);
2933 mapcountmax = mapcountmax / 2;
2934
2935 for (x = 2; x < gx.x_maze_max; x++)
2936 for (y = 0; y < gy.y_maze_max; y++)
2937 if (SpLev_Map[x][y])
2938 mapcount--;
2939
2940 if ((mapcount > (int) (mapcountmax / 10))) {
2941 mapfact = (int) ((mapcount * 100L) / mapcountmax);
2942 for (x = rnd((int) (20 * mapfact) / 100); x; x--) {
2943 maze1xy(&mm, DRY);
2944 (void) mkobj_at(rn2(2) ? GEM_CLASS : RANDOM_CLASS, mm.x, mm.y,
2945 TRUE);
2946 }
2947 for (x = rnd((int) (12 * mapfact) / 100); x; x--) {
2948 struct trap *ttmp;
2949
2950 maze1xy(&mm, DRY);
2951 if ((ttmp = t_at(mm.x, mm.y)) != 0
2952 && (is_pit(ttmp->ttyp) || is_hole(ttmp->ttyp)))
2953 continue;
2954 (void) mksobj_at(BOULDER, mm.x, mm.y, TRUE, FALSE);
2955 }
2956 for (x = rn2(2); x; x--) {
2957 maze1xy(&mm, DRY);
2958 (void) makemon(&mons[PM_MINOTAUR], mm.x, mm.y, NO_MM_FLAGS);
2959 }
2960 for (x = rnd((int) (12 * mapfact) / 100); x; x--) {
2961 maze1xy(&mm, DRY);
2962 (void) makemon((struct permonst *) 0, mm.x, mm.y, NO_MM_FLAGS);
2963 }
2964 for (x = rn2((int) (15 * mapfact) / 100); x; x--) {
2965 maze1xy(&mm, DRY);
2966 (void) mkgold(0L, mm.x, mm.y);
2967 }
2968 for (x = rn2((int) (15 * mapfact) / 100); x; x--) {
2969 int trytrap;
2970
2971 maze1xy(&mm, DRY);
2972 trytrap = rndtrap();
2973 if (sobj_at(BOULDER, mm.x, mm.y))
2974 while (is_pit(trytrap) || is_hole(trytrap))
2975 trytrap = rndtrap();
2976 (void) maketrap(mm.x, mm.y, trytrap);
2977 }
2978 }
2979}
2980
2981staticfn void
2982splev_initlev(lev_init *linit)

Callers 1

lspo_mazewalkFunction · 0.85

Calls 11

rndFunction · 0.85
maze1xyFunction · 0.85
mkobj_atFunction · 0.85
rn2Function · 0.85
t_atFunction · 0.85
mksobj_atFunction · 0.85
makemonFunction · 0.85
mkgoldFunction · 0.85
rndtrapFunction · 0.85
sobj_atFunction · 0.85
maketrapFunction · 0.85

Tested by

no test coverage detected