//There is about 27 minutes of parsing time with povray 3.7 against 
//	about 5 minutes with povray 3.8.0-beta 2 thanks to macro caching.

#version 3.7;

#declare Radiosity = true;
#declare PlaceFlore = true;
#declare PlaceJeep = true;
#declare PlaceHovercraft = true;
#declare PlaceAbramsTank = true;
#declare PlaceFences = true;

global_settings{ assumed_gamma 1.0 
	#if( Radiosity )
		#default{ finish{ ambient 0 } }
	
		radiosity{
			pretrace_start 64 / image_width
			pretrace_end 2 / image_width
			count 800
			nearest_count 9
			low_error_factor 0.7
			minimum_reuse 0.015
			error_bound 0.25
			always_sample off
			gray_threshold 0.65
			brightness 1
			recursion_limit 1
			normal on
			media on
			adc_bailout 0.01 / 2
		}
	#end
}

background{ color srgb 1 }

camera{
	location < 2, 9, -40 >
	look_at < -8, 5.5, 0 >
	right image_width / image_height * x
	sky y
	up y
}

light_source{ < 1, 4, -2 > * 400 color srgb 1 }

#declare GenericIncludesDir = "includes/";
#declare FontsPath = "fonts/";

#include "math.inc"
#include "arrays.inc" //Useful to resize array of little flore
#include concat(GenericIncludesDir, "debug/debugMacros.inc")
#include concat(GenericIncludesDir, "affineFunctionSetter.inc")
#include concat(GenericIncludesDir, "customArraysMacros.inc") //Needs 'arrays.inc' just above line
#include concat(GenericIncludesDir, "colorsMercenaires.inc")
#include concat(GenericIncludesDir, "texturesMercenaires.inc")
#include concat(GenericIncludesDir, "objects/plantObjects.inc") //sets 'BeigeMixPig' pigment
#include concat(GenericIncludesDir, "radiositySky.inc")

#if( PlaceFlore )
	#include concat(GenericIncludesDir, "povtree/kapokTree1.inc")
	#include concat(GenericIncludesDir, "povtree/kapokTree2.inc")
	#include concat(GenericIncludesDir, "povtree/plant1.inc")
#end

#include "includes/waterCanalElements.inc"
#include "includes/backgroundsElements.inc"
#include "includes/wireFencing.inc"

#if( PlaceJeep )
	#local ModelSubDir = concat(GenericIncludesDir, "3d models/jeep/")
	#include concat(GenericIncludesDir, "3d models/jeep/jeep_POV_geom.inc")
#end
#if( PlaceAbramsTank )
	#declare AbramsScale = 5;
	#local CompleteAbramsDir = concat(GenericIncludesDir, "3d models/M1 Abrams/completeAbrams/")
	#include concat(GenericIncludesDir, "3d models/M1 Abrams/completeAbrams/Abrams_geom.inc")
#end

#declare ArialBoldFontPath = concat(FontsPath, "arialbd.ttf")

MakeSky( color srgb < 0.8, 0.8, 1 >, 
		color srgb < 143 / 255, 195 / 255, 251 /255 >, 
		3 )

object{ WaterPlane }

object{ BeigeSlopes translate -0.0001 * y }
object{ SouthWestConcreteBlocks }
object{ NorthEastConcreteBlocks }
object{ NorthForestEarthBox }
object{ BackBarrier }
object{ CornerBarrier }
MakeOnXBarrierPylon(WestSlopesXCoord, PtD.x + BarrierDeltaWithSlope, PtD.z + BarrierDeltaWithSlope, BarrierPylonSpace)
MakeOnZBarrierPylon(SouthSlopesZCoord, PtD.z + BarrierDeltaWithSlope, PtD.x + BarrierDeltaWithSlope, BarrierPylonSpace)
MakeOnXBarrierPylon(WestSlopesXCoord, PtH.x - BarrierDeltaWithSlope, PtH.z - BarrierDeltaWithSlope, BarrierPylonSpace)
MakeOnZBarrierPylon(SouthSlopesZCoord, PtH.z - BarrierDeltaWithSlope, PtH.x - BarrierDeltaWithSlope, BarrierPylonSpace)

PlaceCompletePlantBlock( "9", ArialBoldFontPath, transform{ scale 0.5 translate BlockCornerPosition - < 10, 0, 0 > } )
PlaceCompletePlantBlock( "3", ArialBoldFontPath, transform{ scale 0.5 translate BlockCornerPosition - < 0, 0, 8 > } )
PlaceCompletePlantBlock( "1", ArialBoldFontPath, transform{ scale 0.5 translate BlockCornerPosition } )
object{ PlantBlockPipe }
object{ PipeSupport translate < PlantBlockPipeCenter.x - 1.2, SlopesHeight, PlantBlockPipeCenter.z > }
object{ PipeSupport translate < PlantBlockPipeCenter.x + 1.2, SlopesHeight, PlantBlockPipeCenter.z > }


