
dofile("powerup_3way.lua")
dofile("powerup_laser.lua")
dofile("powerup_missile.lua")
dofile("powerup_shield.lua")
dofile("powerup_spinner.lua")
dofile("powerup_extralife.lua")

function player_add_bullet( actor_name, model_name, rate, sound )
	bullet_actor_name = actor_name
	bullet_model_name = model_name
	bullet_rate = rate
	bullet_sound = sound
	dofile("player_bullet_1.lua")
end

function player_add_player( use_player )
	dofile_lua( use_player )

	local seq = { 0.0, 0.1, 0.2, 0.4, 0.9 }
	c_set_use_explosion_for( "bye_bye", "player-dead", exp_no_align, 100.0, 0.0, 1500.0, 1800.0, seq )
	local seq = { 0.15, 0.25, 0.35, 0.55, 1.05 }
	c_set_use_explosion_for( "bye_bye", "player-dead", exp_no_align, 300.0, 0.0, 1000.0, 1200.0, seq )
	c_add_sound_to_explosion( "player-dead", "explode", "player-dead" )
	local seq = { 0.0, 0.1, 0.3 }
	c_set_use_explosion_for( "smart_bomb", "mine-shockwave", exp_no_align, 0.0, -0.9, 4500.0, 4500.0, seq )
	c_add_particle_to_explosion( "mine-shockwave", "explode", "", "mineshitter-mineexp" )
	c_add_sound_to_explosion( "mine-shockwave", "explode", "mine-exp" )

	local seq = { 0.0, 0.1, 0.2, 0.4, 0.9 }
	c_set_use_explosion_for( "bonus_extra", "flash-1", exp_no_align, 1500.0, 0.0, 3000.0, 6000.0, seq )
	local seq = { 0.01, 0.11, 0.21, 0.41, 0.91 }
	c_set_use_explosion_for( "bonus_extra", "flash-1", exp_no_align, 1500.0, 0.0, 3000.0, 6000.0, seq )
	local seq = { 0.15, 0.25, 0.35, 0.55, 1.05 }
	c_set_use_explosion_for( "bonus_extra", "flash-1", exp_no_align, 1500.0, 0.0, 3000.0, 6000.0, seq )
	local seq = { 0.16, 0.26, 0.36, 0.56, 1.06 }
	c_set_use_explosion_for( "bonus_extra", "flash-1", exp_no_align, 1500.0, 0.0, 3000.0, 6000.0, seq )
	local seq = { 0.25, 0.45, 0.75, 1.45, 1.65 }
	c_set_use_explosion_for( "bonus_extra", "flash-1", exp_no_align, 1000.0, 0.0, 3000.0, 6000.0, seq )
	local seq = { 0.26, 0.46, 0.76, 1.46, 1.66 }
	c_set_use_explosion_for( "bonus_extra", "flash-1", exp_no_align, 1000.0, 0.0, 3000.0, 6000.0, seq )

	c_add_particle_to_explosion( "flash-1", "explode", "", "player-flash" )

	c_set_use_explosion_for( "multiply_extra", "flash-multi", exp_no_align, 0.0, 0.0, 7000.0, 7000.0, {0.0} )
	c_add_particle_to_explosion( "flash-multi", "explode", "", "multi-shockwave" )
end

function player_start( posx, posy, posz )

	local player_choose_2 = c_get_player_num( 2 )
	local player_choose = c_get_player_num( 1 )
	if player_choose > 4 then
		player_choose = 4
	end

	local bullet_type = "bullet3"
	if player_choose_2 > 0 then
		bullet_type = format( "%s-mp", bullet_type )
	end

	-- main bullet
	player_add_bullet( "player_bullet_1", bullet_type, 0.05, "playerfire_1" )
	-- 3 way
	player_add_bullet( "player_bullet_2", "bullet-3way", 0.070, "playerfire_2" )
	-- laser
	player_add_bullet( "player_bullet_3", "bullet-laser", 0.075, "playerfire_3" )
	-- missile
	dofile("player_missile_1.lua")

	-- shield
	dofile("player_shield.lua")
	-- spinner
	dofile("player_spinner.lua")

	local use_player = format( "player_%d", player_choose )
	player_add_player( use_player )

	local apo = ACTOR_PreLaunch( use_player )
	if player_choose_2 > 0 then
		posx = posx - 4.0
	end
	apo:setposn( posy, posz, -posx )
	apo:launch()

	-- player 2
	player_choose = c_get_player_num( 2 )
	if player_choose > 0 then
		if player_choose > 4 then
			player_choose = 4
		end

		bullet_type = "bullet3-mp"
		-- main bullet
		player_add_bullet( "player2_bullet_1", bullet_type, 0.05, "playerfire_1" )

		player_choose = player_choose + 10
		use_player = format( "player_%d", player_choose )
		player_add_player( use_player )

		apo = ACTOR_PreLaunch( use_player )
		posx = posx + 8.0
		apo:setposn( posy, posz, -posx )
		apo:launch()
	end

	if cur_level_num == 99 then
		for t = 1,4,1 do
			use_player = format( "player_%d", t )
			player_add_player( use_player )
		end
		for t = 3,3,1 do
			bullet_type = format( "bullet%d", t )
			player_add_bullet( bullet_type, bullet_type, 0.05, "playerfire_1" )
			bullet_type = format( "bullet%d-mp", t )
			player_add_bullet( bullet_type, bullet_type, 0.05, "playerfire_1" )
		end
	end
end

