
bg_tunneller_unique_name = ""

function floor_start_bg_tunneller()
	local floorname = "bg_tunneller"

	local actor = ACTOR_preload()

	actor[cp_actor_name]		= floorname
	actor[cp_model_dir]			= "rooms"
	actor[cp_model_name]		= floorname

	actor[cp_actor_type]			= cat_ground
	actor[cp_i_collide_with_beasties]	= 0
	actor[cp_these_collide_with_me]		= 0

	c_preload_model( actor )

	c_set_random_anim( floor_base_keyset1[1], floor_base_keyset1[2], floor_base_keyset1[2], 0.0, 0.0 )

	bg_tunneller_unique_name = format( "%s_%d", floorname, actor_unique_id )
	local apo = ACTOR_PreLaunch( floorname, bg_tunneller_unique_name )
	apo:setall( 0.0, 0.0, 0.0, 0.0, 300.0, 0.0, 0.0 )
	apo:launch()
end


function floor_start_bg_tunneller_anim()
	local floorname = "bg_tunneller_anim"

	local actor = ACTOR_preload()

	actor[cp_actor_name]		= floorname
	actor[cp_model_dir]			= "rooms"
	actor[cp_model_name]		= floorname

	actor[cp_actor_type]			= cat_ground
	actor[cp_i_collide_with_beasties]	= 0
	actor[cp_these_collide_with_me]		= 0

	c_preload_model( actor )

	c_set_random_anim( floor_anim_keyset1[1], floor_anim_keyset1[2], floor_anim_keyset1[2], 0.0, 0.0 )
	
	if floor_anim_keyset2 ~= nil then
		c_set_random_anim( floor_anim_keyset2[1], floor_anim_keyset2[2], floor_anim_keyset2[2], 0.0, 0.0 )
	end
	
	if floor_anim_keyset3 ~= nil then
		c_set_random_anim( floor_anim_keyset3[1], floor_anim_keyset3[2], floor_anim_keyset3[2], 0.0, 0.0 )
	end

	local apo = ACTOR_PreLaunch( floorname )
	apo:setall( 0.0, 0.0, 0.0, 0.0, 100.0, 0.0, 0.0 )
	apo:launch()
end


function floor_start_bg_tunneller_slice( slicename, bonenum )
	local apo = ACTOR_PreLaunch( slicename )
	apo:setall( 0.0, 0.0, 0.0, 0.0, 300.0, 0.0, 0.0 )
	apo:launch()

	local bonename = format( "slice%02d", bonenum )
	c_link_to_parent( bg_tunneller_unique_name, bonename )
end


function load_bg_tunneller_slice( slicename, hue )
	local slicemodelname = format( "bg_tunneller_%s", slicename )

-- leave me
	local actor = ACTOR_preload()
-- leave me

	actor[cp_actor_name]		= slicename
	actor[cp_model_dir]			= "rooms"
	actor[cp_model_name]		= slicemodelname

	actor[cp_actor_type]			= cat_ground
	actor[cp_i_collide_with_beasties]	= 0
	actor[cp_these_collide_with_me]		= 0

	actor[cp_launch_hue_shift] = hue

-- leave me
	c_preload_model( actor )
-- leave me
end

-- Choose Floor Method
floor_type = c_zrand_int ( 1 ) + 1



function floor_start_random()
--bg_tunneller
	local choice_base_name1 = { "bend", "straight", "diag" }
	local max_num_choices = getn( choice_base_name1 )
	local choice_num = c_zrand_int( max_num_choices ) + 1

	local tunnel_speed_part_one = {    10,     5,    5,	10}
	local tunnel_speed_part_two = {	    5,     10,    15,	5}
	local tunnel_alpha_value =    {   0.8,   0.9,   0.93,	0.95}
--	local tunnel_alpha_value =    {   0.99,   0.99,   0.99,	0.99}	
	local tunnel_alpha_scale =    {   1.1,   1.2,  1.002,	1.0}

	local max_num_speed_choices = getn( tunnel_speed_part_one )
	local choice_num_speed = c_zrand_int( max_num_speed_choices ) + 1

--override random anim speed type>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
--choice_num_speed = 3

	local choice_speed = c_zrand( tunnel_speed_part_one[choice_num_speed] ) + tunnel_speed_part_two[choice_num_speed]

	local alpha_value = tunnel_alpha_value[choice_num_speed]

--override random anim type>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
--choice_num = 2

	if choice_num == 3 then
		alpha_value = alpha_value - 0.1
	end

	if choice_num == 1 then
		alpha_value = alpha_value - 0.05
	end

	c_set_slice_alpha_scale( alpha_value, tunnel_alpha_scale[choice_num_speed] )
--	c_set_slice_alpha_scale( 0.0, 1.0 )



	c_set_lower_pylon_alpha_scale( 0.8, 1.01 )


	floor_base_keyset1 = { choice_base_name1[choice_num], choice_speed }
	floor_start_bg_tunneller()
--bg_tunneller

	c_print( "tunnel ", choice_base_name1[choice_num], " - speed ", choice_speed, " - alpha ", alpha_value, " - scale ", tunnel_alpha_scale[choice_num_speed] )


