Skip to content
Permalink
Browse files

Biome API: Add shore top and shore filler nodes, underwater node, wat…

…er top node. Add water top depth and shore height parameters. Remove water dust node
  • Loading branch information
paramat authored and kwolekr committed Dec 29, 2014
1 parent 61dfa91 commit 570c2042b1b11fc1581dceb22c74cf47bb217134
Showing with 91 additions and 62 deletions.
  1. +24 −18 src/mapgen_v5.cpp
  2. +23 −18 src/mapgen_v7.cpp
  3. +19 −11 src/mg_biome.cpp
  4. +6 −1 src/mg_biome.h
  5. +19 −14 src/script/lua_api/l_mapgen.cpp
@@ -417,10 +417,12 @@ void MapgenV5::generateBiomes() {

for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
s16 y0_top = biome->depth_top;
s16 y0_filler = biome->depth_top + dfiller;
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
s16 y0_top = biome->depth_top;
s16 y0_filler = biome->depth_top + dfiller;
s16 shore_max = water_level + biome->height_shore;
s16 depth_water_top = biome->depth_water_top;

s16 nplaced = 0;
u32 i = vm->m_area.index(x, node_max.Y, z);
@@ -439,15 +441,20 @@ void MapgenV5::generateBiomes() {

if (c_below != CONTENT_AIR) {
if (nplaced < y0_top) {
// A hack to prevent dirt_with_grass from being
// placed below water. TODO: fix later
content_t c_place = ((y < water_level) &&
(biome->c_top == c_dirt_with_grass)) ?
c_dirt : biome->c_top;
vm->m_data[i] = MapNode(c_place);
if(y < water_level)
vm->m_data[i] = MapNode(biome->c_underwater);
else if(y <= shore_max)
vm->m_data[i] = MapNode(biome->c_shore_top);
else
vm->m_data[i] = MapNode(biome->c_top);
nplaced++;
} else if (nplaced < y0_filler && nplaced >= y0_top) {
vm->m_data[i] = MapNode(biome->c_filler);
if(y < water_level)
vm->m_data[i] = MapNode(biome->c_underwater);
else if(y <= shore_max)
vm->m_data[i] = MapNode(biome->c_shore_filler);
else
vm->m_data[i] = MapNode(biome->c_filler);
nplaced++;
} else if (c == c_stone) {
have_air = false;
@@ -469,7 +476,10 @@ void MapgenV5::generateBiomes() {
} else if (c == c_water_source) {
have_air = true;
nplaced = 0;
vm->m_data[i] = MapNode(biome->c_water);
if(y > water_level - depth_water_top)
vm->m_data[i] = MapNode(biome->c_water_top);
else
vm->m_data[i] = MapNode(biome->c_water);
} else if (c == CONTENT_AIR) {
have_air = true;
nplaced = 0;
@@ -480,6 +490,7 @@ void MapgenV5::generateBiomes() {
}
}


void MapgenV5::dustTopNodes() {
v3s16 em = vm->m_area.getExtent();
u32 index = 0;
@@ -504,12 +515,7 @@ void MapgenV5::dustTopNodes() {
}

content_t c = vm->m_data[vi].getContent();
if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) {
if (y < node_min.Y - 1)
continue;

vm->m_data[vi] = MapNode(biome->c_dust_water);
} else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE
if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE
&& c != biome->c_dust) {
if (y == node_max.Y + 1)
continue;
@@ -516,10 +516,12 @@ void MapgenV7::generateBiomes() {

for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
s16 y0_top = biome->depth_top;
s16 y0_filler = biome->depth_top + dfiller;
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
s16 y0_top = biome->depth_top;
s16 y0_filler = biome->depth_top + dfiller;
s16 shore_max = water_level + biome->height_shore;
s16 depth_water_top = biome->depth_water_top;

s16 nplaced = 0;
u32 i = vm->m_area.index(x, node_max.Y, z);
@@ -545,15 +547,20 @@ void MapgenV7::generateBiomes() {

if (c_below != CONTENT_AIR) {
if (nplaced < y0_top) {
// A hack to prevent dirt_with_grass from being
// placed below water. TODO: fix later
content_t c_place = ((y < water_level) &&
(biome->c_top == c_dirt_with_grass)) ?
c_dirt : biome->c_top;
vm->m_data[i] = MapNode(c_place);
if(y < water_level)
vm->m_data[i] = MapNode(biome->c_underwater);
else if(y <= shore_max)
vm->m_data[i] = MapNode(biome->c_shore_top);
else
vm->m_data[i] = MapNode(biome->c_top);
nplaced++;
} else if (nplaced < y0_filler && nplaced >= y0_top) {
vm->m_data[i] = MapNode(biome->c_filler);
if(y < water_level)
vm->m_data[i] = MapNode(biome->c_underwater);
else if(y <= shore_max)
vm->m_data[i] = MapNode(biome->c_shore_filler);
else
vm->m_data[i] = MapNode(biome->c_filler);
nplaced++;
} else if (c == c_stone) {
have_air = false;
@@ -575,7 +582,10 @@ void MapgenV7::generateBiomes() {
} else if (c == c_water_source) {
have_air = true;
nplaced = 0;
vm->m_data[i] = MapNode(biome->c_water);
if(y > water_level - depth_water_top)
vm->m_data[i] = MapNode(biome->c_water_top);
else
vm->m_data[i] = MapNode(biome->c_water);
} else if (c == CONTENT_AIR) {
have_air = true;
nplaced = 0;
@@ -611,12 +621,7 @@ void MapgenV7::dustTopNodes() {
}

content_t c = vm->m_data[vi].getContent();
if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) {
if (y < node_min.Y)
continue;

vm->m_data[vi] = MapNode(biome->c_dust_water);
} else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
if (y == node_max.Y)
continue;

@@ -38,23 +38,28 @@ BiomeManager::BiomeManager(IGameDef *gamedef) :
// Create default biome to be used in case none exist
Biome *b = new Biome;

b->id = 0;
b->name = "Default";
b->flags = 0;
b->depth_top = 0;
b->depth_filler = 0;
b->height_min = -MAP_GENERATION_LIMIT;
b->height_max = MAP_GENERATION_LIMIT;
b->heat_point = 0.0;
b->humidity_point = 0.0;
b->id = 0;
b->name = "Default";
b->flags = 0;
b->depth_top = 0;
b->depth_filler = 0;
b->height_shore = 0;
b->depth_water_top = 0;
b->height_min = -MAP_GENERATION_LIMIT;
b->height_max = MAP_GENERATION_LIMIT;
b->heat_point = 0.0;
b->humidity_point = 0.0;

NodeResolveInfo *nri = new NodeResolveInfo(b);
nri->nodenames.push_back("air");
nri->nodenames.push_back("air");
nri->nodenames.push_back("air");
nri->nodenames.push_back("air");
nri->nodenames.push_back("air");
nri->nodenames.push_back("mapgen_stone");
nri->nodenames.push_back("mapgen_water_source");
nri->nodenames.push_back("air");
nri->nodenames.push_back("mapgen_water_source");
nri->nodenames.push_back("air");
m_ndef->pendNodeResolve(nri);

add(b);
@@ -121,9 +126,12 @@ void Biome::resolveNodeNames(NodeResolveInfo *nri)
{
m_ndef->getIdFromResolveInfo(nri, "mapgen_dirt_with_grass", CONTENT_AIR, c_top);
m_ndef->getIdFromResolveInfo(nri, "mapgen_dirt", CONTENT_AIR, c_filler);
m_ndef->getIdFromResolveInfo(nri, "mapgen_sand", CONTENT_AIR, c_shore_top);
m_ndef->getIdFromResolveInfo(nri, "mapgen_sand", CONTENT_AIR, c_shore_filler);
m_ndef->getIdFromResolveInfo(nri, "mapgen_sand", CONTENT_AIR, c_underwater);
m_ndef->getIdFromResolveInfo(nri, "mapgen_stone", CONTENT_AIR, c_stone);
m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source", CONTENT_AIR, c_water_top);
m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source", CONTENT_AIR, c_water);
m_ndef->getIdFromResolveInfo(nri, "air", CONTENT_IGNORE, c_dust);
m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source", CONTENT_IGNORE, c_dust_water);
}

@@ -39,13 +39,18 @@ class Biome : public GenElement, public NodeResolver {

content_t c_top;
content_t c_filler;
content_t c_shore_top;
content_t c_shore_filler;
content_t c_underwater;
content_t c_stone;
content_t c_water_top;
content_t c_water;
content_t c_dust;
content_t c_dust_water;

s16 depth_top;
s16 depth_filler;
s16 height_shore;
s16 depth_water_top;

s16 height_min;
s16 height_max;
@@ -422,14 +422,16 @@ int ModApiMapgen::l_register_biome(lua_State *L)
es_BiomeTerrainType, BIOME_TYPE_NORMAL);
Biome *b = bmgr->create(biometype);

b->name = getstringfield_default(L, index, "name", "");
b->depth_top = getintfield_default(L, index, "depth_top", 1);
b->depth_filler = getintfield_default(L, index, "depth_filler", 3);
b->height_min = getintfield_default(L, index, "height_min", 0);
b->height_max = getintfield_default(L, index, "height_max", 0);
b->heat_point = getfloatfield_default(L, index, "heat_point", 0.);
b->humidity_point = getfloatfield_default(L, index, "humidity_point", 0.);
b->flags = 0; //reserved
b->name = getstringfield_default(L, index, "name", "");
b->depth_top = getintfield_default(L, index, "depth_top", 1);
b->depth_filler = getintfield_default(L, index, "depth_filler", 3);
b->height_shore = getintfield_default(L, index, "height_shore", 3);
b->depth_water_top = getintfield_default(L, index, "depth_water_top", 0);
b->height_min = getintfield_default(L, index, "height_min", 0);
b->height_max = getintfield_default(L, index, "height_max", 0);
b->heat_point = getfloatfield_default(L, index, "heat_point", 0.);
b->humidity_point = getfloatfield_default(L, index, "humidity_point", 0.);
b->flags = 0; //reserved

u32 id = bmgr->add(b);
if (id == (u32)-1) {
@@ -439,12 +441,15 @@ int ModApiMapgen::l_register_biome(lua_State *L)

NodeResolveInfo *nri = new NodeResolveInfo(b);
std::list<std::string> &nnames = nri->nodenames;
nnames.push_back(getstringfield_default(L, index, "node_top", ""));
nnames.push_back(getstringfield_default(L, index, "node_filler", ""));
nnames.push_back(getstringfield_default(L, index, "node_stone", ""));
nnames.push_back(getstringfield_default(L, index, "node_water", ""));
nnames.push_back(getstringfield_default(L, index, "node_dust", ""));
nnames.push_back(getstringfield_default(L, index, "node_dust_water", ""));
nnames.push_back(getstringfield_default(L, index, "node_top", ""));
nnames.push_back(getstringfield_default(L, index, "node_filler", ""));
nnames.push_back(getstringfield_default(L, index, "node_shore_top", ""));
nnames.push_back(getstringfield_default(L, index, "node_shore_filler", ""));
nnames.push_back(getstringfield_default(L, index, "node_underwater", ""));
nnames.push_back(getstringfield_default(L, index, "node_stone", ""));
nnames.push_back(getstringfield_default(L, index, "node_water_top", ""));
nnames.push_back(getstringfield_default(L, index, "node_water", ""));
nnames.push_back(getstringfield_default(L, index, "node_dust", ""));
ndef->pendNodeResolve(nri);

verbosestream << "register_biome: " << b->name << std::endl;

0 comments on commit 570c204

Please sign in to comment.
You can’t perform that action at this time.