
function floor_start( floorname, count, delay )

	floorname = format ( "floor-%s", floorname )

	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

	actor[cp_launch_hue_shift] = floor_hue[1]

-- change texture ?
if floor_bmpswap ~= nil then
	for t = 1,19,2 do
		if floor_bmpswap[t] ~= nil then
			c_change_bitmap( floor_bmpswap[t], floor_bmpswap[t+1] )
		else
			-- end loop
			break
		end
	end
end

	c_preload_model( actor )


	c_set_random_anim( floor_keyset1[1], floor_keyset1[2], floor_keyset1[3], floor_keyset1[4], floor_keyset1[5] )

	if floor_keyset2 ~= nil then
		c_set_random_anim( floor_keyset2[1], floor_keyset2[2], floor_keyset2[3], floor_keyset2[4], floor_keyset2[5] )
	end


	local apo = ACTOR_PreLaunch( floorname )

	local size = floor_pos[5]
	local posx = 0
	local posy = 0
	local posz = 0
	local rot = 0
	local hue = 0

	for t = 0, ( count -  1 ), 1 do
		posx = floor_pos[1] + (floor_trans[1] * t)
		posy = floor_pos[2] + (floor_trans[2] * t)
		posz = floor_pos[3] + (floor_trans[3] * t)
		rot = floor_pos[4] + (floor_trans[4] * t)
		hue = floor_hue[2] * t
		apo:setall( posx, posy, posz, rot, size, hue, 0.0 )
		apo:setanimdelay( delay * t )
		apo:launch()
		size = size * floor_trans[5]
	end
end


function floor_start_random()
	if gfx_level < 1 then
		return
	end

	local choice_floortype_name = { "1", "1", "1","1", "1", "1","1", "1", "1", "2" }
	local choice_floortype_num = c_zrand_int( 10 ) + 1

	local choice_keyset1_name = { "pulse", "swiv20", "scale20", "scale5" }
	local choice_keyset1_num = c_zrand_int( 4 ) + 1
	local choice_keyset1_speed_min = c_zrand( 200 ) + 100
	local choice_keyset1_speed_max = choice_keyset1_speed_min -- c_zrand( 200 ) + 100

	floor_keyset1 = { choice_keyset1_name[choice_keyset1_num], choice_keyset1_speed_min, choice_keyset1_speed_max, 0, 0 }


	floor_keyset2 = nil
	if choice_floortype_name[choice_floortype_num] == "1" then
		local choice_keyset2_name = { "flat", "scale170", "scale140", "scale120", "scale80", "scale60", "scale30", "ysquish", "xsquish", "flat","flat","flat","flat","flat","flat","tilth","tiltv","movev","moveh","anitwist30", "anisquish-1", "anisquish-2" }
		local choice_keyset2_num = c_zrand_int( 22 ) + 1
		local choice_keyset2_speed_min = c_zrand( 200 ) + 100
		local choice_keyset2_speed_max = choice_keyset2_speed_min -- c_zrand( 200 ) + 100

		local ani_delay = 0
		if choice_keyset2_num < 16 then
			ani_delay = 600
		end

		floor_keyset2 = { choice_keyset2_name[choice_keyset2_num], choice_keyset2_speed_min, choice_keyset2_speed_max, ani_delay, ani_delay }
	end


	local floor_posy = 20.0
	floor_pos = { 0,-floor_posy,0, 0,200 }

	local choice_floortype_count = c_zrand_int( 3 ) + 3
	local choice_floortype_delay = c_zrand( 0.2 ) + 0.2
	floor_posy = c_zrand( 20.0 ) + 20.0
	floor_trans = { 0,-floor_posy,0, 0,c_zrand(0.85,1.0) }

	local floor_hue_add = c_zrand(-45.0,45.0)
	if floor_hue_add > 0.0 then
		floor_hue_add = floor_hue_add + 15.0
	else
		floor_hue_add = floor_hue_add - 15.0
	end
--	c_print( "hue", gfx_level, floor_hue_add )

	if gfx_level == 3 then
		choice_floortype_count = c_zrand_int( 6 ) + 6
		choice_floortype_delay = c_zrand( 0.1 ) + 0.1
		floor_trans[2] = floor_trans[2] * 0.5
		floor_trans[5] = c_zrand(0.9,1.0)
	elseif gfx_level == 1 then
		choice_floortype_count = c_zrand_int( 2 ) + 2
		choice_floortype_delay = c_zrand( 0.3 ) + 0.3
		floor_trans[2] = floor_trans[2] * 2.0
		floor_trans[5] = c_zrand(0.8,1.0)
	end

	local choice_bitmap = 0
	local bitmap_name = ""
	floor_bmpswap = nil

	if choice_floortype_name[choice_floortype_num] == "2" then
--		choice_bitmap = c_zrand_int( 2 ) + 1
--		bitmap_name = "tunnel-1tile"
		choice_floortype_count = c_zrand_int( 3 ) + 6
		if gfx_level == 1 then
			choice_floortype_count = c_zrand_int( 3 ) + 3
		end
		floor_trans[2] = -( c_zrand( 20.0 ) + 20.0 )
		floor_trans[5] = c_zrand(0.7,0.9)
		floor_hue_add = floor_hue_add * 2.0
	elseif choice_floortype_name[choice_floortype_num] == "1" then
		choice_bitmap = c_zrand_int( 18 ) + 1
		if demo_level == 1 then
			choice_bitmap = c_zrand_int( 4 ) + 1
		end
		bitmap_name = "floor-1_"
	end

	if choice_bitmap > 1 then
		local bitmap_name_1 = format( "%s%d.bmp", bitmap_name, 1 )
		local bitmap_name_2 = format( "%s%d.bmp", bitmap_name, choice_bitmap )
		floor_bmpswap = { bitmap_name_1 , bitmap_name_2 }
	end

	floor_hue_add = floor_hue_add / choice_floortype_count
	floor_hue = { floor_colour, floor_hue_add }

	floor_start( choice_floortype_name[choice_floortype_num], choice_floortype_count, choice_floortype_delay )
end
