2013-04-21 06:11:05 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
2018-01-15 03:26:15 +01:00
|
|
|
Copyright (C) 2010-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
Copyright (C) 2010-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
|
|
|
|
Copyright (C) 2015-2018 paramat
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util/numeric.h"
|
2018-04-02 23:51:08 +02:00
|
|
|
#include <cmath>
|
2013-04-21 06:11:05 +02:00
|
|
|
#include "map.h"
|
|
|
|
#include "mapgen.h"
|
2015-01-21 14:24:11 +01:00
|
|
|
#include "mapgen_v5.h"
|
2013-04-28 04:40:52 +02:00
|
|
|
#include "mapgen_v6.h"
|
|
|
|
#include "mapgen_v7.h"
|
2016-05-19 09:40:22 +02:00
|
|
|
#include "mg_biome.h"
|
2013-04-21 06:11:05 +02:00
|
|
|
#include "cavegen.h"
|
|
|
|
|
2016-05-27 05:23:05 +02:00
|
|
|
static NoiseParams nparams_caveliquids(0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0.6, 2.0);
|
2013-07-02 03:10:59 +02:00
|
|
|
|
2016-05-19 09:40:22 +02:00
|
|
|
|
|
|
|
////
|
|
|
|
//// CavesNoiseIntersection
|
|
|
|
////
|
|
|
|
|
|
|
|
CavesNoiseIntersection::CavesNoiseIntersection(
|
2018-02-10 21:04:16 +01:00
|
|
|
const NodeDefManager *nodedef, BiomeManager *biomemgr, v3s16 chunksize,
|
2016-06-04 07:35:37 +02:00
|
|
|
NoiseParams *np_cave1, NoiseParams *np_cave2, s32 seed, float cave_width)
|
2016-05-19 09:40:22 +02:00
|
|
|
{
|
|
|
|
assert(nodedef);
|
|
|
|
assert(biomemgr);
|
|
|
|
|
|
|
|
m_ndef = nodedef;
|
|
|
|
m_bmgr = biomemgr;
|
|
|
|
|
|
|
|
m_csize = chunksize;
|
|
|
|
m_cave_width = cave_width;
|
|
|
|
|
|
|
|
m_ystride = m_csize.X;
|
|
|
|
m_zstride_1d = m_csize.X * (m_csize.Y + 1);
|
|
|
|
|
|
|
|
// Noises are created using 1-down overgeneration
|
|
|
|
// A Nx-by-1-by-Nz-sized plane is at the bottom of the desired for
|
|
|
|
// re-carving the solid overtop placed for blocking sunlight
|
|
|
|
noise_cave1 = new Noise(np_cave1, seed, m_csize.X, m_csize.Y + 1, m_csize.Z);
|
|
|
|
noise_cave2 = new Noise(np_cave2, seed, m_csize.X, m_csize.Y + 1, m_csize.Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CavesNoiseIntersection::~CavesNoiseIntersection()
|
|
|
|
{
|
|
|
|
delete noise_cave1;
|
|
|
|
delete noise_cave2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CavesNoiseIntersection::generateCaves(MMVManip *vm,
|
|
|
|
v3s16 nmin, v3s16 nmax, u8 *biomemap)
|
|
|
|
{
|
|
|
|
assert(vm);
|
|
|
|
assert(biomemap);
|
|
|
|
|
|
|
|
noise_cave1->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);
|
|
|
|
noise_cave2->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);
|
|
|
|
|
2017-07-26 07:35:09 +02:00
|
|
|
const v3s16 &em = vm->m_area.getExtent();
|
2017-02-15 01:14:11 +01:00
|
|
|
u32 index2d = 0; // Biomemap index
|
2016-05-19 09:40:22 +02:00
|
|
|
|
|
|
|
for (s16 z = nmin.Z; z <= nmax.Z; z++)
|
|
|
|
for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) {
|
|
|
|
bool column_is_open = false; // Is column open to overground
|
2016-07-20 01:23:08 +02:00
|
|
|
bool is_under_river = false; // Is column under river water
|
2017-02-15 01:14:11 +01:00
|
|
|
bool is_under_tunnel = false; // Is tunnel or is under tunnel
|
2017-09-11 22:23:43 +02:00
|
|
|
bool is_top_filler_above = false; // Is top or filler above node
|
2017-02-15 01:14:11 +01:00
|
|
|
// Indexes at column top
|
2016-05-19 09:40:22 +02:00
|
|
|
u32 vi = vm->m_area.index(x, nmax.Y, z);
|
|
|
|
u32 index3d = (z - nmin.Z) * m_zstride_1d + m_csize.Y * m_ystride +
|
2017-02-15 01:14:11 +01:00
|
|
|
(x - nmin.X); // 3D noise index
|
2016-05-19 09:40:22 +02:00
|
|
|
// Biome of column
|
|
|
|
Biome *biome = (Biome *)m_bmgr->getRaw(biomemap[index2d]);
|
2017-02-15 01:14:11 +01:00
|
|
|
u16 depth_top = biome->depth_top;
|
|
|
|
u16 base_filler = depth_top + biome->depth_filler;
|
|
|
|
u16 depth_riverbed = biome->depth_riverbed;
|
|
|
|
u16 nplaced = 0;
|
2016-05-19 09:40:22 +02:00
|
|
|
// Don't excavate the overgenerated stone at nmax.Y + 1,
|
|
|
|
// this creates a 'roof' over the tunnel, preventing light in
|
|
|
|
// tunnels at mapchunk borders when generating mapchunks upwards.
|
|
|
|
// This 'roof' is removed when the mapchunk above is generated.
|
|
|
|
for (s16 y = nmax.Y; y >= nmin.Y - 1; y--,
|
|
|
|
index3d -= m_ystride,
|
2018-03-09 08:49:00 +01:00
|
|
|
VoxelArea::add_y(em, vi, -1)) {
|
2016-05-19 09:40:22 +02:00
|
|
|
content_t c = vm->m_data[vi].getContent();
|
2017-09-11 22:23:43 +02:00
|
|
|
|
2016-05-19 09:40:22 +02:00
|
|
|
if (c == CONTENT_AIR || c == biome->c_water_top ||
|
|
|
|
c == biome->c_water) {
|
|
|
|
column_is_open = true;
|
2017-09-11 22:23:43 +02:00
|
|
|
is_top_filler_above = false;
|
2016-05-19 09:40:22 +02:00
|
|
|
continue;
|
2017-08-20 19:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == biome->c_river_water) {
|
2016-07-20 01:23:08 +02:00
|
|
|
column_is_open = true;
|
|
|
|
is_under_river = true;
|
2017-09-11 22:23:43 +02:00
|
|
|
is_top_filler_above = false;
|
2016-07-20 01:23:08 +02:00
|
|
|
continue;
|
2016-05-19 09:40:22 +02:00
|
|
|
}
|
2017-09-11 22:23:43 +02:00
|
|
|
|
2016-05-19 09:40:22 +02:00
|
|
|
// Ground
|
|
|
|
float d1 = contour(noise_cave1->result[index3d]);
|
|
|
|
float d2 = contour(noise_cave2->result[index3d]);
|
|
|
|
|
|
|
|
if (d1 * d2 > m_cave_width && m_ndef->get(c).is_ground_content) {
|
|
|
|
// In tunnel and ground content, excavate
|
|
|
|
vm->m_data[vi] = MapNode(CONTENT_AIR);
|
2017-02-15 01:14:11 +01:00
|
|
|
is_under_tunnel = true;
|
2017-09-11 22:23:43 +02:00
|
|
|
// If tunnel roof is top or filler, replace with stone
|
|
|
|
if (is_top_filler_above)
|
|
|
|
vm->m_data[vi + em.X] = MapNode(biome->c_stone);
|
|
|
|
is_top_filler_above = false;
|
2017-02-15 01:14:11 +01:00
|
|
|
} else if (column_is_open && is_under_tunnel &&
|
|
|
|
(c == biome->c_stone || c == biome->c_filler)) {
|
|
|
|
// Tunnel entrance floor, place biome surface nodes
|
|
|
|
if (is_under_river) {
|
|
|
|
if (nplaced < depth_riverbed) {
|
2016-07-20 01:23:08 +02:00
|
|
|
vm->m_data[vi] = MapNode(biome->c_riverbed);
|
2017-09-11 22:23:43 +02:00
|
|
|
is_top_filler_above = true;
|
2017-02-15 01:14:11 +01:00
|
|
|
nplaced++;
|
|
|
|
} else {
|
|
|
|
// Disable top/filler placement
|
|
|
|
column_is_open = false;
|
|
|
|
is_under_river = false;
|
|
|
|
is_under_tunnel = false;
|
|
|
|
}
|
|
|
|
} else if (nplaced < depth_top) {
|
|
|
|
vm->m_data[vi] = MapNode(biome->c_top);
|
2017-09-11 22:23:43 +02:00
|
|
|
is_top_filler_above = true;
|
2017-02-15 01:14:11 +01:00
|
|
|
nplaced++;
|
|
|
|
} else if (nplaced < base_filler) {
|
|
|
|
vm->m_data[vi] = MapNode(biome->c_filler);
|
2017-09-11 22:23:43 +02:00
|
|
|
is_top_filler_above = true;
|
2017-02-15 01:14:11 +01:00
|
|
|
nplaced++;
|
|
|
|
} else {
|
|
|
|
// Disable top/filler placement
|
|
|
|
column_is_open = false;
|
|
|
|
is_under_tunnel = false;
|
2016-07-20 01:23:08 +02:00
|
|
|
}
|
2017-02-15 01:14:11 +01:00
|
|
|
} else {
|
|
|
|
// Not tunnel or tunnel entrance floor
|
2017-09-11 22:23:43 +02:00
|
|
|
// Check node for possible replacing with stone for tunnel roof
|
|
|
|
if (c == biome->c_top || c == biome->c_filler)
|
|
|
|
is_top_filler_above = true;
|
|
|
|
|
2016-05-19 09:40:22 +02:00
|
|
|
column_is_open = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-12 14:26:09 +01:00
|
|
|
////
|
|
|
|
//// CavernsNoise
|
|
|
|
////
|
|
|
|
|
|
|
|
CavernsNoise::CavernsNoise(
|
2018-02-10 21:04:16 +01:00
|
|
|
const NodeDefManager *nodedef, v3s16 chunksize, NoiseParams *np_cavern,
|
2017-03-12 14:26:09 +01:00
|
|
|
s32 seed, float cavern_limit, float cavern_taper, float cavern_threshold)
|
|
|
|
{
|
|
|
|
assert(nodedef);
|
|
|
|
|
2017-05-11 04:39:43 +02:00
|
|
|
m_ndef = nodedef;
|
2017-03-12 14:26:09 +01:00
|
|
|
|
2017-05-11 04:39:43 +02:00
|
|
|
m_csize = chunksize;
|
2017-03-12 14:26:09 +01:00
|
|
|
m_cavern_limit = cavern_limit;
|
|
|
|
m_cavern_taper = cavern_taper;
|
|
|
|
m_cavern_threshold = cavern_threshold;
|
|
|
|
|
|
|
|
m_ystride = m_csize.X;
|
|
|
|
m_zstride_1d = m_csize.X * (m_csize.Y + 1);
|
|
|
|
|
|
|
|
// Noise is created using 1-down overgeneration
|
|
|
|
// A Nx-by-1-by-Nz-sized plane is at the bottom of the desired for
|
|
|
|
// re-carving the solid overtop placed for blocking sunlight
|
|
|
|
noise_cavern = new Noise(np_cavern, seed, m_csize.X, m_csize.Y + 1, m_csize.Z);
|
|
|
|
|
|
|
|
c_water_source = m_ndef->getId("mapgen_water_source");
|
|
|
|
if (c_water_source == CONTENT_IGNORE)
|
|
|
|
c_water_source = CONTENT_AIR;
|
|
|
|
|
|
|
|
c_lava_source = m_ndef->getId("mapgen_lava_source");
|
|
|
|
if (c_lava_source == CONTENT_IGNORE)
|
|
|
|
c_lava_source = CONTENT_AIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CavernsNoise::~CavernsNoise()
|
|
|
|
{
|
|
|
|
delete noise_cavern;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax)
|
|
|
|
{
|
|
|
|
assert(vm);
|
|
|
|
|
|
|
|
// Calculate noise
|
|
|
|
noise_cavern->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);
|
|
|
|
|
|
|
|
// Cache cavern_amp values
|
2017-04-07 17:59:27 +02:00
|
|
|
float *cavern_amp = new float[m_csize.Y + 1];
|
2017-03-12 14:26:09 +01:00
|
|
|
u8 cavern_amp_index = 0; // Index zero at column top
|
|
|
|
for (s16 y = nmax.Y; y >= nmin.Y - 1; y--, cavern_amp_index++) {
|
|
|
|
cavern_amp[cavern_amp_index] =
|
|
|
|
MYMIN((m_cavern_limit - y) / (float)m_cavern_taper, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
//// Place nodes
|
2017-05-11 04:39:43 +02:00
|
|
|
bool near_cavern = false;
|
2017-07-26 07:35:09 +02:00
|
|
|
const v3s16 &em = vm->m_area.getExtent();
|
2017-03-12 14:26:09 +01:00
|
|
|
u32 index2d = 0;
|
|
|
|
|
|
|
|
for (s16 z = nmin.Z; z <= nmax.Z; z++)
|
|
|
|
for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) {
|
|
|
|
// Reset cave_amp index to column top
|
|
|
|
cavern_amp_index = 0;
|
|
|
|
// Initial voxelmanip index at column top
|
|
|
|
u32 vi = vm->m_area.index(x, nmax.Y, z);
|
|
|
|
// Initial 3D noise index at column top
|
|
|
|
u32 index3d = (z - nmin.Z) * m_zstride_1d + m_csize.Y * m_ystride +
|
|
|
|
(x - nmin.X);
|
|
|
|
// Don't excavate the overgenerated stone at node_max.Y + 1,
|
|
|
|
// this creates a 'roof' over the cavern, preventing light in
|
|
|
|
// caverns at mapchunk borders when generating mapchunks upwards.
|
|
|
|
// This 'roof' is excavated when the mapchunk above is generated.
|
|
|
|
for (s16 y = nmax.Y; y >= nmin.Y - 1; y--,
|
|
|
|
index3d -= m_ystride,
|
2018-03-09 08:49:00 +01:00
|
|
|
VoxelArea::add_y(em, vi, -1),
|
2017-03-12 14:26:09 +01:00
|
|
|
cavern_amp_index++) {
|
|
|
|
content_t c = vm->m_data[vi].getContent();
|
2018-04-02 23:51:08 +02:00
|
|
|
float n_absamp_cavern = std::fabs(noise_cavern->result[index3d]) *
|
2017-05-11 04:39:43 +02:00
|
|
|
cavern_amp[cavern_amp_index];
|
|
|
|
// Disable CavesRandomWalk at a safe distance from caverns
|
|
|
|
// to avoid excessively spreading liquids in caverns.
|
|
|
|
if (n_absamp_cavern > m_cavern_threshold - 0.1f) {
|
|
|
|
near_cavern = true;
|
|
|
|
if (n_absamp_cavern > m_cavern_threshold &&
|
|
|
|
m_ndef->get(c).is_ground_content)
|
|
|
|
vm->m_data[vi] = MapNode(CONTENT_AIR);
|
2017-03-12 14:26:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-07 17:59:27 +02:00
|
|
|
delete[] cavern_amp;
|
2017-05-11 04:39:43 +02:00
|
|
|
|
|
|
|
return near_cavern;
|
2017-03-12 14:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 19:21:13 +02:00
|
|
|
////
|
|
|
|
//// CavesRandomWalk
|
|
|
|
////
|
2013-04-21 06:11:05 +02:00
|
|
|
|
2016-05-11 04:56:03 +02:00
|
|
|
CavesRandomWalk::CavesRandomWalk(
|
2018-02-10 21:04:16 +01:00
|
|
|
const NodeDefManager *ndef,
|
2016-05-11 04:56:03 +02:00
|
|
|
GenerateNotifier *gennotify,
|
2016-06-04 07:35:37 +02:00
|
|
|
s32 seed,
|
2016-05-11 04:56:03 +02:00
|
|
|
int water_level,
|
|
|
|
content_t water_source,
|
2017-06-21 05:20:18 +02:00
|
|
|
content_t lava_source,
|
2018-04-05 18:21:41 +02:00
|
|
|
int lava_depth,
|
|
|
|
BiomeGen *biomegen)
|
2015-08-03 05:34:11 +02:00
|
|
|
{
|
2016-05-11 04:56:03 +02:00
|
|
|
assert(ndef);
|
|
|
|
|
|
|
|
this->ndef = ndef;
|
|
|
|
this->gennotify = gennotify;
|
|
|
|
this->seed = seed;
|
|
|
|
this->water_level = water_level;
|
2015-03-04 11:14:07 +01:00
|
|
|
this->np_caveliquids = &nparams_caveliquids;
|
2017-06-21 05:20:18 +02:00
|
|
|
this->lava_depth = lava_depth;
|
2018-04-05 18:21:41 +02:00
|
|
|
this->bmgn = biomegen;
|
2016-05-10 06:01:37 +02:00
|
|
|
|
2016-05-11 04:56:03 +02:00
|
|
|
c_water_source = water_source;
|
|
|
|
if (c_water_source == CONTENT_IGNORE)
|
|
|
|
c_water_source = ndef->getId("mapgen_water_source");
|
|
|
|
if (c_water_source == CONTENT_IGNORE)
|
|
|
|
c_water_source = CONTENT_AIR;
|
2013-04-21 06:11:05 +02:00
|
|
|
|
2016-05-11 04:56:03 +02:00
|
|
|
c_lava_source = lava_source;
|
|
|
|
if (c_lava_source == CONTENT_IGNORE)
|
|
|
|
c_lava_source = ndef->getId("mapgen_lava_source");
|
|
|
|
if (c_lava_source == CONTENT_IGNORE)
|
|
|
|
c_lava_source = CONTENT_AIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CavesRandomWalk::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax,
|
2016-05-11 06:00:05 +02:00
|
|
|
PseudoRandom *ps, bool is_large_cave, int max_stone_height, s16 *heightmap)
|
2016-05-11 04:56:03 +02:00
|
|
|
{
|
|
|
|
assert(vm);
|
|
|
|
assert(ps);
|
|
|
|
|
2016-05-11 06:00:05 +02:00
|
|
|
this->vm = vm;
|
|
|
|
this->ps = ps;
|
|
|
|
this->node_min = nmin;
|
|
|
|
this->node_max = nmax;
|
|
|
|
this->heightmap = heightmap;
|
|
|
|
this->large_cave = is_large_cave;
|
2016-05-11 04:56:03 +02:00
|
|
|
|
|
|
|
this->ystride = nmax.X - nmin.X + 1;
|
|
|
|
|
|
|
|
// Set initial parameters from randomness
|
2016-05-15 04:46:50 +02:00
|
|
|
int dswitchint = ps->range(1, 14);
|
|
|
|
flooded = ps->range(1, 2) == 2;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2016-05-11 06:00:05 +02:00
|
|
|
if (large_cave) {
|
|
|
|
part_max_length_rs = ps->range(2, 4);
|
|
|
|
tunnel_routepoints = ps->range(5, ps->range(15, 30));
|
|
|
|
min_tunnel_diameter = 5;
|
|
|
|
max_tunnel_diameter = ps->range(7, ps->range(8, 24));
|
|
|
|
} else {
|
|
|
|
part_max_length_rs = ps->range(2, 9);
|
|
|
|
tunnel_routepoints = ps->range(10, ps->range(15, 30));
|
|
|
|
min_tunnel_diameter = 2;
|
|
|
|
max_tunnel_diameter = ps->range(2, 6);
|
|
|
|
}
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2015-03-04 11:14:07 +01:00
|
|
|
large_cave_is_flat = (ps->range(0, 1) == 0);
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
main_direction = v3f(0, 0, 0);
|
|
|
|
|
|
|
|
// Allowed route area size in nodes
|
|
|
|
ar = node_max - node_min + v3s16(1, 1, 1);
|
|
|
|
// Area starting point in nodes
|
|
|
|
of = node_min;
|
|
|
|
|
|
|
|
// Allow a bit more
|
|
|
|
//(this should be more than the maximum radius of the tunnel)
|
2016-05-15 04:46:50 +02:00
|
|
|
const s16 insure = 10;
|
2015-03-04 11:14:07 +01:00
|
|
|
s16 more = MYMAX(MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure, 1);
|
2016-05-15 04:46:50 +02:00
|
|
|
ar += v3s16(1, 0, 1) * more * 2;
|
|
|
|
of -= v3s16(1, 0, 1) * more;
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
route_y_min = 0;
|
|
|
|
// Allow half a diameter + 7 over stone surface
|
2018-04-17 23:25:59 +02:00
|
|
|
route_y_max = -of.Y + max_stone_height + max_tunnel_diameter / 2 + 7;
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
// Limit maximum to area
|
|
|
|
route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
|
|
|
|
|
2016-05-11 06:00:05 +02:00
|
|
|
if (large_cave) {
|
|
|
|
s16 minpos = 0;
|
|
|
|
if (node_min.Y < water_level && node_max.Y > water_level) {
|
|
|
|
minpos = water_level - max_tunnel_diameter / 3 - of.Y;
|
|
|
|
route_y_max = water_level + max_tunnel_diameter / 3 - of.Y;
|
|
|
|
}
|
|
|
|
route_y_min = ps->range(minpos, minpos + max_tunnel_diameter);
|
|
|
|
route_y_min = rangelim(route_y_min, 0, route_y_max);
|
2016-05-10 06:01:37 +02:00
|
|
|
}
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
s16 route_start_y_min = route_y_min;
|
|
|
|
s16 route_start_y_max = route_y_max;
|
|
|
|
|
2015-03-04 11:14:07 +01:00
|
|
|
route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1);
|
|
|
|
route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1);
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
// Randomize starting position
|
2016-05-15 04:46:50 +02:00
|
|
|
orp.Z = (float)(ps->next() % ar.Z) + 0.5f;
|
|
|
|
orp.Y = (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5f;
|
|
|
|
orp.X = (float)(ps->next() % ar.X) + 0.5f;
|
2013-04-21 06:11:05 +02:00
|
|
|
|
2014-12-06 10:18:04 +01:00
|
|
|
// Add generation notify begin event
|
2016-05-11 04:56:03 +02:00
|
|
|
if (gennotify) {
|
|
|
|
v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
|
2016-05-11 06:00:05 +02:00
|
|
|
GenNotifyType notifytype = large_cave ?
|
|
|
|
GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN;
|
2016-05-11 04:56:03 +02:00
|
|
|
gennotify->addEvent(notifytype, abs_pos);
|
|
|
|
}
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
// Generate some tunnel starting from orp
|
|
|
|
for (u16 j = 0; j < tunnel_routepoints; j++)
|
|
|
|
makeTunnel(j % dswitchint == 0);
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2014-12-06 10:18:04 +01:00
|
|
|
// Add generation notify end event
|
2016-05-11 04:56:03 +02:00
|
|
|
if (gennotify) {
|
|
|
|
v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
|
2016-05-11 06:00:05 +02:00
|
|
|
GenNotifyType notifytype = large_cave ?
|
|
|
|
GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END;
|
2016-05-11 04:56:03 +02:00
|
|
|
gennotify->addEvent(notifytype, abs_pos);
|
|
|
|
}
|
2013-04-21 06:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 06:01:37 +02:00
|
|
|
void CavesRandomWalk::makeTunnel(bool dirswitch)
|
2015-08-03 05:34:11 +02:00
|
|
|
{
|
2016-05-11 06:00:05 +02:00
|
|
|
if (dirswitch && !large_cave) {
|
2016-05-11 09:47:45 +02:00
|
|
|
main_direction.Z = ((float)(ps->next() % 20) - (float)10) / 10;
|
|
|
|
main_direction.Y = ((float)(ps->next() % 20) - (float)10) / 30;
|
|
|
|
main_direction.X = ((float)(ps->next() % 20) - (float)10) / 10;
|
|
|
|
|
2016-05-11 06:00:05 +02:00
|
|
|
main_direction *= (float)ps->range(0, 10) / 10;
|
|
|
|
}
|
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
// Randomize size
|
|
|
|
s16 min_d = min_tunnel_diameter;
|
|
|
|
s16 max_d = max_tunnel_diameter;
|
|
|
|
rs = ps->range(min_d, max_d);
|
2015-03-04 11:14:07 +01:00
|
|
|
s16 rs_part_max_length_rs = rs * part_max_length_rs;
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
v3s16 maxlen;
|
2016-05-11 06:00:05 +02:00
|
|
|
if (large_cave) {
|
|
|
|
maxlen = v3s16(
|
|
|
|
rs_part_max_length_rs,
|
|
|
|
rs_part_max_length_rs / 2,
|
|
|
|
rs_part_max_length_rs
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
maxlen = v3s16(
|
|
|
|
rs_part_max_length_rs,
|
|
|
|
ps->range(1, rs_part_max_length_rs),
|
|
|
|
rs_part_max_length_rs
|
|
|
|
);
|
|
|
|
}
|
2013-04-21 06:11:05 +02:00
|
|
|
|
2015-03-04 11:14:07 +01:00
|
|
|
v3f vec;
|
2013-04-21 06:11:05 +02:00
|
|
|
// Jump downward sometimes
|
2016-05-11 06:00:05 +02:00
|
|
|
if (!large_cave && ps->range(0, 12) == 0) {
|
2016-05-11 09:47:45 +02:00
|
|
|
vec.Z = (float)(ps->next() % (maxlen.Z * 1)) - (float)maxlen.Z / 2;
|
|
|
|
vec.Y = (float)(ps->next() % (maxlen.Y * 2)) - (float)maxlen.Y;
|
|
|
|
vec.X = (float)(ps->next() % (maxlen.X * 1)) - (float)maxlen.X / 2;
|
2016-05-11 06:00:05 +02:00
|
|
|
} else {
|
2016-05-11 09:47:45 +02:00
|
|
|
vec.Z = (float)(ps->next() % (maxlen.Z * 1)) - (float)maxlen.Z / 2;
|
|
|
|
vec.Y = (float)(ps->next() % (maxlen.Y * 1)) - (float)maxlen.Y / 2;
|
|
|
|
vec.X = (float)(ps->next() % (maxlen.X * 1)) - (float)maxlen.X / 2;
|
2016-05-11 06:00:05 +02:00
|
|
|
}
|
2013-04-21 06:11:05 +02:00
|
|
|
|
2015-07-18 21:37:04 +02:00
|
|
|
// Do not make caves that are above ground.
|
2015-03-01 02:30:47 +01:00
|
|
|
// It is only necessary to check the startpoint and endpoint.
|
2016-05-10 19:35:39 +02:00
|
|
|
v3s16 p1 = v3s16(orp.X, orp.Y, orp.Z) + of + rs / 2;
|
|
|
|
v3s16 p2 = v3s16(vec.X, vec.Y, vec.Z) + p1;
|
|
|
|
if (isPosAboveSurface(p1) || isPosAboveSurface(p2))
|
2015-03-04 11:14:07 +01:00
|
|
|
return;
|
2015-03-01 02:30:47 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
vec += main_direction;
|
|
|
|
|
|
|
|
v3f rp = orp + vec;
|
|
|
|
if (rp.X < 0)
|
|
|
|
rp.X = 0;
|
|
|
|
else if (rp.X >= ar.X)
|
|
|
|
rp.X = ar.X - 1;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
if (rp.Y < route_y_min)
|
|
|
|
rp.Y = route_y_min;
|
|
|
|
else if (rp.Y >= route_y_max)
|
|
|
|
rp.Y = route_y_max - 1;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
if (rp.Z < 0)
|
|
|
|
rp.Z = 0;
|
|
|
|
else if (rp.Z >= ar.Z)
|
|
|
|
rp.Z = ar.Z - 1;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
vec = rp - orp;
|
|
|
|
|
|
|
|
float veclen = vec.getLength();
|
2016-05-15 04:46:50 +02:00
|
|
|
if (veclen < 0.05f)
|
|
|
|
veclen = 1.0f;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
// Every second section is rough
|
2015-03-04 11:14:07 +01:00
|
|
|
bool randomize_xz = (ps->range(1, 2) == 1);
|
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
// Carve routes
|
2016-05-15 04:46:50 +02:00
|
|
|
for (float f = 0.f; f < 1.0f; f += 1.0f / veclen)
|
2015-07-18 21:37:04 +02:00
|
|
|
carveRoute(vec, f, randomize_xz);
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
orp = rp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 06:01:37 +02:00
|
|
|
void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz)
|
2015-08-03 05:34:11 +02:00
|
|
|
{
|
2013-04-21 06:11:05 +02:00
|
|
|
MapNode airnode(CONTENT_AIR);
|
|
|
|
MapNode waternode(c_water_source);
|
|
|
|
MapNode lavanode(c_lava_source);
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
v3s16 startp(orp.X, orp.Y, orp.Z);
|
|
|
|
startp += of;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2018-04-21 21:35:29 +02:00
|
|
|
v3f fp = orp + vec * f;
|
|
|
|
fp.X += 0.1f * ps->range(-10, 10);
|
|
|
|
fp.Z += 0.1f * ps->range(-10, 10);
|
|
|
|
v3s16 cp(fp.X, fp.Y, fp.Z);
|
|
|
|
|
|
|
|
// Get biome at 'cp + of', the absolute centre point of this route
|
|
|
|
v3s16 cpabs = cp + of;
|
2018-04-05 18:21:41 +02:00
|
|
|
MapNode liquidnode = CONTENT_IGNORE;
|
|
|
|
|
|
|
|
if (bmgn) {
|
2018-04-21 21:35:29 +02:00
|
|
|
Biome *biome = (Biome *)bmgn->calcBiomeAtPoint(cpabs);
|
2018-04-05 18:21:41 +02:00
|
|
|
if (biome->c_cave_liquid != CONTENT_IGNORE)
|
|
|
|
liquidnode = biome->c_cave_liquid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (liquidnode == CONTENT_IGNORE) {
|
2018-04-21 21:35:29 +02:00
|
|
|
// Fallback to classic behaviour using point 'startp'
|
2018-04-05 18:21:41 +02:00
|
|
|
float nval = NoisePerlin3D(np_caveliquids, startp.X,
|
|
|
|
startp.Y, startp.Z, seed);
|
|
|
|
liquidnode = (nval < 0.40f && node_max.Y < lava_depth) ?
|
|
|
|
lavanode : waternode;
|
|
|
|
}
|
2015-03-04 11:14:07 +01:00
|
|
|
|
2016-05-15 04:46:50 +02:00
|
|
|
s16 d0 = -rs / 2;
|
2013-04-21 06:11:05 +02:00
|
|
|
s16 d1 = d0 + rs;
|
|
|
|
if (randomize_xz) {
|
|
|
|
d0 += ps->range(-1, 1);
|
|
|
|
d1 += ps->range(-1, 1);
|
|
|
|
}
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2016-05-11 06:00:05 +02:00
|
|
|
bool flat_cave_floor = !large_cave && ps->range(0, 2) == 2;
|
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
for (s16 z0 = d0; z0 <= d1; z0++) {
|
|
|
|
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
|
|
|
|
for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
|
|
|
|
s16 maxabsxz = MYMAX(abs(x0), abs(z0));
|
2015-03-04 11:14:07 +01:00
|
|
|
|
2015-07-18 21:37:04 +02:00
|
|
|
s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
|
2015-03-04 11:14:07 +01:00
|
|
|
|
2014-12-06 10:18:04 +01:00
|
|
|
for (s16 y0 = -si2; y0 <= si2; y0++) {
|
2016-05-11 06:00:05 +02:00
|
|
|
// Make better floors in small caves
|
|
|
|
if (flat_cave_floor && y0 <= -rs / 2 && rs <= 7)
|
|
|
|
continue;
|
|
|
|
|
2013-04-21 06:11:05 +02:00
|
|
|
if (large_cave_is_flat) {
|
|
|
|
// Make large caves not so tall
|
|
|
|
if (rs > 7 && abs(y0) >= rs / 3)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
|
|
|
|
p += of;
|
|
|
|
|
2017-08-16 08:26:04 +02:00
|
|
|
if (!vm->m_area.contains(p))
|
2013-04-21 06:11:05 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
u32 i = vm->m_area.index(p);
|
2013-11-30 02:54:04 +01:00
|
|
|
content_t c = vm->m_data[i].getContent();
|
2015-04-06 23:52:08 +02:00
|
|
|
if (!ndef->get(c).is_ground_content)
|
2013-11-30 02:54:04 +01:00
|
|
|
continue;
|
2013-04-21 06:11:05 +02:00
|
|
|
|
2016-05-11 06:00:05 +02:00
|
|
|
if (large_cave) {
|
|
|
|
int full_ymin = node_min.Y - MAP_BLOCKSIZE;
|
|
|
|
int full_ymax = node_max.Y + MAP_BLOCKSIZE;
|
|
|
|
|
|
|
|
if (flooded && full_ymin < water_level && full_ymax > water_level)
|
|
|
|
vm->m_data[i] = (p.Y <= water_level) ? waternode : airnode;
|
|
|
|
else if (flooded && full_ymax < water_level)
|
|
|
|
vm->m_data[i] = (p.Y < startp.Y - 4) ? liquidnode : airnode;
|
|
|
|
else
|
|
|
|
vm->m_data[i] = airnode;
|
|
|
|
} else {
|
|
|
|
if (c == CONTENT_IGNORE)
|
|
|
|
continue;
|
2013-04-21 06:11:05 +02:00
|
|
|
|
|
|
|
vm->m_data[i] = airnode;
|
2016-05-11 06:00:05 +02:00
|
|
|
vm->m_flags[i] |= VMANIP_FLAG_CAVE;
|
|
|
|
}
|
2013-04-21 06:11:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-28 04:40:52 +02:00
|
|
|
|
|
|
|
|
2016-05-10 19:35:39 +02:00
|
|
|
inline bool CavesRandomWalk::isPosAboveSurface(v3s16 p)
|
|
|
|
{
|
|
|
|
if (heightmap != NULL &&
|
|
|
|
p.Z >= node_min.Z && p.Z <= node_max.Z &&
|
|
|
|
p.X >= node_min.X && p.X <= node_max.X) {
|
|
|
|
u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
|
|
|
|
if (heightmap[index] < p.Y)
|
|
|
|
return true;
|
|
|
|
} else if (p.Y > water_level) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 06:10:59 +02:00
|
|
|
////
|
|
|
|
//// CavesV6
|
|
|
|
////
|
2013-04-28 04:40:52 +02:00
|
|
|
|
2018-02-10 21:04:16 +01:00
|
|
|
CavesV6::CavesV6(const NodeDefManager *ndef, GenerateNotifier *gennotify,
|
2016-05-10 19:21:13 +02:00
|
|
|
int water_level, content_t water_source, content_t lava_source)
|
2015-08-03 05:34:11 +02:00
|
|
|
{
|
2016-05-10 19:21:13 +02:00
|
|
|
assert(ndef);
|
|
|
|
|
|
|
|
this->ndef = ndef;
|
|
|
|
this->gennotify = gennotify;
|
|
|
|
this->water_level = water_level;
|
|
|
|
|
|
|
|
c_water_source = water_source;
|
|
|
|
if (c_water_source == CONTENT_IGNORE)
|
|
|
|
c_water_source = ndef->getId("mapgen_water_source");
|
|
|
|
if (c_water_source == CONTENT_IGNORE)
|
|
|
|
c_water_source = CONTENT_AIR;
|
|
|
|
|
|
|
|
c_lava_source = lava_source;
|
|
|
|
if (c_lava_source == CONTENT_IGNORE)
|
|
|
|
c_lava_source = ndef->getId("mapgen_lava_source");
|
|
|
|
if (c_lava_source == CONTENT_IGNORE)
|
|
|
|
c_lava_source = CONTENT_AIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax,
|
|
|
|
PseudoRandom *ps, PseudoRandom *ps2,
|
|
|
|
bool is_large_cave, int max_stone_height, s16 *heightmap)
|
|
|
|
{
|
|
|
|
assert(vm);
|
|
|
|
assert(ps);
|
|
|
|
assert(ps2);
|
|
|
|
|
|
|
|
this->vm = vm;
|
|
|
|
this->ps = ps;
|
|
|
|
this->ps2 = ps2;
|
|
|
|
this->node_min = nmin;
|
|
|
|
this->node_max = nmax;
|
|
|
|
this->heightmap = heightmap;
|
|
|
|
this->large_cave = is_large_cave;
|
|
|
|
|
|
|
|
this->ystride = nmax.X - nmin.X + 1;
|
2013-04-28 04:40:52 +02:00
|
|
|
|
2016-05-10 19:21:13 +02:00
|
|
|
// Set initial parameters from randomness
|
2015-03-04 11:14:07 +01:00
|
|
|
min_tunnel_diameter = 2;
|
|
|
|
max_tunnel_diameter = ps->range(2, 6);
|
2016-05-15 04:46:50 +02:00
|
|
|
int dswitchint = ps->range(1, 14);
|
2013-04-28 04:40:52 +02:00
|
|
|
if (large_cave) {
|
2016-05-10 06:10:59 +02:00
|
|
|
part_max_length_rs = ps->range(2, 4);
|
|
|
|
tunnel_routepoints = ps->range(5, ps->range(15, 30));
|
2013-04-28 04:40:52 +02:00
|
|
|
min_tunnel_diameter = 5;
|
2016-05-10 06:10:59 +02:00
|
|
|
max_tunnel_diameter = ps->range(7, ps->range(8, 24));
|
2013-04-28 04:40:52 +02:00
|
|
|
} else {
|
2016-05-10 06:10:59 +02:00
|
|
|
part_max_length_rs = ps->range(2, 9);
|
|
|
|
tunnel_routepoints = ps->range(10, ps->range(15, 30));
|
2013-04-28 04:40:52 +02:00
|
|
|
}
|
2016-05-10 06:10:59 +02:00
|
|
|
large_cave_is_flat = (ps->range(0, 1) == 0);
|
2013-04-28 04:40:52 +02:00
|
|
|
|
|
|
|
main_direction = v3f(0, 0, 0);
|
|
|
|
|
|
|
|
// Allowed route area size in nodes
|
|
|
|
ar = node_max - node_min + v3s16(1, 1, 1);
|
|
|
|
// Area starting point in nodes
|
|
|
|
of = node_min;
|
|
|
|
|
|
|
|
// Allow a bit more
|
|
|
|
//(this should be more than the maximum radius of the tunnel)
|
2015-03-04 11:14:07 +01:00
|
|
|
const s16 max_spread_amount = MAP_BLOCKSIZE;
|
2016-05-15 04:46:50 +02:00
|
|
|
const s16 insure = 10;
|
2015-03-04 11:14:07 +01:00
|
|
|
s16 more = MYMAX(max_spread_amount - max_tunnel_diameter / 2 - insure, 1);
|
2016-05-10 06:10:59 +02:00
|
|
|
ar += v3s16(1, 0, 1) * more * 2;
|
|
|
|
of -= v3s16(1, 0, 1) * more;
|
2013-04-28 04:40:52 +02:00
|
|
|
|
|
|
|
route_y_min = 0;
|
|
|
|
// Allow half a diameter + 7 over stone surface
|
2016-05-10 19:21:13 +02:00
|
|
|
route_y_max = -of.Y + max_stone_height + max_tunnel_diameter / 2 + 7;
|
2013-04-28 04:40:52 +02:00
|
|
|
|
|
|
|
// Limit maximum to area
|
|
|
|
route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
|
|
|
|
|
|
|
|
if (large_cave) {
|
2016-05-10 06:10:59 +02:00
|
|
|
s16 minpos = 0;
|
2013-04-28 04:40:52 +02:00
|
|
|
if (node_min.Y < water_level && node_max.Y > water_level) {
|
2016-05-10 06:10:59 +02:00
|
|
|
minpos = water_level - max_tunnel_diameter / 3 - of.Y;
|
|
|
|
route_y_max = water_level + max_tunnel_diameter / 3 - of.Y;
|
2013-04-28 04:40:52 +02:00
|
|
|
}
|
2016-05-10 06:10:59 +02:00
|
|
|
route_y_min = ps->range(minpos, minpos + max_tunnel_diameter);
|
2013-04-28 04:40:52 +02:00
|
|
|
route_y_min = rangelim(route_y_min, 0, route_y_max);
|
|
|
|
}
|
|
|
|
|
|
|
|
s16 route_start_y_min = route_y_min;
|
|
|
|
s16 route_start_y_max = route_y_max;
|
|
|
|
|
2016-05-10 06:10:59 +02:00
|
|
|
route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1);
|
|
|
|
route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1);
|
2013-04-28 04:40:52 +02:00
|
|
|
|
|
|
|
// Randomize starting position
|
2016-05-15 04:46:50 +02:00
|
|
|
orp.Z = (float)(ps->next() % ar.Z) + 0.5f;
|
|
|
|
orp.Y = (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5f;
|
|
|
|
orp.X = (float)(ps->next() % ar.X) + 0.5f;
|
2013-04-28 04:40:52 +02:00
|
|
|
|
2014-12-06 10:18:04 +01:00
|
|
|
// Add generation notify begin event
|
2016-05-10 19:21:13 +02:00
|
|
|
if (gennotify != NULL) {
|
|
|
|
v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
|
|
|
|
GenNotifyType notifytype = large_cave ?
|
|
|
|
GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN;
|
|
|
|
gennotify->addEvent(notifytype, abs_pos);
|
|
|
|
}
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
// Generate some tunnel starting from orp
|
|
|
|
for (u16 j = 0; j < tunnel_routepoints; j++)
|
|
|
|
makeTunnel(j % dswitchint == 0);
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2014-12-06 10:18:04 +01:00
|
|
|
// Add generation notify end event
|
2016-05-10 19:21:13 +02:00
|
|
|
if (gennotify != NULL) {
|
2016-05-11 04:56:03 +02:00
|
|
|
v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
|
2016-05-10 19:21:13 +02:00
|
|
|
GenNotifyType notifytype = large_cave ?
|
|
|
|
GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END;
|
|
|
|
gennotify->addEvent(notifytype, abs_pos);
|
|
|
|
}
|
2013-04-28 04:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 06:10:59 +02:00
|
|
|
void CavesV6::makeTunnel(bool dirswitch)
|
2015-08-03 05:34:11 +02:00
|
|
|
{
|
2013-04-28 04:40:52 +02:00
|
|
|
if (dirswitch && !large_cave) {
|
2016-05-11 09:47:45 +02:00
|
|
|
main_direction.Z = ((float)(ps->next() % 20) - (float)10) / 10;
|
|
|
|
main_direction.Y = ((float)(ps->next() % 20) - (float)10) / 30;
|
|
|
|
main_direction.X = ((float)(ps->next() % 20) - (float)10) / 10;
|
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
main_direction *= (float)ps->range(0, 10) / 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Randomize size
|
|
|
|
s16 min_d = min_tunnel_diameter;
|
|
|
|
s16 max_d = max_tunnel_diameter;
|
|
|
|
rs = ps->range(min_d, max_d);
|
2015-03-04 11:14:07 +01:00
|
|
|
s16 rs_part_max_length_rs = rs * part_max_length_rs;
|
2013-04-28 04:40:52 +02:00
|
|
|
|
|
|
|
v3s16 maxlen;
|
|
|
|
if (large_cave) {
|
|
|
|
maxlen = v3s16(
|
2015-03-04 11:14:07 +01:00
|
|
|
rs_part_max_length_rs,
|
|
|
|
rs_part_max_length_rs / 2,
|
|
|
|
rs_part_max_length_rs
|
2013-04-28 04:40:52 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
maxlen = v3s16(
|
2015-03-04 11:14:07 +01:00
|
|
|
rs_part_max_length_rs,
|
|
|
|
ps->range(1, rs_part_max_length_rs),
|
|
|
|
rs_part_max_length_rs
|
2013-04-28 04:40:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-11 09:47:45 +02:00
|
|
|
v3f vec;
|
|
|
|
vec.Z = (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2;
|
|
|
|
vec.Y = (float)(ps->next() % maxlen.Y) - (float)maxlen.Y / 2;
|
|
|
|
vec.X = (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2;
|
2015-03-04 11:14:07 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
// Jump downward sometimes
|
|
|
|
if (!large_cave && ps->range(0, 12) == 0) {
|
2016-05-11 09:47:45 +02:00
|
|
|
vec.Z = (float)(ps->next() % maxlen.Z) - (float)maxlen.Z / 2;
|
|
|
|
vec.Y = (float)(ps->next() % (maxlen.Y * 2)) - (float)maxlen.Y;
|
|
|
|
vec.X = (float)(ps->next() % maxlen.X) - (float)maxlen.X / 2;
|
2013-04-28 04:40:52 +02:00
|
|
|
}
|
|
|
|
|
2016-05-10 19:35:39 +02:00
|
|
|
// Do not make caves that are entirely above ground, to fix shadow bugs
|
|
|
|
// caused by overgenerated large caves.
|
2013-04-28 04:40:52 +02:00
|
|
|
// It is only necessary to check the startpoint and endpoint.
|
2016-05-10 19:35:39 +02:00
|
|
|
v3s16 p1 = v3s16(orp.X, orp.Y, orp.Z) + of + rs / 2;
|
|
|
|
v3s16 p2 = v3s16(vec.X, vec.Y, vec.Z) + p1;
|
2013-04-28 04:40:52 +02:00
|
|
|
|
2016-05-10 19:35:39 +02:00
|
|
|
// If startpoint and endpoint are above ground, disable placement of nodes
|
|
|
|
// in carveRoute while still running all PseudoRandom calls to ensure caves
|
|
|
|
// are consistent with existing worlds.
|
|
|
|
bool tunnel_above_ground =
|
|
|
|
p1.Y > getSurfaceFromHeightmap(p1) &&
|
|
|
|
p2.Y > getSurfaceFromHeightmap(p2);
|
2015-07-18 21:37:04 +02:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
vec += main_direction;
|
|
|
|
|
|
|
|
v3f rp = orp + vec;
|
|
|
|
if (rp.X < 0)
|
|
|
|
rp.X = 0;
|
|
|
|
else if (rp.X >= ar.X)
|
|
|
|
rp.X = ar.X - 1;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
if (rp.Y < route_y_min)
|
|
|
|
rp.Y = route_y_min;
|
|
|
|
else if (rp.Y >= route_y_max)
|
|
|
|
rp.Y = route_y_max - 1;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
if (rp.Z < 0)
|
|
|
|
rp.Z = 0;
|
|
|
|
else if (rp.Z >= ar.Z)
|
|
|
|
rp.Z = ar.Z - 1;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
vec = rp - orp;
|
|
|
|
|
|
|
|
float veclen = vec.getLength();
|
2015-03-04 11:14:07 +01:00
|
|
|
// As odd as it sounds, veclen is *exactly* 0.0 sometimes, causing a FPE
|
2016-05-15 04:46:50 +02:00
|
|
|
if (veclen < 0.05f)
|
|
|
|
veclen = 1.0f;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
// Every second section is rough
|
2015-03-04 11:14:07 +01:00
|
|
|
bool randomize_xz = (ps2->range(1, 2) == 1);
|
2013-04-28 04:40:52 +02:00
|
|
|
|
|
|
|
// Carve routes
|
2016-05-15 04:46:50 +02:00
|
|
|
for (float f = 0.f; f < 1.0f; f += 1.0f / veclen)
|
2015-08-03 05:34:11 +02:00
|
|
|
carveRoute(vec, f, randomize_xz, tunnel_above_ground);
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
orp = rp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 06:10:59 +02:00
|
|
|
void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz,
|
|
|
|
bool tunnel_above_ground)
|
2015-08-03 05:34:11 +02:00
|
|
|
{
|
2013-04-28 04:40:52 +02:00
|
|
|
MapNode airnode(CONTENT_AIR);
|
|
|
|
MapNode waternode(c_water_source);
|
|
|
|
MapNode lavanode(c_lava_source);
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
v3s16 startp(orp.X, orp.Y, orp.Z);
|
|
|
|
startp += of;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
v3f fp = orp + vec * f;
|
2016-05-15 04:46:50 +02:00
|
|
|
fp.X += 0.1f * ps->range(-10, 10);
|
|
|
|
fp.Z += 0.1f * ps->range(-10, 10);
|
2013-04-28 04:40:52 +02:00
|
|
|
v3s16 cp(fp.X, fp.Y, fp.Z);
|
|
|
|
|
2016-05-10 19:21:13 +02:00
|
|
|
s16 d0 = -rs / 2;
|
2013-04-28 04:40:52 +02:00
|
|
|
s16 d1 = d0 + rs;
|
|
|
|
if (randomize_xz) {
|
|
|
|
d0 += ps->range(-1, 1);
|
|
|
|
d1 += ps->range(-1, 1);
|
|
|
|
}
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
for (s16 z0 = d0; z0 <= d1; z0++) {
|
|
|
|
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
|
|
|
|
for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
|
2015-08-03 05:34:11 +02:00
|
|
|
if (tunnel_above_ground)
|
|
|
|
continue;
|
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
s16 maxabsxz = MYMAX(abs(x0), abs(z0));
|
2015-03-04 11:14:07 +01:00
|
|
|
s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
|
2013-04-28 04:40:52 +02:00
|
|
|
for (s16 y0 = -si2; y0 <= si2; y0++) {
|
|
|
|
if (large_cave_is_flat) {
|
|
|
|
// Make large caves not so tall
|
|
|
|
if (rs > 7 && abs(y0) >= rs / 3)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
|
|
|
|
p += of;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2017-08-16 08:26:04 +02:00
|
|
|
if (!vm->m_area.contains(p))
|
2013-04-28 04:40:52 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
u32 i = vm->m_area.index(p);
|
|
|
|
content_t c = vm->m_data[i].getContent();
|
2015-03-04 11:14:07 +01:00
|
|
|
if (!ndef->get(c).is_ground_content)
|
2013-04-28 04:40:52 +02:00
|
|
|
continue;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
if (large_cave) {
|
|
|
|
int full_ymin = node_min.Y - MAP_BLOCKSIZE;
|
|
|
|
int full_ymax = node_max.Y + MAP_BLOCKSIZE;
|
|
|
|
|
2016-05-10 06:10:59 +02:00
|
|
|
if (full_ymin < water_level && full_ymax > water_level) {
|
2016-05-10 19:21:13 +02:00
|
|
|
vm->m_data[i] = (p.Y <= water_level) ? waternode : airnode;
|
2016-05-10 06:10:59 +02:00
|
|
|
} else if (full_ymax < water_level) {
|
2016-05-10 19:21:13 +02:00
|
|
|
vm->m_data[i] = (p.Y < startp.Y - 2) ? lavanode : airnode;
|
2015-03-04 11:14:07 +01:00
|
|
|
} else {
|
2013-04-28 04:40:52 +02:00
|
|
|
vm->m_data[i] = airnode;
|
2015-03-04 11:14:07 +01:00
|
|
|
}
|
2013-04-28 04:40:52 +02:00
|
|
|
} else {
|
2015-04-06 23:52:08 +02:00
|
|
|
if (c == CONTENT_IGNORE || c == CONTENT_AIR)
|
2013-07-06 08:21:35 +02:00
|
|
|
continue;
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2013-04-28 04:40:52 +02:00
|
|
|
vm->m_data[i] = airnode;
|
|
|
|
vm->m_flags[i] |= VMANIP_FLAG_CAVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 19:35:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
inline s16 CavesV6::getSurfaceFromHeightmap(v3s16 p)
|
|
|
|
{
|
|
|
|
if (heightmap != NULL &&
|
|
|
|
p.Z >= node_min.Z && p.Z <= node_max.Z &&
|
|
|
|
p.X >= node_min.X && p.X <= node_max.X) {
|
|
|
|
u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
|
|
|
|
return heightmap[index];
|
|
|
|
}
|
2017-08-16 08:26:04 +02:00
|
|
|
|
|
|
|
return water_level;
|
|
|
|
|
2016-05-10 19:35:39 +02:00
|
|
|
}
|