@@ -134,7 +134,6 @@ void MapgenV5Params::writeParams(Settings *settings) const
134
134
135
135
int MapgenV5::getSpawnLevelAtPoint (v2s16 p)
136
136
{
137
- // TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO);
138
137
139
138
float f = 0.55 + NoisePerlin2D (&noise_factor->np , p.X , p.Y , seed);
140
139
if (f < 0.01 )
@@ -143,25 +142,27 @@ int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
143
142
f *= 1.6 ;
144
143
float h = NoisePerlin2D (&noise_height->np , p.X , p.Y , seed);
145
144
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--) {
147
154
float n_ground = NoisePerlin3D (&noise_ground->np , p.X , y, p.Y , seed);
148
155
149
156
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)
153
158
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 ;
160
162
}
161
163
}
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;
165
166
}
166
167
167
168
0 commit comments