Decoration API: Add flag for placement on liquid surface
authorparamat <mat.gregory@virginmedia.com>
Wed, 21 Oct 2015 07:51:59 +0000 (08:51 +0100)
committerparamat <mat.gregory@virginmedia.com>
Fri, 23 Oct 2015 20:30:20 +0000 (21:30 +0100)
Add findLiquidSurface() function to mapgen.cpp
Update lua_api.txt

doc/lua_api.txt
src/mapgen.cpp
src/mapgen.h
src/mg_decoration.cpp
src/mg_decoration.h

index 0339345ba6416394f8f6bc637bd910339b08d71f..52da2d0957896162d3d73a4c2f3d7a8fe64079ca 100644 (file)
@@ -801,15 +801,13 @@ Decoration types
 ----------------
 The varying types of decorations that can be placed.
 
-The default value is `simple`, and is currently the only type supported.
-
 ### `simple`
 Creates a 1 times `H` times 1 column of a specified node (or a random node from
 a list, if a decoration list is specified). Can specify a certain node it must
 spawn next to, such as water or lava, for example. Can also generate a
 decoration of random height between a specified lower and upper bound.
 This type of decoration is intended for placement of grass, flowers, cacti,
-papyri, and so on.
+papyri, waterlilies and so on.
 
 ### `schematic`
 Copies a box of `MapNodes` from a specified schematic file (or raw description).
@@ -848,8 +846,8 @@ Schematic attributes
 --------------------
 See section "Flag Specifier Format".
 
-Currently supported flags: `place_center_x`, `place_center_y`,
-                          `place_center_z`, `force_placement`.
+Currently supported flags: `place_center_x`, `place_center_y`, `place_center_z`,
+                           `force_placement`.
 
 * `place_center_x`: Placement of this decoration is centered along the X axis.
 * `place_center_y`: Placement of this decoration is centered along the Y axis.
@@ -3418,6 +3416,11 @@ Definition tables
     -- ^ Minimum and maximum `y` positions these decorations can be generated at.
     -- ^ This parameter refers to the `y` position of the decoration base, so
     --   the actual maximum height would be `height_max + size.Y`.
+        flags = "liquid_surface",
+    --  ^ Flags for all decoration types.
+    --  ^ "liquid_surface": Instead of placement on the highest solid surface
+    --  ^ in a mapchunk column, placement is on the highest liquid surface.
+    --  ^ Placement is disabled if solid nodes are found above the liquid surface.
 
         ----- Simple-type parameters
         decoration = "default:grass",
index f5046459e92a10b123b06061681b0f92e166c349..8a77000fae9010de1cb1c6905d0b93eae3942acf 100644 (file)
@@ -161,6 +161,26 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
 }
 
 
+// Returns -MAX_MAP_GENERATION_LIMIT if not found or if ground is found first
+s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
+{
+       v3s16 em = vm->m_area.getExtent();
+       u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
+       s16 y;
+
+       for (y = ymax; y >= ymin; y--) {
+               MapNode &n = vm->m_data[i];
+               if (ndef->get(n).walkable)
+                       return -MAX_MAP_GENERATION_LIMIT;
+               else if (ndef->get(n).isLiquid())
+                       break;
+
+               vm->m_area.add_y(em, i, -1);
+       }
+       return (y >= ymin) ? y : -MAX_MAP_GENERATION_LIMIT;
+}
+
+
 void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax)
 {
        if (!heightmap)
index 4b28ec9364529432003832967b4f059da2f4419b..0561ddf9840f94d2c15ff1ddcce39d484f26e706 100644 (file)
@@ -166,6 +166,7 @@ public:
        static u32 getBlockSeed2(v3s16 p, int seed);
        s16 findGroundLevelFull(v2s16 p2d);
        s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
+       s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
        void updateHeightmap(v3s16 nmin, v3s16 nmax);
        void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
 
index 4f543a7ddff120e1d24245cc4bc2db3070bd2c34..1e080fd6a48ad1d6dfb30e3ebd6ac452f39f50ab 100644 (file)
@@ -30,6 +30,7 @@ FlagDesc flagdesc_deco[] = {
        {"place_center_y", DECO_PLACE_CENTER_Y},
        {"place_center_z", DECO_PLACE_CENTER_Z},
        {"force_placement", DECO_FORCE_PLACEMENT},
+       {"liquid_surface", DECO_LIQUID_SURFACE},
        {NULL,             0}
 };
 
@@ -124,9 +125,13 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 
                        int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X);
 
-                       s16 y = mg->heightmap ?
-                                       mg->heightmap[mapindex] :
-                                       mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
+                       s16 y = -MAX_MAP_GENERATION_LIMIT;
+                       if (flags & DECO_LIQUID_SURFACE)
+                               y = mg->findLiquidSurface(v2s16(x, z), nmin.Y, nmax.Y);
+                       else if (mg->heightmap)
+                               y = mg->heightmap[mapindex];
+                       else
+                               y = mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
 
                        if (y < nmin.Y || y > nmax.Y ||
                                y < y_min  || y > y_max)
index c712ce7c8e5dfb672950457dda810804c9e19c30..16af02a1a478cd5ab840c8b0baa8d7c4b2cbbb80 100644 (file)
@@ -41,6 +41,7 @@ enum DecorationType {
 #define DECO_PLACE_CENTER_Z  0x04
 #define DECO_USE_NOISE       0x08
 #define DECO_FORCE_PLACEMENT 0x10
+#define DECO_LIQUID_SURFACE  0x20
 
 extern FlagDesc flagdesc_deco[];