From 9b0d77a549e4c29c9c189ff2a454568fa9746c1e Mon Sep 17 00:00:00 2001
From: kwolekr <kwolekr@minetest.net>
Date: Tue, 30 Dec 2014 01:48:20 -0500
Subject: [PATCH] Replace instances of height_min/height_max with y_min/y_max
 to remove ambiguity

---
 src/mg_biome.cpp                |  6 +++---
 src/mg_biome.h                  |  4 ++--
 src/mg_decoration.cpp           |  4 ++--
 src/mg_decoration.h             |  4 ++--
 src/mg_ore.cpp                  | 20 ++++++++++----------
 src/mg_ore.h                    |  4 ++--
 src/script/lua_api/l_mapgen.cpp | 22 ++++++++++++++++------
 7 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/src/mg_biome.cpp b/src/mg_biome.cpp
index 0492980ee..0616d81a2 100644
--- a/src/mg_biome.cpp
+++ b/src/mg_biome.cpp
@@ -45,8 +45,8 @@ BiomeManager::BiomeManager(IGameDef *gamedef) :
 	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->y_min           = -MAP_GENERATION_LIMIT;
+	b->y_max           = MAP_GENERATION_LIMIT;
 	b->heat_point      = 0.0;
 	b->humidity_point  = 0.0;
 
