diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mapgen.cpp | 20 | ||||
-rw-r--r-- | src/mapgen.h | 1 | ||||
-rw-r--r-- | src/mg_decoration.cpp | 11 | ||||
-rw-r--r-- | src/mg_decoration.h | 1 |
4 files changed, 30 insertions, 3 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp index f5046459e..8a77000fa 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -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) diff --git a/src/mapgen.h b/src/mapgen.h index 4b28ec936..0561ddf98 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -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); diff --git a/src/mg_decoration.cpp b/src/mg_decoration.cpp index 4f543a7dd..1e080fd6a 100644 --- a/src/mg_decoration.cpp +++ b/src/mg_decoration.cpp @@ -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) diff --git a/src/mg_decoration.h b/src/mg_decoration.h index c712ce7c8..16af02a1a 100644 --- a/src/mg_decoration.h +++ b/src/mg_decoration.h @@ -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[]; |