Skip to content

Commit 3aab517

Browse files
paramatrubenwardy
authored andcommittedAug 12, 2017
Mgv5: Make spawn position search more reliable
1 parent bb1c711 commit 3aab517

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed
 

‎src/mapgen_v5.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ void MapgenV5Params::writeParams(Settings *settings) const
134134

135135
int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
136136
{
137-
//TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO);
138137

139138
float f = 0.55 + NoisePerlin2D(&noise_factor->np, p.X, p.Y, seed);
140139
if (f < 0.01)
@@ -143,25 +142,27 @@ int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
143142
f *= 1.6;
144143
float h = NoisePerlin2D(&noise_height->np, p.X, p.Y, seed);
145144

146-
for (s16 y = 128; y >= -128; y--) {
145+
// noise_height 'offset' is the average level of terrain. At least 50% of
146+
// terrain will be below this.
147+
// Raising the maximum spawn level above 'water_level + 16' is necessary
148+
// for when noise_height 'offset' is set much higher than water_level.
149+
s16 max_spawn_y = MYMAX(noise_height->np.offset, water_level + 16);
150+
151+
// Starting spawn search at max_spawn_y + 128 ensures 128 nodes of open
152+
// space above spawn position. Avoids spawning in possibly sealed voids.
153+
for (s16 y = max_spawn_y + 128; y >= water_level; y--) {
147154
float n_ground = NoisePerlin3D(&noise_ground->np, p.X, y, p.Y, seed);
148155

149156
if (n_ground * f > y - h) { // If solid
150-
// If either top 2 nodes of search are solid this is inside a
151-
// mountain or floatland with possibly no space for the player to spawn.
152-
if (y >= 127) {
157+
if (y < water_level || y > max_spawn_y)
153158
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
154-
} else { // Ground below at least 2 nodes of empty space
155-
if (y <= water_level || y > water_level + 16)
156-
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
157-
else
158-
return y;
159-
}
159+
else
160+
// y + 2 because y is surface and due to biome 'dust' nodes.
161+
return y + 2;
160162
}
161163
}
162-
163-
//printf("getGroundLevelAtPoint: %dus\n", t.stop());
164-
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn position, no ground found
164+
// Unsuitable spawn position, no ground found
165+
return MAX_MAP_GENERATION_LIMIT;
165166
}
166167

167168

0 commit comments

Comments
 (0)
Please sign in to comment.