function init()
	gun.name = "Homing Missile"
	gun.fireDelay = 100
	gun.shotrange = 6000--acts as fuse
	gun.shotspeed = 400
	gun.shotdamage = 4.5
	gun.shotknockback = 10000
	gun.chargeTime = 750
	
	gun.firecost = 5
	
	gun.skipUpdate = 0--calls the lua gun update function
	return 0
end


function update()
	--if we've started locking on
	if math.abs(gun.charge) > .1 then
		--get a target
		gun.target = stage.getClosestShip(gun.releaseX, gun.releaseY, gun.owner.faction, -1, 600)
	
		--if target changed, reset charge
		--if gun.hasNewTarget() == 1 then gun.charge = 0 end
		
		--create emitter at the target
		if gun.hasTarget() == 1 then
			stage.createEmitter("lockon", gun.target.x, gun.target.y)
			emitter.rot = gun.charge * 360
			emitter.scale = 2.5 + gun.charge
			emitter.alpha = math.abs(gun.charge)
			emitter.upload()
		end
	else
		gun.clearTarget()
	end
	return 0
end


function fire()
	--if we've fully locked on
	if gun.charge > .95 then
		--store gun properties
		fireangle = gun.owner.rot
		shotspeed =  gun.shotspeed
		shotrange = gun.shotrange
		shotdamage = gun.shotdamage
		target = gun.target
		owner = gun.owner
		
		--use up the gun's juice cost
		gun.useCost()
		
		--reset charge
		gun.charge = 0
		
		--fire a missile
		stage.createShip("Missile", "null", gun.firex, gun.firey, 5)
		--aquire target
		ship.controller.setTarget(target)
		--ignore owner (can't collide)
		ship.ignore(owner)
		--move at speed
		ship.movrot = fireangle
		ship.rot = fireangle
		ship.speed = shotspeed
		--set the fuse
		ship.controller.resetTimer("fuse", shotrange)
		--set damage to the gun's damage
		ship.setWeaponDamage(shotdamage)
		
		stage.sfx("gun_missilethoom.wav", ship.x, ship.y)
	end
	return 0
end

function shot_update()

	return 0
end