#if( PlaceHovercraft )
	#include concat(GenericIncludesDir, "3d models/hovercraft/hovercraft.inc")
	#include "includes/hovercraftDefines.inc"
	#include concat(GenericIncludesDir, "3d models/hovercraft/waterScum.inc")
	
	HoverCraft_PlaceObject( true, transform{ scale 0.35 rotate 180 * y translate < -6, 0, -22 > } )
	//Place water scum at the back of the hovercraft
	#declare ScumMediaIntensity = 16;
	#declare WaterScumYPos = -0.123;
	
	union{
		PlaceWaterScum( 0, 8, transform{ translate < 0, 0, -HoverCraftSize.z / 2 * 0.95 > 
									scale 0.35 rotate 180 * y translate < -6, WaterScumYPos, -22 > }, ScumMediaIntensity )
		
		#for( It, 0, 3 )
			#local MediaIntensity = SetWithAffineFunction(0, 4, ScumMediaIntensity, 0, It);
			PlaceWaterScumBorder( 0, 8, transform{ translate < 0, 0, -HoverCraftSize.z / 2 * 0.95 > 
									scale 0.35 rotate 180 * y translate < -6, WaterScumYPos, -22 > }, MediaIntensity, It )
		#end
		no_radiosity
	}
#end

#if( PlaceJeep )
	object{ Jeep scale 0.85 rotate 180 * y rotate -13 * z
		translate < ( max_extent( EastSideRoad ).x + min_extent( EastSideRoad ).x ) / 2 - EastSideRoadScale.x / 2, PtE.y, -6 > }
#end

#if( PlaceAbramsTank )
	#local Normal = < 0, 0, 0 >;
	#local TraceStart = < ( max_extent( EastSideRoad ).x + min_extent( EastSideRoad ).x ) / 2 + 1, 1000, 20 >;
	#local YPos = trace( EastSideRoad, TraceStart, -y, Normal );
	
	#if( Normal.x != 0 | Normal.y != 0 | Normal.z != 0 )
		object{ M1Abrams rotate -90 * y scale AbramsScale translate YPos }
	#end
#end

object{ NorthForestEarthBox }

#if( PlaceFlore )
	#declare NorthTreesLocationArray = array[1079];
	#declare NorthPlantsLocationArray = array[29000];
	
	PlantForest( NorthForestEarthBox, "NorthForestEarthBox", NorthTreesLocationArray, NorthPlantsLocationArray )
	
	#declare EastTreesLocationArray = array[661];
	#declare EastPlantsLocationArray = array[20000];
	PlantForest( EastForestEarthBox, "EastForestEarthBox", EastTreesLocationArray, EastPlantsLocationArray)
#end

#declare WaterMediaSpecularSpacing = 2;

PlaceWaterMediaSpeculars(< WestSlopesXCoord, PtI.z >,< PtC.x, PtC.z >, MediaSphereRadius * 2, WaterMediaSpecularSpacing )

PlaceWaterMediaSpeculars(< PtG.x, SouthSlopesZCoord >,< PtC.x, PtG.z >, MediaSphereRadius * 2, WaterMediaSpecularSpacing )

object{ EastSideRoad }

object{ SideWalkPrism translate < NorthEastCorner.x, PtE.y - SideWalkSize.y , PtE.z > }

object{ SideWalkPrism rotate 180 * y 
	translate < max_extent( EastSideRoad ).x + SideWalkSize.x, PtE.y - SideWalkSize.y, max_extent( EastSideRoad ).z >
}

object{ RightSideRoadConcreteBlock }

object{ EastForestEarthBox }

#if( PlaceFences )
	//Near water canal fence
	MakeWireFenceOnX( WireFencingLength, WestFencesNumber, FencesWiresHighness, WireInterval, 
		transform{ translate < WestFenceEndingPos.x - WireFencingLength * WestFencesNumber - PylonRadius * 1.5, SlopesHeight, min_extent( NorthForestEarthBox ).z > } )

	//Road east side fence
	MakeWireFenceOnX( WireFencingLength, EastSideRoadFencesNumber, FencesWiresHighness, WireInterval,
		transform{ rotate -90 * y translate < min_extent( EastForestEarthBox ).x, SlopesHeight, min_extent( EastSideRoad ).z > } ) 
	
	//Road west side fence
	MakeWireFenceOnX( WireFencingLength, WestSideRoadFencesNumber, FencesWiresHighness, WireInterval,
		transform{ rotate -90 * y translate < max_extent( NorthForestEarthBox ).x, SlopesHeight, min_extent( NorthForestEarthBox ).z + PylonRadius * 1.5 > } ) 
#end