
global gBoosts as tPath

function ProcessBoost(vehicle ref as tVehicle, cell ref as tCell, env ref as tEnvironment)
	i as integer
	d as float
	x as integer
	

	if cell.boost = 0
		exitfunction
	endif
	
	if vehicle.velocity.max < vehicle.velocity.save
		exitfunction
	endif

	d = (GetObjectDepth(vehicle.hit) * 0.5) + (GetObjectWidth(env.boost.id) * 0.55)
	
	if DistanceXZ(GetObjectPos(vehicle.hit), GetObjectPos(cell.boost)) < d
		if vehicle.velocity.boost = 0
			vehicle.velocity.time = timer() + 5				
			vehicle.velocity.boost = vehicle.velocity.max
			vehicle.velocity.max = vehicle.velocity.max * 1.2
		endif
		SetObject3DPhysicsMaxLinearVelocity( vehicle.hit, vehicle.velocity.max ) 			
	endif
	
endfunction


function LoadBoosts(env as tEnvironment)
	i 		as integer
	fnode	as tNode
	tnode	as tNode	
	d		as tPoint
	look	as integer
	boost	as integer
	cell	as tCell
	g		as tPoint
	new		as tPath
	
	gBoosts = FindPathByName("boost")
	
	if gBoosts.name = "bad"
		gBoosts = new
		exitfunction
	endif
				
	for i=0 to gBoosts.nodes.length step 2
		fnode = gBoosts.nodes[i]
		tnode = gBoosts.nodes[i + 1]		
		
		g.x = round(fnode.pos.x / TO_TILE_X) - gGrid.offset.x
		g.y = round(fnode.pos.y / TO_TILE_Y) - gGrid.offset.y 
		g.z = round(fnode.pos.z / TO_TILE_Z) - gGrid.offset.z		
		cell = gGrid.cells[round(g.z), round(g.x), round(g.y)]			
			
		boost = CloneObject(env.boost.id)
		
		SetObjectVisible(boost, 1)
		/*
		SetObjectDepthBias(boost, 4 ) 
		SetObjectDepthWrite(boost, 1) 
		SetObjectCullMode(boost, 0)				
				*/
		fnode.id = boost

		inc fNode.pos.y, 3
		inc tNode.pos.y, 3		
		
		SetObjectPos(boost, fnode.pos)
		
		if abs(tNode.pos.x - fNode.pos.x) > abs(tNode.pos.z - fNode.pos.z) 
			SetObjectLookAt(boost, tNode.pos.x, tNode.pos.y, fNode.pos.z, 0)
		else
			SetObjectLookAt(boost, fNode.pos.x, tNode.pos.y, tNode.pos.z, 0)			
		endif
		
		gBoosts.nodes[i] = fnode
		
		cell.boost = boost
		
		gGrid.cells[round(g.z), round(g.x), round(g.y)] = cell
	next
	
endfunction

