#declare SmallForestGround =
union{
	object{ EastGroundA }
	object{ EastGroundB }
	object{ SouthGroundC }
	object{ WestGroundB }
	object{ WestGroundA }
}

#declare MapleTreeArray = array[2]{ MapleA, MapleF }
#declare KapokTreeArray = array[2]{ KapokTree1, KapokTree2 }

#declare SmallTreeChoiceSeed = seed( 1234 );
#declare SmallTreeRotateSeed = seed( 5678 );
#declare SmallTreeDecalSeed = seed( 9999 );
#declare SmallTreeScaleSeed = seed( 1111 );

#declare BigTreeChoiceSeed = seed( 2222 );
#declare BigTreeRotateSeed = seed( 3333 );
#declare BigTreeDecalSeed = seed( 4444 );
#declare BigTreeScaleSeed = seed( 5555 );

#macro GetTreeIndex(RandValue)
	#local ArrayIndex = 0;
	#if( RandValue >= 0 & RandValue < 0.2 )
		#local ArrayIndex = 0;
	#else
		#local ArrayIndex = 1;
	#end
	ArrayIndex
#end

#macro PlaceSmallTrees(TreesBaseScale, ScalePercentAdd, Interval)
	#for( ItX, min_extent( SmallForestGround ).x, max_extent( SmallForestGround ).x, Interval )
		#for( ItZ, min_extent( SmallForestGround ).z, max_extent( SmallForestGround ).z, Interval )
			#if(
				//Not in the yard
				! ( ItX >= WallMinExtent.x - Interval & ItX <= WallMaxExtent.x + Interval & ItZ >= WallMinExtent.z - Interval & ItZ <= WallMaxExtent.z + Interval ) 
				
				//Not on the entrance road
				& ! ( ItX >= WallA_Entrance_I.u - Interval & ItX < WallE_Entrance_I.u + Interval & ItZ >= WallA_Entrance_I.v & ItZ <= WallA_Entrance_I.v + ExitRoadLength )	)
				
				object{ MapleTreeArray[GetTreeIndex(rand(SmallTreeChoiceSeed) ) ] scale TreesBaseScale + AffineFunc( 0, 1, 0, TreesBaseScale * ScalePercentAdd, rand(SmallTreeScaleSeed) ) 
					rotate rand(SmallTreeRotateSeed) * 360 * y 
					translate < ItX + AffineFunc( 0, 1, -Interval / 3, Interval / 3, rand(SmallTreeDecalSeed) ), FlatEarthLevel, 
								ItZ + AffineFunc( 0, 1, -Interval / 3, Interval / 3, rand(SmallTreeDecalSeed) ) >
				}
			#end
		#end
	#end
#end

#macro PlaceKapokTrees1(TreesBaseScale, ScalePercentAdd, Interval)
	#for( ItX, min_extent( West2_GroundA ).x, max_extent( West2_GroundA ).x, Interval )
		#for( ItZ, min_extent( West2_GroundA ).z, max_extent( West2_GroundA	).z, Interval )
			object{ KapokTreeArray[ GetTreeIndex(rand(BigTreeChoiceSeed) ) ] scale TreesBaseScale + AffineFunc( 0, 1, 0, TreesBaseScale * ScalePercentAdd, rand(BigTreeScaleSeed) )
				rotate rand( BigTreeRotateSeed ) * 360 * y
				translate < ItX + AffineFunc( 0, 1, -Interval / 3, Interval / 3, rand(BigTreeDecalSeed) ), FlatEarthLevel,
							ItZ + AffineFunc( 0, 1, -Interval / 3, Interval / 3, rand(BigTreeDecalSeed) ) >
			}
		#end
	#end
#end

#macro PlaceKapokTrees(GroundObject, TreesBaseScale, ScalePercentAdd, Interval)
	#for( ItX, min_extent( GroundObject ).x, max_extent( GroundObject ).x, Interval )
		#for( ItZ, min_extent( GroundObject ).z, max_extent( GroundObject	).z, Interval )
			object{ KapokTreeArray[ GetTreeIndex(rand(BigTreeChoiceSeed) ) ] scale TreesBaseScale + AffineFunc( 0, 1, 0, TreesBaseScale * ScalePercentAdd, rand(BigTreeScaleSeed) )
				rotate rand( BigTreeRotateSeed ) * 360 * y
				translate < ItX + AffineFunc( 0, 1, -Interval / 3, Interval / 3, rand(BigTreeDecalSeed) ), FlatEarthLevel,
							ItZ + AffineFunc( 0, 1, -Interval / 3, Interval / 3, rand(BigTreeDecalSeed) ) >
			}
		#end
	#end
#end

