Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit 357c8453be32c5e6261c6a5a8946907ae024fd86
- Author: kwolekr <kwolekr@minetest.net>
- Date: Wed Mar 27 15:08:34 2013 -0400
- Vary ore density by height
- diff --git a/src/mapgen.cpp b/src/mapgen.cpp
- index b5deaae..20e8a89 100644
- --- a/src/mapgen.cpp
- +++ b/src/mapgen.cpp
- @@ -86,6 +86,20 @@ void Ore::resolveNodeNames(INodeDefManager *ndef) {
- }
- +s16 Ore::getScarcity(s16 y) {
- + s16 smin = clust_scarcity_min;
- + s16 smax = clust_scarcity_max;
- + s16 sramp = clust_scarcity_ramp;
- +
- + if (y <= sramp)
- + return smin;
- +
- + float factor = (float)(sramp - y) / (float)(sramp - height_max);
- + s16 scarcity = smin + factor * (smax - smin);
- + return scarcity;
- +}
- +
- +
- void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
- if (nmin.Y > height_max || nmax.Y < height_min)
- return;
- @@ -106,8 +120,8 @@ void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
- (nmax.Z - nmin.Z + 1);
- int csize = clust_size;
- int orechance = (csize * csize * csize) / clust_num_ores;
- - int nclusters = volume / clust_scarcity;
- -
- + int nclusters = volume / getScarcity(nmin.Y);
- +
- for (int i = 0; i != nclusters; i++) {
- int x0 = pr.range(nmin.X, nmax.X - csize + 1);
- int y0 = pr.range(ymin, ymax - csize + 1);
- diff --git a/src/mapgen.h b/src/mapgen.h
- index a900985..31aef8c 100644
- --- a/src/mapgen.h
- +++ b/src/mapgen.h
- @@ -110,7 +110,9 @@ class Ore {
- content_t ore;
- content_t wherein; // the node to be replaced
- - s16 clust_scarcity; //
- + s16 clust_scarcity_min;
- + s16 clust_scarcity_ramp;
- + s16 clust_scarcity_max;
- s16 clust_num_ores; // how many ore nodes are in a chunk
- s16 clust_size; // how large (in nodes) a chunk of ore is
- s16 height_min;
- @@ -127,6 +129,7 @@ class Ore {
- }
- void resolveNodeNames(INodeDefManager *ndef);
- + s16 getScarcity(s16 y);
- virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
- };
- diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
- index 80abffa..5f213d8 100644
- --- a/src/scriptapi.cpp
- +++ b/src/scriptapi.cpp
- @@ -712,7 +712,9 @@ static int l_register_ore(lua_State *L)
- ore->ore_name = getstringfield_default(L, index, "ore", "");
- ore->wherein_name = getstringfield_default(L, index, "wherein", "");
- - ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
- + ore->clust_scarcity_min = getintfield_default(L, index, "clust_scarcity_min", 100);
- + ore->clust_scarcity_ramp = getintfield_default(L, index, "clust_scarcity_ramp", 0);
- + ore->clust_scarcity_max = getintfield_default(L, index, "clust_scarcity_max", 100);
- ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);
- ore->clust_size = getintfield_default(L, index, "clust_size", 0);
- ore->height_min = getintfield_default(L, index, "height_min", 0);
- @@ -725,7 +727,7 @@ static int l_register_ore(lua_State *L)
- ore->noise = NULL;
- - if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) {
- + if (ore->clust_num_ores <= 0) {
- errorstream << "register_ore: clust_scarcity and clust_num_ores"
- "must be greater than 0";
- delete ore;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement