#declare RandPos = seed(15000);

#declare OnMountTreeRand = seed(65579);

#macro PlaceBushesOnMountain( StartPos, EndPos, CollisionObject, BushesNumber)
    #local Norm = <0, 0, 0>;
    #for( it_x, int(StartPos.x), int(EndPos.x), 1 )// default step value: 2            
        #for(it_z, int(StartPos.z), int(EndPos.z), 1 )
            #local StartPoint = <it_x + 1.5*rand(RandPos) - 0.75, 80000, it_z + 1.5*rand(RandPos) - 0.75 >;
            #local BushPos = trace(CollisionObject, StartPoint, -y, Norm );
            #if(Norm.x != 0 | Norm.y != 0 | Norm.z != 0)  
                #if( vdot(Norm, y) > 0.5 )
					#if( mod(it_x, 2) = 0 & mod(it_z, 2) = 0 )
						#if( mod(it_x, 32) = 0 & mod(it_z, 32) = 0 & vdot(Norm, y) > 0.8 ) 
							#local TreeType = rand(OnMountTreeRand);
							#if( TreeType >= 0.5 )
								object{ WavedBranches rotate 360*rand(OnMountTreeRand)*y scale WavedBranchesScale translate BushPos }
							#else
								object{ KapokTree2 rotate 360*rand(OnMountTreeRand)*y scale KapokTreeScale translate BushPos }
							#end
						#else
							//object{Bush1 scale 2 Reorient_Trans(y, Norm) translate BushPos }
							//#local BushesNumber = BushesNumber + 1;
						#end
					#end
                #end
            #end 
        #end
    #end
#end

#macro PlaceMountainTrees(BushesNum)
	#debug "Placing trees on mountains\n"
	PlaceBushesOnMountain( min_extent(MountainA), max_extent(MountainA), MountainA , BushesNum )
	PlaceBushesOnMountain( min_extent(MountainB), max_extent(MountainB), MountainB , BushesNum )
	PlaceBushesOnMountain( min_extent(MountainC), max_extent(MountainC), MountainC , BushesNum )
	PlaceBushesOnMountain( min_extent(MountainD), max_extent(MountainD), MountainD , BushesNum )
	PlaceBushesOnMountain( min_extent(MountainE), max_extent(MountainE), MountainE , BushesNum )
#end