@@ -91,7 +91,7 @@ Biome *BiomeManager::getBiome(float heat, float humidity, s16 y)
 
 	for (size_t i = 1; i < m_elements.size(); i++) {
 		b = (Biome *)m_elements[i];
-		if (!b || y > b->height_max || y < b->height_min)
+		if (!b || y > b->y_max || y < b->y_min)
 			continue;
 
 		float d_heat     = heat     - b->heat_point;
diff --git a/src/mg_biome.h b/src/mg_biome.h
index f5a5deae3..3577960a9 100644
--- a/src/mg_biome.h
+++ b/src/mg_biome.h
@@ -52,8 +52,8 @@ class Biome : public GenElement, public NodeResolver {
 	s16 height_shore;
 	s16 depth_water_top;
 
-	s16 height_min;
-	s16 height_max;
+	s16 y_min;
+	s16 y_max;
 	float heat_point;
 	float humidity_point;
 
diff --git a/src/mg_decoration.cpp b/src/mg_decoration.cpp
index dec82a638..1848024dc 100644
--- a/src/mg_decoration.cpp
+++ b/src/mg_decoration.cpp
@@ -140,8 +140,8 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 					mg->heightmap[mapindex] :
 					mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
 
-			if (y < nmin.Y     || y > nmax.Y ||
-				y < height_min || y > height_max)
+			if (y < nmin.Y || y > nmax.Y ||
+				y < y_min  || y > y_max)
 				continue;
 
 			int height = getHeight();
diff --git a/src/mg_decoration.h b/src/mg_decoration.h
index 3c96611c7..59c3ff558 100644
--- a/src/mg_decoration.h
+++ b/src/mg_decoration.h
@@ -66,8 +66,8 @@ class Decoration : public GenElement, public NodeResolver {
 	int mapseed;
 	std::vector<content_t> c_place_on;
 	s16 sidelen;
-	s16 height_min;
-	s16 height_max;
+	s16 y_min;
+	s16 y_max;
 	float fill_ratio;
 	NoiseParams np;
 
diff --git a/src/mg_ore.cpp b/src/mg_ore.cpp
index 95bc02f4f..5bbc40e13 100644
--- a/src/mg_ore.cpp
+++ b/src/mg_ore.cpp
@@ -95,25 +95,25 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
 {
 	int in_range = 0;
 
-	in_range |= (nmin.Y <= height_max && nmax.Y >= height_min);
+	in_range |= (nmin.Y <= y_max && nmax.Y >= y_min);
 	if (flags & OREFLAG_ABSHEIGHT)
-		in_range |= (nmin.Y >= -height_max && nmax.Y <= -height_min) << 1;
+		in_range |= (nmin.Y >= -y_max && nmax.Y <= -y_min) << 1;
 	if (!in_range)
 		return 0;
 
-	int ymin, ymax;
+	int actual_ymin, actual_ymax;
 	if (in_range & ORE_RANGE_MIRROR) {
-		ymin = MYMAX(nmin.Y, -height_max);
-		ymax = MYMIN(nmax.Y, -height_min);
+		actual_ymin = MYMAX(nmin.Y, -y_max);
+		actual_ymax = MYMIN(nmax.Y, -y_min);
 	} else {
-		ymin = MYMAX(nmin.Y, height_min);
-		ymax = MYMIN(nmax.Y, height_max);
+		actual_ymin = MYMAX(nmin.Y, y_min);
+		actual_ymax = MYMIN(nmax.Y, y_max);
 	}
-	if (clust_size >= ymax - ymin + 1)
+	if (clust_size >= actual_ymax - actual_ymin + 1)
 		return 0;
 
-	nmin.Y = ymin;
-	nmax.Y = ymax;
+	nmin.Y = actual_ymin;
+	nmax.Y = actual_ymax;
 	generate(mg->vm, mg->seed, blockseed, nmin, nmax);
 
 	return 1;
diff --git a/src/mg_ore.h b/src/mg_ore.h
index bd81a63fb..dc33873d4 100644
--- a/src/mg_ore.h
+++ b/src/mg_ore.h
@@ -56,8 +56,8 @@ class Ore : public GenElement, public NodeResolver {
 	u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
 	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;
-	s16 height_max;
+	s16 y_min;
+	s16 y_max;
 	u8 ore_param2;		// to set node-specific attributes
 	u32 flags;          // attributes for this ore
 	float nthresh;      // threshhold for noise at which an ore is placed
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 9e6eacff8..d7c687bd8 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -448,8 +448,8 @@ int ModApiMapgen::l_register_biome(lua_State *L)
 	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",    -31000);
-	b->height_max      = getintfield_default(L, index, "height_max",     31000);
+	b->y_min           = getintfield_default(L, index, "y_min",         -31000);
+	b->y_max           = getintfield_default(L, index, "y_max",          31000);
 	b->heat_point      = getfloatfield_default(L, index, "heat_point",     0.f);
 	b->humidity_point  = getfloatfield_default(L, index, "humidity_point", 0.f);
 	b->flags           = 0; //reserved
@@ -522,8 +522,8 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
 
 	deco->name       = getstringfield_default(L, index, "name", "");
 	deco->fill_ratio = getfloatfield_default(L, index, "fill_ratio", 0.02);
-	deco->height_min = getintfield_default(L, index, "height_min", -31000);
-	deco->height_max = getintfield_default(L, index, "height_max", 31000);
+	deco->y_min      = getintfield_default(L, index, "y_min", -31000);
+	deco->y_max      = getintfield_default(L, index, "y_max", 31000);
 	deco->sidelen    = getintfield_default(L, index, "sidelen", 8);
 	if (deco->sidelen <= 0) {
 		errorstream << "register_decoration: sidelen must be "
@@ -683,12 +683,22 @@ int ModApiMapgen::l_register_ore(lua_State *L)
 	ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
 	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", -31000);
-	ore->height_max     = getintfield_default(L, index, "height_max", 31000);
 	ore->nthresh        = getfloatfield_default(L, index, "noise_threshhold", 0);
 	ore->noise          = NULL;
 	ore->flags          = 0;
 
+	// height_min and height_max are aliases for y_min and y_max, respectively,
+	// for backwards compatibility
+	int ymin, ymax;
+	if (!getintfield(L, index, "y_min", ymin) &&
+		!getintfield(L, index, "height_min", ymin))
+		ymin = -31000;
+	if (!getintfield(L, index, "y_max", ymax) &&
+		!getintfield(L, index, "height_max", ymax))
+		ymax = 31000;
+	ore->y_min = ymin;
+	ore->y_max = ymax;
+
 	if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) {
 		errorstream << "register_ore: clust_scarcity and clust_num_ores"
 			"must be greater than 0" << std::endl;
-- 
GitLab