--bg_tunneller_anim
	local choice_anim_name1 = { "swingx", "scalex" }
	max_num_choices = getn( choice_anim_name1 )
	choice_num = c_zrand_int( max_num_choices ) + 1
	choice_speed = c_zrand( 100 ) + 5
--override random
--choice_num = 1
--choice_speed = 60
	floor_anim_keyset1 = { choice_anim_name1[choice_num], choice_speed }

	local choice_anim_name2 = { "swingy", "scaley" }
	max_num_choices = getn( choice_anim_name2 )
	choice_num = c_zrand_int( max_num_choices ) + 1
	choice_speed = c_zrand( 100 ) + 5
--override random
--choice_num = 1
--choice_speed = 60
	floor_anim_keyset2 = { choice_anim_name2[choice_num], choice_speed }

	local choice_anim_name3 = { "spin360", "sway90", "sway50", "sway20" }
	max_num_choices = getn( choice_anim_name3 )
	choice_num = c_zrand_int( max_num_choices ) + 1
	choice_speed = c_zrand( 100 ) + 5
--override random
--choice_num = 1
--choice_speed = 60
	floor_anim_keyset3 = { choice_anim_name3[choice_num], choice_speed }


	floor_start_bg_tunneller_anim()
--bg_tunneller_anim


--bg_tunneller_slice
	local slice_hue = 0.0
	local slice_names = {}
-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	slice_names = { "1_1", "1_2", "2_1", "2_2", "2_3", "4_1", "4_2", "4_3", "4_4", "4_5", "4_6", "4_7" }
	max_num_choices = getn( slice_names ) 



	local slice_template = {}
	local slice_template_choice = c_zrand_int( 12 ) + 1
--	local slice_template_choice = 1

		if slice_template_choice == 1 then
		        slice_template = { 1,2,3,3,2,1,2,3,3,2,1,2,3,3,2,1,2,3,3,2 }
		elseif slice_template_choice == 2 then
		        slice_template = { 1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3 }
		elseif slice_template_choice == 3 then
		        slice_template = { 1,1,1,2,2,3,3,3,2,2,1,1,1,2,2,3,3,3,2,2 }
		elseif slice_template_choice == 4 then
		        slice_template = { 1,2,3,1,1,2,3,1,1,2,3,1,1,2,3,1,1,2,3,1 }
		elseif slice_template_choice == 5 then
		        slice_template = { 1,2,2,2,2,1,2,2,2,2,1,3,3,3,3,1,3,3,3,3 }
		elseif slice_template_choice == 6 then
		        slice_template = { 1,2,1,2,1,3,1,3,2,3,2,3,3,2,3,2,3,1,3,1 }
		elseif slice_template_choice == 7 then
		        slice_template = { 1,2,2,2,3,3,3,2,2,2,1,2,2,2,3,3,3,2,2,2 }
		elseif slice_template_choice == 8 then
		        slice_template = { 1,2,3,2,3,1,2,3,2,3,1,2,3,2,3,1,2,3,2,3 }
		elseif slice_template_choice == 9 then
		        slice_template = { 1,1,1,2,1,2,2,2,3,2,3,3,3,2,3,2,2,2,1,2 }
		elseif slice_template_choice == 10 then
		        slice_template = { 1,1,2,2,3,3,2,2,1,1,1,1,2,2,3,3,2,2,1,1 }
		elseif slice_template_choice == 11 then
		        slice_template = { 1,2,3,1,3,3,1,3,2,1,1,2,3,1,3,3,1,3,2,1 }
		elseif slice_template_choice == 12 then
		        slice_template = { 1,1,2,1,2,1,2,2,1,2,2,2,3,2,3,3,3,3,2,1 }
		end


	local slicename
	local slicename1
	local slicename2
	local slicename3

	if cur_level_num > 99 then
		choice_num = c_zrand_int( max_num_choices ) + 1
--		choice_num = 6
		slicename1 = format( "slice_%s", slice_names[choice_num] )
		slice_hue = floor_colour + c_zrand(0.0,0.0)
--		slice_hue = 0
		load_bg_tunneller_slice( slicename1, slice_hue )

		choice_num = c_zrand_int( max_num_choices ) + 1
--		choice_num = 6		
		slicename2 = format( "slice_%s", slice_names[choice_num] )
		slice_hue = floor_colour + 20 + c_zrand(0.0,40.0)
--		slice_hue = 0
		load_bg_tunneller_slice( slicename2, slice_hue )

		choice_num = c_zrand_int( max_num_choices ) + 1
--		choice_num = 6	
		slicename3 = format( "slice_%s", slice_names[choice_num] )
		slice_hue = floor_colour - 20 - c_zrand(0.0,40.0)
--		slice_hue = 0
		load_bg_tunneller_slice( slicename3, slice_hue )
	end

	for t = 1, 20, 1 do
		if cur_level_num < 100 then
			if t <= max_num_choices then
				slicename = format( "slice_%s", slice_names[t] )
				load_bg_tunneller_slice( slicename, 0.0 )
			end
		else
			if slice_template[t] == 1 then
				slicename = slicename1
			elseif slice_template[t] == 2 then
				slicename = slicename2
			else
				slicename = slicename3
			end
		end
		floor_start_bg_tunneller_slice( slicename, t )
	end
--bg_tunneller_slice
end

