#declare HillsSideWidth = 50;
#declare RockHillWidth = HillsSideWidth / 2;

#declare HillsTotalWidth = HillsSideWidth * 2 + WallMaxExtent.x - WallMinExtent.x;
#declare HillsTotalDepth = HillsSideWidth * 2 + WallMaxExtent.z - WallMinExtent.z;

#declare FlatEarthLevel = 0;

#declare CrackleHillsLevel = FlatEarthLevel - 0.5;

#declare NorthAfterFarRoadZStart = WallA_Entrance_I.v + ExitRoadLength + WallE_Entrance_I.u - 1 - WallA_Entrance_I.u;

#declare EastGroundA = box{ < -HillsTotalWidth / 2, FlatEarthLevel, WallA_Entrance_I.v >, < WallA_Entrance_I.u, -1, WallA_Entrance_I.v + ExitRoadLength > texture{ EarthTexture } }

#declare EastGroundB = box{ < -HillsTotalWidth / 2, FlatEarthLevel, WallMinExtent.z >, < WallMinExtent.x, -1, WallMaxExtent.z > texture{ EarthTexture } }

#declare SouthGroundC = box{ < -HillsTotalWidth / 2, FlatEarthLevel, WallMinExtent.z >, < HillsTotalWidth / 2, -1, WallMinExtent.z - HillsSideWidth > texture{ EarthTexture } }

#declare WestGroundB = box{ < WallMaxExtent.x, FlatEarthLevel, WallMinExtent.z >,< HillsTotalWidth / 2, -1, WallMaxExtent.z > texture{ EarthTexture } }

#declare WestGroundA = box{ < WallE_Entrance_I.u, FlatEarthLevel, WallA_Entrance_I.v >,< HillsTotalWidth / 2, -1, WallA_Entrance_I.v + ExitRoadLength > texture{ EarthTexture } }

#declare NorthGroundA = box{ < -HillsTotalWidth / 2, FlatEarthLevel, NorthAfterFarRoadZStart >, < HillsTotalWidth / 2, -1, NorthAfterFarRoadZStart + HillsSideWidth > texture{ EarthTexture } }

#declare NorthGroundB = box{ < -HillsTotalWidth / 2, FlatEarthLevel, NorthAfterFarRoadZStart + HillsSideWidth >, 
							< HillsTotalWidth / 2, -1, NorthAfterFarRoadZStart + HillsSideWidth * 2 > texture{ EarthTexture } }

#declare West2_GroundA = box{ < -HillsTotalWidth / 2, FlatEarthLevel, -HillsTotalDepth / 2 >, < -HillsTotalWidth / 2 - HillsSideWidth, -1, HillsTotalDepth / 2 > texture{ EarthTexture } }

#declare IsoHillsSlopeHighness = 4;
#declare IsoHillsTop = IsoHillsSlopeHighness + 1;

#declare PlaneFunction = function{ y }

#declare LinearPig = pigment{ gradient x color_map{ [ 0.3 color srgb 0 ]
													[ 0.35 color srgb 1]
													[ 0.4 color srgb 1 ]
													[ 0.6 color srgb 0.75 ]
													[ 0.8 color srgb 0.35 ]
													[ 0.95 color srgb 0 ] } }
													
#declare RoundPig = pigment{ spherical color_map{ 	[ 0.05 color srgb 0 ]
													[ 0.2 color srgb 0.35 ]
													[ 0.4 color srgb 0.75 ]
													[ 0.6 color srgb 1 ] 
													[ 0.65 color srgb 1 ]
													[ 0.7 color srgb 0 ]
													} }

#declare CracklePig = 
	pigment{ crackle color_map{
	[ 0 color rgb 0.2 ]
	[ 0.5 color rgb 0.75 ]
	[ 1.0 color rgb 0.8 ]
		}
	}


#macro MakeLinearCrackledHill(Transform, IsoSurfContMin, IsoSurfContMax, SlopeHighnessStrength, MaxGradient)
	#local IsoSurfSize = IsoSurfContMax - IsoSurfContMin;
	#local BoxForHill = box{ < IsoSurfContMin.x, FlatEarthLevel, IsoSurfContMin.z >, < IsoSurfContMin.x + 0.5 * IsoSurfSize.x, SlopeHighnessStrength, IsoSurfContMax.z > }
	#local CrackleAndBoxPat = pigment{ object{ BoxForHill pigment{ CracklePig }, pigment{ color srgb 0 } } }
	#local FinalCrackleFunc = function{ pigment{ CrackleAndBoxPat } }
	#local LinearFunc = function{ pigment{ LinearPig scale < IsoSurfSize.x, 1, IsoSurfSize.z > } }
	union{
		isosurface{
			function{ PlaneFunction(x,y,z) 
				- LinearFunc(x,y,z).gray * SlopeHighnessStrength
				- FinalCrackleFunc(x,y,z).gray 
				}
			accuracy 0.01
			max_gradient MaxGradient
			contained_by{ box{ IsoSurfContMin, IsoSurfContMax } }
			texture{ pigment{ RockPigment } }
		}
	
		object{ BoxForHill texture{ EarthTexture } }
		transform{ Transform }
	}
#end

#macro MakeRoundCrackleHill(Transform, Bottom, Top, Radius, SlopeHighnessStrength, MaxGradient )
	#local GroundRadiusFactor = 1.75;
	#local LocalSphereFunc = function{ x * x * GroundRadiusFactor + y * y * Radius + z * z * GroundRadiusFactor - Radius * Radius }
	#local CylinderForHill = cylinder{ < 0, FlatEarthLevel, 0 >, < 0, SlopeHighnessStrength, 0 >, Radius * 0.5 }
	#local CrackleAndCylinderPat = pigment{ object{ CylinderForHill pigment{ CracklePig }, pigment{ color srgb 0 } } }
	#local FinalCrackleFunc = function{ pigment{ CrackleAndCylinderPat } }
	#local RoundFunc = function{ pigment{ RoundPig scale < Radius, 1, Radius > } }
	#local UsefulCrackleFunc = function{ pigment{ CracklePig } }
	union{
		isosurface{
			function{ 
				LocalSphereFunc(x,y,z)
				//PlaneFunction(x,y,z)
				//RoundFunc(x,y,z).gray * SlopeHighnessStrength
				- UsefulCrackleFunc(x,y,z).gray
			}
			accuracy 0.01
			max_gradient MaxGradient
			contained_by{ sphere{ 0, Radius * 1.5 } }
			texture{ pigment{ RockPigment } }
			transform{ Transform }
		}
	}
#end