diff --git a/res/content/base/generators/demo.files/script.lua b/res/content/base/generators/demo.files/script.lua index cd443163..7c103090 100644 --- a/res/content/base/generators/demo.files/script.lua +++ b/res/content/base/generators/demo.files/script.lua @@ -1,3 +1,13 @@ +-- Get entry-point and filename from `entry-point:filename` path +-- // TODO: move to stdmin +function parse_path(path) + local index = string.find(path, ':') + if index == nil then + error("invalid path syntax (':' missing)") + end + return string.sub(path, 1, index-1), string.sub(path, index+1, -1) +end + local _, dir = parse_path(__DIR__) ores = file.read_combined_list(dir.."/ores.json") @@ -26,6 +36,17 @@ end function place_structures(x, z, w, d, seed, hmap, chunk_height) local placements = {} place_ores(placements, x, z, w, d, seed, hmap, chunk_height) + + if math.random() < 0.1 then -- generate caves + local sy = math.random() * (chunk_height / 2) + local ey = math.random() * (chunk_height / 2) + local sx = x + math.random() * 20 - 10 + local ex = x + math.random() * 20 - 10 + local sz = z + math.random() * 20 - 10 + local ez = z + math.random() * 20 - 10 + table.insert(placements, + {":line", 0, {sx - 10, sy, sz - 10}, {ex + 10, ey, ez + 10}, 3}) + end return placements end diff --git a/res/generators/default.files/script.lua b/res/generators/default.files/script.lua deleted file mode 100644 index 1bec4cab..00000000 --- a/res/generators/default.files/script.lua +++ /dev/null @@ -1,23 +0,0 @@ --- TODO: delete this file after caves complete implementation - -function generate_heightmap(x, y, w, h, seed, s) - local map = Heightmap(w, h) - map:add(0.25) - return map -end - - -function place_structures(x, z, w, d, seed, hmap, chunk_height) - local placements = {} - do - local sy = math.random() * (chunk_height / 4) - local ey = math.random() * (chunk_height / 4) - local sx = x + math.random() * 20 - 10 - local ex = x + math.random() * 20 - 10 - local sz = z + math.random() * 20 - 10 - local ez = z + math.random() * 20 - 10 - table.insert(placements, - {":line", 0, {sx - 10, sy, sz - 10}, {ex + 10, ey, ez + 10}, 3}) - end - return placements -end diff --git a/src/world/generator/WorldGenerator.cpp b/src/world/generator/WorldGenerator.cpp index b29914c7..daf22ece 100644 --- a/src/world/generator/WorldGenerator.cpp +++ b/src/world/generator/WorldGenerator.cpp @@ -341,7 +341,13 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) { } } } + generateLines(prototype, voxels, chunkX, chunkZ); + generateStructures(prototype, voxels, chunkX, chunkZ); +} +void WorldGenerator::generateStructures( + const ChunkPrototype& prototype, voxel* voxels, int chunkX, int chunkZ +) { for (const auto& placement : prototype.structures) { if (placement.structure < 0 || placement.structure >= def.structures.size()) { logger.error() << "invalid structure index " << placement.structure; @@ -380,7 +386,6 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) { } } } - generateLines(prototype, voxels, chunkX, chunkZ); } void WorldGenerator::generateLines( diff --git a/src/world/generator/WorldGenerator.hpp b/src/world/generator/WorldGenerator.hpp index 784b4329..e40ce92f 100644 --- a/src/world/generator/WorldGenerator.hpp +++ b/src/world/generator/WorldGenerator.hpp @@ -80,6 +80,9 @@ class WorldGenerator { void generateLines( const ChunkPrototype& prototype, voxel* voxels, int x, int z ); + void generateStructures( + const ChunkPrototype& prototype, voxel* voxels, int x, int z + ); public: WorldGenerator( const GeneratorDef& def,