function lrm.init()

 local lrm_bullet = load_particle("lrm_bullet.obj")
 local lrm_gun = load_particle("lrm_gun.obj")
 local sound_fire = sounds["lrm_fire.wav"]

 local salvosize = 15
 local aimspeed = 3

 function lrm.target(object)
  local target = object:data().target
  local dx = object:data().dx
  local dy = object:data().dy

  if not target then
   target = object:closest_worm()
  end
 
  if target then
   local a = object:angle()
   local x1, y1 = object:pos()
   local x2, y2 = target:pos()
  
   if ( angle_diff(a,vector_direction(x1, y1, x2, y2)) > 0 ) then
    object:set_angle(a + aimspeed)
   else
    object:set_angle(a - aimspeed)
   end
 
  end

 end

 function lrm.shoot(worm)
  worm:data().lrm = salvosize
  worm:data().lrm_target = worm:closest_worm()
 end

 function lrm.gun(worm)
  local dx,dy = angle_vector(worm:angle(),5)
  for i = -2,2 do
   gun = worm:shoot(lrm_gun,1,0,0,0,0,0,180-10*i,5)
   gun:set_spd(dx,dy)
  end
 end

 function lrm.missile(worm)
  local lrm_ammo = worm:data().lrm
  if lrm_ammo then
   lrm_ammo = lrm_ammo - 1
   if lrm_ammo == 0 then
    lrm_ammo = nil
   end
   worm:data().lrm = lrm_ammo
   local bullet = worm:shoot(lrm_bullet, 1, 1, 0, 0, 0, 35, 0, math.random(10, 30) * 0.5)
   local angle = worm:angle()
   bullet:set_angle(angle)
   bullet:data().target = worm:data().lrm_target
   sound_fire:play(worm,nil,100,1.2,0.05)
  end
 end
end