]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Biome API: Add shore top and shore filler nodes, underwater node, water top node...
authorparamat <mat.gregory@virginmedia.com>
Sun, 28 Dec 2014 05:20:42 +0000 (05:20 +0000)
committerkwolekr <kwolekr@minetest.net>
Mon, 29 Dec 2014 02:37:43 +0000 (21:37 -0500)
src/mapgen_v5.cpp
src/mapgen_v7.cpp
src/mg_biome.cpp
src/mg_biome.h
src/script/lua_api/l_mapgen.cpp

index 9723c987b0ccabf10fb36c36827757fb855e63bf..a7d9698d5d945906e1a58e7713f9b93a02b0c650 100644 (file)
@@ -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;
index 2f55964d815dbf8cdcc5221226901e94bb41b435..06a47971ef7cf50fa9f776893dbfc521a92b35e5 100644 (file)
@@ -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;
 
index 763bef1bc5df94cbb6e424896eb1c748011ec94f..0492980ee2dc564284c48a7a4e865269da95a182 100644 (file)
@@ -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);
 }
 
index 870c1196113acc64eafd8149e338e891d89cadf9..f5a5deae3b69d2d1f108fc38f01d15b075ec008e 100644 (file)
@@ -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;
index c0a58305b05ff820821bf97723276970816b4779..a2e5d31d14f9c2770a809254b30ecc616954f904 100644 (file)
@@ -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;