Skip to content

Commit ce1a70c

Browse files
committed
Mgv5: getGroundLevelAtPoint searches a larger range
1 parent 94464fc commit ce1a70c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/mapgen_v5.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,24 @@ int MapgenV5::getGroundLevelAtPoint(v2s16 p)
182182
f *= 1.6;
183183
float h = NoisePerlin2D(&noise_height->np, p.X, p.Y, seed);
184184

185-
s16 search_top = water_level + 15;
186-
s16 search_base = water_level;
185+
s16 search_start = 128; // Only bother searching this range, actual
186+
s16 search_end = -128; // ground level is rarely higher or lower.
187187

188-
s16 level = -31000;
189-
for (s16 y = search_top; y >= search_base; y--) {
188+
for (s16 y = search_start; y >= search_end; y--) {
190189
float n_ground = NoisePerlin3D(&noise_ground->np, p.X, y, p.Y, seed);
190+
// If solid
191191
if (n_ground * f > y - h) {
192-
if (y >= search_top - 7)
193-
break;
192+
// If either top 2 nodes of search are solid this is inside a
193+
// mountain or floatland with no space for the player to spawn.
194+
if (y >= search_start - 1)
195+
return MAX_MAP_GENERATION_LIMIT;
194196
else
195-
level = y;
196-
break;
197+
return y; // Ground below at least 2 nodes of space
197198
}
198199
}
199200

200201
//printf("getGroundLevelAtPoint: %dus\n", t.stop());
201-
return level;
202+
return -MAX_MAP_GENERATION_LIMIT;
202203
}
203204

204205

0 commit comments

Comments
 (0)