set_speed_seq = nil
search_uniqueid = nil
-- speed_seq { move speed, anim name, anim speed, anim delay }

cur_random_seq_num = 1


function m_plop( plop_tick, act, pattern_seq, speed_seq )
end


function r_plop( plop_tick, act, diffnum, stagenum, pattern_text, start_y, speed_seq )
	search_uniqueid = nil
	if plop_tick > 0 then
		local pattern_name = nil
		local curx = -48.0
		local speed = 0.03
		local originalspeed = 0.03
		local animspeed = 80.0
		local extract_char = nil

		if speed_seq ~= nil then
			set_speed_seq = speed_seq
			speed = speed_seq[1]
		end

		originalspeed = speed
		if diff_level == 1.0 then
			speed = speed * 0.75
		end
		if diff_level == 2.0 then
			speed = speed * 0.875
		end
--		if diff_level == 3.0 then
--			speed = speed * 1.25
--		end
--		plop_tick = ( plop_tick * originalspeed ) / speed

		for m = 1, 17, 1 do
			extract_char = format( "x%s", strsub( pattern_text, m, m ) )
			if extract_char ~= nil then
				if extract_char ~= " " then
					pattern_name = nil
					if extract_char == "x9" then
						pattern_name = "breakbrick_firecrab"
					elseif extract_char == "x8" then
						pattern_name = "breakbrick_rockcrab"
					elseif extract_char == "x2" then
						pattern_name = "breakbrick_mover"
					elseif extract_char == "x3" then
						pattern_name = "breakbrick_movey"
					elseif extract_char == "x1" then
						pattern_name = "breakbrick_move"
					end

					if pattern_name ~= nil then
--						animspeed = ( ( ( 200.0 - 80.0 ) * ( speed - 0.03 ) ) / 0.09 ) + 80.0
						set_speed_seq = { originalspeed,"walk",animspeed,0.0 }

						actor_plopper( plop_tick, pattern_name, 1, diffnum, stagenum, 0,0, curx,curx, start_y,start_y, 90.0, 0.0 )
					end
				end
			end
			curx = curx + 6.0
		end
		set_speed_seq = nil
	end
end


function x_plop( plop_tick, act, diffnum, stagenum, posx1, posy1, rotate, siz, path, speed_seq )
	search_uniqueid = nil
	set_speed_seq = nil
	local act_count = 1

	local searchidpos = strfind( act, "_id" )
--	c_print( "strfind>", searchidpos )
	if searchidpos ~= nil then
		search_uniqueid = strsub( act, searchidpos+1 )
		local strippedact = strsub( act, 1, searchidpos-1 )
--		c_print( "strsub> ", search_uniqueid, " > ", strippedact )
		act = strippedact
	end
	
	if diffnum < 0 then
		act_count = -diffnum
		diffnum = 0
	end
	
	actor_plopper( plop_tick, act, act_count, diffnum, stagenum, 0,0, posx1,posx1, posy1,posy1, rotate, siz, path )
	set_speed_seq = nil
end


function a_plop( plop_tick, act, act_count, posx1, posy1, rotate, siz, path, speed_seq )
end


function actor_plopper( plop_tick, act, act_count, diffnum, stagenum, time_delay, time_delay_delta, posx1, posx2, posy1, posy2, rotate, siz, path )
		if act_count > 0.0 then
			local posx = 0.0
			local posy = 0.0
			local posz = 0.0
			local hue = 0.0
			local rot = rotate
			local unique_name = nil
			local friend_unique_name = nil
			local parent_unique_name = nil
			local unique_name_list_1 = nil
			local launch_delay = plop_tick
			local launch_delay_inc = time_delay
			local launch_delay_delta = time_delay_delta
			local elastic = 0
			local res
			local last_act

			if launch_delay_delta <= 0.0 then
				launch_delay_delta = 1.0
			end

			res = strfind( act, "elastic" )
			if res ~= nil then
				elastic = 1
			end

			for c = 1, act_count, 1 do
				last_act = act
				friend_unique_name = nil
				posx = c_zrand(posx1,posx2)
				posy = c_zrand(posy1,posy2)
				--hue = c_zrand(-25.0,25.0)
				--if rotate == -90 then
				--	rot = c_zrand(-180.0,180.0)
				--end

				if elastic > 0 then
					if c == 1 then
						launch_delay_inc = 0.0
						posx = posx1
						posy = posy1
					elseif c == 2 then
						posx = posx2
						posy = posy2
					else
						posx = posx2 + ( ( posx1 - posx2 ) * ( c - 2 ) / ( act_count - 1 ) )
						posy = posy2 + ( ( posy1 - posy2 ) * ( c - 2 ) / ( act_count - 1 ) )
					end
				end

				if random_offset_seq ~= nil then
					if random_offset_seq[cur_random_seq_num] ~= nil then
						-- c_print( "offset ", cur_random_seq_num, random_offset_seq[cur_random_seq_num] )
						posx = posx + random_offset_seq[cur_random_seq_num]
					end
					cur_random_seq_num = cur_random_seq_num + 1
					if random_offset_seq[cur_random_seq_num] == nil then
						cur_random_seq_num = 1
					end
				end

				if act == "waterjet_timer" then
					friend_unique_name = format( "water_timer%d", actor_unique_id )
					local apo = ACTOR_PreLaunch( "water_timer", friend_unique_name )
					apo:setall( posy, posz, -posx, 90.0, siz, hue, launch_delay, diffnum, stagenum, path )
					apo:launch()
				end
				if act == "firejet_timer" then
					friend_unique_name = format( "fire_timer%d", actor_unique_id )
					local apo = ACTOR_PreLaunch( "fire_timer", friend_unique_name )
					apo:setall( posy, posz, -posx, 90.0, siz, hue, launch_delay, diffnum, stagenum, path )
					apo:launch()
				end
				if act == "switchjet_timer" then
					friend_unique_name = format( "switch_timer%d", actor_unique_id )
					local apo = ACTOR_PreLaunch( "switch_timer", friend_unique_name )
					apo:setall( posy, posz, -posx, 90.0, siz, hue, launch_delay, diffnum, stagenum, path )
					apo:launch()
				end

				if search_uniqueid ~= nil then
					unique_name = format( "%s_%s", act, search_uniqueid )
				else
					unique_name = format( "%s_%d", act, actor_unique_id )
				end
				local apo = ACTOR_PreLaunch( act, unique_name )
				apo:setall( posy, posz, -posx, rot, siz, hue, launch_delay, diffnum, stagenum, path )
				apo:launch()

				if set_speed_seq ~= nil then
					c_set_unique_speed_values( set_speed_seq )
				end

				if act == "baskethead" then
					friend_unique_name = unique_name
					if search_uniqueid ~= nil then
						unique_name = format( "basketbase_%s", search_uniqueid )
					else
						unique_name = format( "basketbase_%d", actor_unique_id )
					end
					local apo = ACTOR_PreLaunch( "basketbase", unique_name )
					apo:setall( posy, posz, -posx, rot, siz, hue, launch_delay, diffnum, stagenum, path )
					apo:launch()
				end

				if act == "baskethead2" then
					friend_unique_name = unique_name
					if search_uniqueid ~= nil then
						unique_name = format( "basketbase2_%s", search_uniqueid )
					else
						unique_name = format( "basketbase2_%d", actor_unique_id )
					end
					local apo = ACTOR_PreLaunch( "basketbase2", unique_name )
					apo:setall( posy, posz, -posx, rot, siz, hue, launch_delay, diffnum, stagenum, path )
					apo:launch()
				end

				if friend_unique_name ~= nil then
					c_link_to_friend( friend_unique_name )
				end

				if elastic > 0 then
					search_uniqueid = nil
					rotate = 90
					rot = 90
					if c == 1 then
						unique_name_list_1 = unique_name
						c_set_elastic_dist( (act_count*2.0) )
						if act == "elastic_swing_post" then
							act = "elastic_swing_ball"
						elseif act == "elastic_swing_postr" then
							act = "elastic_swing_ballr"
						end
					elseif c == 2 then
						c_set_elastic_dist( (act_count*2.0) )
						c_link_to_parent( parent_unique_name, "mainbone" )
						if act == "elastic_ball" then
							act = "elastic_chain"
						elseif act == "elastic_ballr" then
							act = "elastic_chainr"
						elseif act == "elastic_swing_ball" then
							act = "elastic_swing_chain"
							posz = -3.0
						elseif act == "elastic_swing_ballr" then
							act = "elastic_swing_chainr"
							posz = -3.0
						elseif act == "elastic_bone_post" then
							act = "elastic_bone_chain"
						elseif act == "elastic_bone_postr" then
							act = "elastic_bone_chainr"
						elseif act == "elastic_ledge_post" then
							act = "elastic_ledge_chain"
						elseif act == "elastic_ledge_postr" then
							act = "elastic_ledge_chainr"
						end
					else
						c_print( parent_unique_name )
						c_link_to_parent( "x", "mainbone", parent_unique_name, parent_unique_name )
					end

					if c == act_count and c > 2 then
						c_link_to_parent( "x", "mainbone", unique_name_list_1, unique_name_list_1 )
					end

					parent_unique_name = unique_name
				end

				launch_delay = launch_delay + launch_delay_inc
				launch_delay_inc = launch_delay_inc * launch_delay_delta
			end

		end
end

